生活随笔
收集整理的這篇文章主要介紹了
超级马力 超级玛丽游戏开发 入门级源码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
【實例簡介】
我停止這個項目有三個原因;
我必須把精力集中在我的主要項目上。這只是一個有趣的副業。
2)我不愿意為非個人用途而濫用受版權保護的材料,你也不應該。
這次參賽的比賽結束了。
我發布這個項目的源代碼,因為我已經得到了相當多的電子郵件與真的
但是我自己沒有時間去執行這些建議。
該代碼(/src/)是作為公共域發布的,所以你可以隨心所欲地使用它。
美術(/res/)仍然是任天堂的版權,所以幾乎可以肯定的是,我們不能用它來做任何事情。問任天堂。
還有,如果你想做個更大的項目,請考慮用法律藝術代替藝術。
文件:590m.com/f/25127180-494079677-fd92a3(訪問密碼: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();}
}
}
總結
以上是生活随笔為你收集整理的超级马力 超级玛丽游戏开发 入门级源码的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。