在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例Java游戏开发 → 超级马力 超级玛丽游戏开发 入门级源码,仅供参考学习

超级马力 超级玛丽游戏开发 入门级源码,仅供参考学习

Java游戏开发

下载此实例
  • 开发语言:Java
  • 实例大小:0.26M
  • 下载次数:75
  • 浏览次数:1127
  • 发布时间:2012-12-18
  • 实例类别:Java游戏开发
  • 发 布 人:chaogu
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 超级玛丽

实例介绍

【实例简介】

 

I stopped working on this project for three reasons;
1) I had to focus on my main project. This was just a fun side project.
2) I didn't feel comfortable abusing copyrighted material for non-personal use, and neither should you.
3) The competition this was an entry for ended.

I'm releasing the source code for this project since I've gotten quite a bit of email with really
good suggestions on how to make this better, but I don't have the time to implement them myself.

The code (/src/) is released as public domain, so you can do with it what you wish.
The art (/res/) is still copyright nintendo, so it's almost certainly NOT ok to do anything at all with it. Ask nintendo.

And, please, if you're going to make a bigger project out of this, please consider replacing the art with legal art.

 


About the code:

The code is basically undocumented, but should be readable anyway as it's fairly clean. The main entry points are
AppletLauncher and FrameLauncher. The main game is in MarioComponent.

"sonar" is the base of a software sound engine I've been working on. It's pretty nice, but there's a few bugs in it
(mostly timing based). It can easilly be ripped out and reused in another project.

The level editor isn't used for anything more than changing the behavior of blocks anymore. But I think there's still
code in there somewhere for loading a level instead of generating it, so if you want to reintroduce static levels,
you've got a nice base for a level editor there.

The game DOES support scrolling in the Y directions right out of the box! However, I didn't think it fit the retro feeling,
so I made all levels only one screen tall. ;)

The sprite package and class should be renamed into "entity" or "mobile" or something..


【实例截图】


【核心代码】

 

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();
        }
    }
}


 

标签: 超级玛丽

实例下载地址

超级马力 超级玛丽游戏开发 入门级源码,仅供参考学习

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警