Super horsepower super Mary game development entry-level source code

Posted by dreamdelerium on Fri, 18 Feb 2022 22:24:58 +0100

[example introduction]

I stopped this project for three reasons;

I must concentrate on my main project. It's just an interesting sideline.

2) I don't want to abuse copyrighted materials for non personal purposes, and you shouldn't.

The competition is over.

I released the source code of this project because I've got quite a lot of emails and really

But I don't have time to implement these suggestions myself.

The code (/ src /) is published as a public domain, so you can use it as you like.

Art (/ res /) is still Nintendo's copyright, so it's almost certain that we can't do anything with it. Ask Nintendo.

Also, if you want to do a bigger project, please consider using legal art instead of art.

File: 590m.com/f/25127180-494079677-fd92a3 (access password: 551685)

About code:

This code is basically undocumented, but it should be readable because it is quite clean. The main entry point is

AppletLauncher FrameLauncher. The main game is in MarioComponent.

"sonar" is the foundation of a software sound engine I have been committed to developing. It's beautiful, but there are some bug s in it

(mainly based on time). It can be easily taken out and reused in another project.

The level editor is no longer used to change the behavior of bricks. But I think there's more

The code is used to load levels rather than generate levels, so if you want to reintroduce static levels,

You have created a good foundation for the level editor.

The game does support scrolling in the Y direction! But I don't think it's suitable for the retro feeling,

So I set all levels to one screen high

Sprite packages and classes should be renamed "entity" or "move" or something else.

[example screenshot]


[core code]

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

}