Compare commits

...

2 Commits

Author SHA1 Message Date
DaniTheSkunk 16fdcee057 helper function for loading texture in basegame 2022-10-15 05:54:44 +00:00
DaniTheSkunk e398f7a095 added sample functions to BaseGame 2022-10-15 05:52:41 +00:00
4 changed files with 40 additions and 4 deletions

View File

@ -1,18 +1,32 @@
package com.danitheskunk.skunkworks; package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.audio.AudioEngine;
import com.danitheskunk.skunkworks.audio.ISample;
import com.danitheskunk.skunkworks.audio.nodes.Mixer;
import com.danitheskunk.skunkworks.audio.nodes.Node;
import com.danitheskunk.skunkworks.audio.nodes.SamplePlayer;
import com.danitheskunk.skunkworks.gfx.IRenderContext; import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.font.IFont; import com.danitheskunk.skunkworks.gfx.font.IFont;
import com.danitheskunk.skunkworks.nodes.Node;
import com.danitheskunk.skunkworks.nodes.NodeRoot; import com.danitheskunk.skunkworks.nodes.NodeRoot;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
public abstract class BaseGame { public abstract class BaseGame {
protected Engine engine; protected Engine engine;
protected AudioEngine audioEngine;
protected Mixer mixer;
protected SamplePlayer samplePlayer;
protected IWindow window; protected IWindow window;
protected IFont debugFont; protected IFont debugFont;
protected NodeRoot rootNode; protected NodeRoot rootNode;
public BaseGame(Vec2i windowSize, String windowTitle) { public BaseGame(Vec2i windowSize, String windowTitle) {
this.audioEngine = new AudioEngine(44100, 256, 8);
this.mixer = new Mixer(this.audioEngine, 2);
this.samplePlayer = new SamplePlayer(this.audioEngine);
Node.connect(samplePlayer, 0, mixer, 0);
this.audioEngine.setNode(this.mixer);
this.engine = new Engine(); this.engine = new Engine();
this.window = engine.openWindow(windowSize, windowTitle); this.window = engine.openWindow(windowSize, windowTitle);
//todo: load from .jar //todo: load from .jar
@ -38,6 +52,7 @@ public abstract class BaseGame {
rootNode.render(rc); rootNode.render(rc);
render(rc); render(rc);
window.renderFinish(rc); window.renderFinish(rc);
audioEngine.refill();
} }
} }
@ -58,4 +73,20 @@ public abstract class BaseGame {
protected void update(double delta) { protected void update(double delta) {
} }
protected ISample loadSample(String path) {
return audioEngine.loadSample(path);
}
protected void playSample(ISample sample) {
samplePlayer.play(sample);
}
protected void playSample(ISample sample, boolean looping) {
samplePlayer.play(sample, looping);
}
protected ITexture loadTexture(String path) {
return window.loadTexture(path);
}
} }

View File

@ -1,19 +1,24 @@
package com.danitheskunk.skunkworks; package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.audio.ISample;
import com.danitheskunk.skunkworks.nodes.NodeSprite; import com.danitheskunk.skunkworks.nodes.NodeSprite;
public class TestNode extends BaseGame { public class TestNode extends BaseGame {
NodeSprite sprite; NodeSprite sprite;
ISample kick;
public TestNode() { public TestNode() {
super(new Vec2i(1280, 720), "Skunkworks"); super(new Vec2i(1280, 720), "Skunkworks");
kick = loadSample("demoassets/kick.wav");
sprite = new NodeSprite(); sprite = new NodeSprite();
sprite.setTexture(window.loadTexture("demoassets/test.png")); sprite.setTexture(loadTexture("demoassets/test.png"));
sprite.setPos(new Vec2f(100, 100)); sprite.setPos(new Vec2f(100, 100));
rootNode.add(sprite); rootNode.add(sprite);
sprite.tweenPos(new Vec2f(800, 400), 120).delay(60).then(() -> { sprite.tweenPos(new Vec2f(800, 400), 120).delay(60).then(() -> {
System.out.println("yay! got there! now lets go home"); System.out.println("yay! got there! now lets go home");
sprite.tweenPos(new Vec2f(100, 100), 120); sprite.tweenPos(new Vec2f(100, 100), 120);
playSample(kick);
}); });
} }

View File

@ -27,7 +27,7 @@ public class TestSound {
var sin3 = new Sine(engine, 523.25); var sin3 = new Sine(engine, 523.25);
engine.setNode(mix); engine.setNode(mix);
//Node.connect(sin1, 0, mix, 0); //Node.connect(sin1, 0, mix, 0);
//Node.connect(sin3, 0, mix, 1); Node.connect(sin3, 0, mix, 1);
//Node.connect(sin2, 0, mix, 2); //Node.connect(sin2, 0, mix, 2);
var loop = engine.loadSample("C:\\Users\\dani\\Downloads\\AKWF" + var loop = engine.loadSample("C:\\Users\\dani\\Downloads\\AKWF" +
@ -41,7 +41,7 @@ public class TestSound {
player.play(loop, true); player.play(loop, true);
for(int j = 0; j < 10; ++j) { for(int j = 0; j < 10; ++j) {
//player.play(kick); player.play(kick);
for(int i = 0; i < 50; ++i) { for(int i = 0; i < 50; ++i) {
engine.refill(); engine.refill();
Thread.sleep(20); Thread.sleep(20);

BIN
demoassets/kick.wav Normal file

Binary file not shown.