本文共 3837 字,大约阅读时间需要 12 分钟。
【实例简介】
我停止这个项目有三个原因;
我必须把精力集中在我的主要项目上。这只是一个有趣的副业。
2)我不愿意为非个人用途而滥用受版权保护的材料,你也不应该。
这次参赛的比赛结束了。
我发布这个项目的源代码,因为我已经得到了相当多的电子邮件与真的
但是我自己没有时间去执行这些建议。
该代码(/src/)是作为公共域发布的,所以你可以随心所欲地使用它。
美术(/res/)仍然是任天堂的版权,所以几乎可以肯定的是,我们不能用它来做任何事情。问任天堂。
还有,如果你想做个更大的项目,请考虑用法律艺术代替艺术。
文件:(访问密码:551685)
关于代码:
这段代码基本上没有文档记录,但是应该是可读的,因为它相当干净。主要的入口点是
AppletLauncher FrameLauncher。主要游戏是在MarioComponent中。
“sonar”是我一直致力于开发的一款软件音效引擎的基础。它很漂亮,但是里面有一些bug
(主要是基于时间)。可以很容易地将其取出并在另一个项目中重用。
关卡编辑器不再用于改变砖块的行为。但我认为还有
代码是用来加载关卡而不是生成关卡的,所以如果你想重新引入静态关卡,
你已经为关卡编辑器创造了一个良好的基础。
游戏确实支持在Y方向上滚动!但是,我觉得它不适合复古的感觉,
所以我将所有关卡设置为一个屏幕高。,)
精灵包和类应该重命名为“实体”或“移动”或其他东西。
【实例截图】
【核心代码】
public class SonarSoundEngine implements Runnable
{ private SonarSample silentSample; private SourceDataLine sdl; private int rate = 44100; private ListenerMixer listenerMixer; private int bufferSize = rate / 100; // 10 ms private ByteBuffer soundBuffer = ByteBuffer.allocate(bufferSize * 4); private float[] leftBuf, rightBuf; private float amplitude = 1; private float targetAmplitude = 1; private boolean alive = true;protected SonarSoundEngine(){} public SonarSoundEngine(int maxChannels) throws LineUnavailableException{ silentSample = new SonarSample(new float[] {0}, 44100); Mixer mixer = AudioSystem.getMixer(null); sdl = (SourceDataLine) mixer.getLine(new Line.Info(SourceDataLine.class)); sdl.open(new AudioFormat(rate, 16, 2, true, false), bufferSize * 2 * 2 * 2 * 2 * 2); soundBuffer.order(ByteOrder.LITTLE_ENDIAN); sdl.start(); try {
/* FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
volumeControl.setValue(volumeControl.getMaximum());*/ } catch (IllegalArgumentException e) { System.out.println(“Failed to set the sound volume”); }listenerMixer = new ListenerMixer(maxChannels); leftBuf = new float[bufferSize]; rightBuf = new float[bufferSize]; Thread thread = new Thread(this); thread.setDaemon(true); thread.setPriority(10); thread.start();}public void setListener(SoundListener soundListener){ listenerMixer.setSoundListener(soundListener);}public void shutDown(){ alive = false;}public SonarSample loadSample(String resourceName){ try { return SampleLoader.loadSample(resourceName); } catch (Exception e) { System.out.println("Failed to load sample " resourceName ". Using silent sample"); e.printStackTrace(); return silentSample; }}public void play(SonarSample sample, SoundSource soundSource, float volume, float priority, float rate){ synchronized (listenerMixer) { listenerMixer.addSoundProducer(new SamplePlayer((SonarSample) sample, rate), soundSource, volume, priority); }}public void clientTick(float alpha){ synchronized (listenerMixer) { listenerMixer.update(alpha); }}public void tick(){ soundBuffer.clear(); // targetAmplitude = (targetAmplitude - 1) * 0.9f 1; // targetAmplitude = (targetAmplitude - 1) * 0.9f 1; synchronized (listenerMixer) { float maxAmplitude = listenerMixer.read(leftBuf, rightBuf, rate); // if (maxAmplitude > targetAmplitude) targetAmplitude = maxAmplitude; } soundBuffer.clear(); float gain = 32000; for (int i = 0; i < bufferSize; i ) { // amplitude = (targetAmplitude - amplitude) / rate; // amplitude = 1; // float gain = 30000; int l = (int) (leftBuf[i] * gain); int r = (int) (rightBuf[i] * gain); if (l > 32767) l = 32767; if (r > 32767) r = 32767; if (l < -32767) l = -32767; if (r < -32767) r = -32767; soundBuffer.putShort((short)l); soundBuffer.putShort((short)r); } sdl.write(soundBuffer.array(), 0, bufferSize * 2 * 2);}public void run(){ while (alive) { tick(); }}
}
转载地址:http://petyk.baihongyu.com/