Egg and attacking work

This commit is contained in:
Gnarwhal 2020-04-19 16:11:06 -07:00 committed by Gnarwhal
parent 5fd4389d1b
commit 9136988f8e
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
72 changed files with 10071 additions and 726 deletions

BIN
res/audio/Clacks.aac Normal file

Binary file not shown.

BIN
res/audio/Clacks.wav Normal file

Binary file not shown.

BIN
res/audio/Clicks.aac Normal file

Binary file not shown.

BIN
res/audio/Clicks.wav Normal file

Binary file not shown.

BIN
res/audio/Swoosh.aac Normal file

Binary file not shown.

BIN
res/audio/Swoosh.wav Normal file

Binary file not shown.

BIN
res/audio/Thumps.aac Normal file

Binary file not shown.

BIN
res/audio/Thumps.wav Normal file

Binary file not shown.

127
res/audio/sour.aup Normal file
View file

@ -0,0 +1,127 @@
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE project PUBLIC "-//audacityproject-1.3.0//DTD//EN" "http://audacity.sourceforge.net/xml/audacityproject-1.3.0.dtd" >
<project xmlns="http://audacity.sourceforge.net/xml/" projname="sour_data" version="1.3.0" audacityversion="2.3.2" sel0="0.0121458333" sel1="1.3687500000" vpos="0" h="0.0000000000" zoom="164.7836538462" rate="48000.0" snapto="off" selectionformat="hh:mm:ss + milliseconds" frequencyformat="Hz" bandwidthformat="octaves">
<tags>
<tag name="Software" value="Lavf58.39.101"/>
</tags>
<wavetrack name="Thumps" channel="0" linked="1" mute="0" solo="0" height="150" minimized="0" isSelected="1" rate="48000" gain="1.0" pan="0.0" colorindex="0">
<waveclip offset="0.01214583" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="16021">
<waveblock start="0">
<simpleblockfile filename="e08083ab.au" len="16021" min="-0.000001" max="0.000001" rms="0.0"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="0.34591667" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="19028">
<waveblock start="0">
<simpleblockfile filename="e08083f4.au" len="19028" min="-0.936817" max="1.472945" rms="0.124196"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="0.74233333" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="28704">
<waveblock start="0">
<simpleblockfile filename="e0808eed.au" len="28704" min="-0.000164" max="0.00004" rms="0.000008"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="1.34033333" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="1364">
<waveblock start="0">
<simpleblockfile filename="e0808ef4.au" len="1364" min="0.0" max="0.0" rms="0.0"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
</wavetrack>
<wavetrack name="Thumps" channel="1" linked="0" mute="0" solo="0" height="150" minimized="0" isSelected="1" rate="48000" gain="1.0" pan="0.0" colorindex="0">
<waveclip offset="0.01214583" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="16021">
<waveblock start="0">
<simpleblockfile filename="e0808323.au" len="16021" min="-0.000001" max="0.000001" rms="0.0"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="0.34591667" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="19028">
<waveblock start="0">
<simpleblockfile filename="e0808b06.au" len="19028" min="-0.936817" max="1.472945" rms="0.124196"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="0.74233333" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="28704">
<waveblock start="0">
<simpleblockfile filename="e0808961.au" len="28704" min="-0.000164" max="0.00004" rms="0.000008"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="1.34033333" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="1364">
<waveblock start="0">
<simpleblockfile filename="e080803c.au" len="1364" min="0.0" max="0.0" rms="0.0"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
</wavetrack>
<wavetrack name="Audio Track" channel="0" linked="1" mute="0" solo="0" height="150" minimized="0" isSelected="1" rate="48000" gain="1.0" pan="0.0" colorindex="0">
<waveclip offset="0.01214583" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="61714">
<waveblock start="0">
<simpleblockfile filename="e0808bba.au" len="61714" min="-1.621721" max="3.158184" rms="0.189468"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="1.29785417" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="2039">
<waveblock start="0">
<simpleblockfile filename="e08080fe.au" len="2039" min="-0.000185" max="0.000056" rms="0.00001"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="1.34033333" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="1364">
<waveblock start="0">
<simpleblockfile filename="e0808d2b.au" len="1364" min="-0.000065" max="0.000184" rms="0.000006"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
</wavetrack>
<wavetrack name="Audio Track" channel="1" linked="0" mute="0" solo="0" height="150" minimized="0" isSelected="1" rate="48000" gain="1.0" pan="0.0" colorindex="0">
<waveclip offset="0.01214583" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="61714">
<waveblock start="0">
<simpleblockfile filename="e0808ecb.au" len="61714" min="-1.621721" max="3.158184" rms="0.189468"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="1.29785417" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="2039">
<waveblock start="0">
<simpleblockfile filename="e08080dd.au" len="2039" min="-0.000185" max="0.000056" rms="0.00001"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="1.34033333" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="1364">
<waveblock start="0">
<simpleblockfile filename="e080811a.au" len="1364" min="-0.000065" max="0.000184" rms="0.000006"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
</wavetrack>
</project>

BIN
res/audio/sour.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

63
res/audio/sweet.aup Normal file
View file

@ -0,0 +1,63 @@
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE project PUBLIC "-//audacityproject-1.3.0//DTD//EN" "http://audacity.sourceforge.net/xml/audacityproject-1.3.0.dtd" >
<project xmlns="http://audacity.sourceforge.net/xml/" projname="sweet_data" version="1.3.0" audacityversion="2.3.2" sel0="0.0121458333" sel1="0.0121458333" vpos="0" h="0.0000000000" zoom="164.7836538462" rate="48000.0" snapto="off" selectionformat="hh:mm:ss + milliseconds" frequencyformat="Hz" bandwidthformat="octaves">
<tags>
<tag name="Software" value="Lavf58.39.101"/>
</tags>
<wavetrack name="Thumps" channel="0" linked="1" mute="0" solo="0" height="150" minimized="0" isSelected="1" rate="48000" gain="1.0" pan="0.0" colorindex="0">
<waveclip offset="0.30542291" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="28704">
<waveblock start="0">
<simpleblockfile filename="e0808528.au" len="28704" min="-0.121093" max="0.116137" rms="0.025088"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="0.01214583" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="14077">
<waveblock start="0">
<simpleblockfile filename="e08089f9.au" len="14077" min="-0.455328" max="0.696397" rms="0.066507"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
</wavetrack>
<wavetrack name="Thumps" channel="1" linked="0" mute="0" solo="0" height="150" minimized="0" isSelected="1" rate="48000" gain="1.0" pan="0.0" colorindex="0">
<waveclip offset="0.30542291" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="28704">
<waveblock start="0">
<simpleblockfile filename="e0808f95.au" len="28704" min="-0.095378" max="0.109781" rms="0.023558"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
<waveclip offset="0.01214583" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="14077">
<waveblock start="0">
<simpleblockfile filename="e080800b.au" len="14077" min="-0.457024" max="0.697582" rms="0.066056"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
</wavetrack>
<wavetrack name="Audio Track" channel="0" linked="1" mute="0" solo="0" height="150" minimized="0" isSelected="0" rate="48000" gain="1.0" pan="0.0" colorindex="0">
<waveclip offset="0.01214583" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="43269">
<waveblock start="0">
<simpleblockfile filename="e080863b.au" len="43269" min="-0.578513" max="1.121367" rms="0.095043"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
</wavetrack>
<wavetrack name="Audio Track" channel="1" linked="0" mute="0" solo="0" height="150" minimized="0" isSelected="0" rate="48000" gain="1.0" pan="0.0" colorindex="0">
<waveclip offset="0.01214583" colorindex="0">
<sequence maxsamples="262144" sampleformat="262159" numsamples="43269">
<waveblock start="0">
<simpleblockfile filename="e0808cd7.au" len="43269" min="-0.574524" max="1.122271" rms="0.096022"/>
</waveblock>
</sequence>
<envelope numpoints="0"/>
</waveclip>
</wavetrack>
</project>

BIN
res/audio/sweet.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

7223
res/img/eggs.ai Normal file

File diff suppressed because one or more lines are too long

BIN
res/img/eggs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

1205
res/img/platform.ai Normal file

File diff suppressed because one or more lines are too long

BIN
res/img/platform.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -11,7 +11,7 @@ out vec4 color;
void main() { void main() {
vec4 sample = texture(sampler, texCoords); vec4 sample = texture(sampler, texCoords);
float x = sample.r + time; float x = sample.r + time;
color = vec4(iColor * mod(floor(x), 2) * (-x + 2), sample.a); color = vec4(iColor, mod(floor(x), 2) * (-x + 2) * sample.a);
if (color.a == 0) { if (color.a == 0) {
discard; discard;
} }

View file

@ -0,0 +1,171 @@
package com.gnarwhal.ld46.game;
import com.gnarwhal.ld46.engine.display.Camera;
import com.gnarwhal.ld46.engine.model.Rect;
import com.gnarwhal.ld46.engine.shaders.Shader;
import com.gnarwhal.ld46.engine.shaders.Shader2t;
import com.gnarwhal.ld46.engine.texture.Texture;
import org.joml.Vector2f;
import org.joml.Vector3f;
import static com.gnarwhal.ld46.game.Main.dtime;
public class Egg extends Rect {
private static final float WIDTH = 96;
private static final float HEIGHT = 128;
private static Texture texture;
private static Shader2t shader;
private Vector3f velocity;
private boolean grounded;
private float a;
private float b;
final float VERT_BOUNCE_DECAY = 0.25f;
final float HIT_BOUNCE_DECAY = 0.9f;
private float vertBounceDecay;
private float bounceChangeTime;
public Egg(Camera camera) {
super(camera, (camera.getWidth() - WIDTH) / 2, (camera.getHeight() - HEIGHT) / 2, -0.2f, WIDTH, HEIGHT, 0, false);
velocity = new Vector3f(600, -600, 0);
if (texture == null) {
texture = new Texture("res/img/eggs.png");
shader = Shader.SHADER2T;
}
a = (WIDTH + HEIGHT) / 4;
b = (WIDTH - HEIGHT) / 4;
vertBounceDecay = VERT_BOUNCE_DECAY;
}
public void update(Platform[] platforms) {
final float GROUNDED_DECELERATION = 1760;
final float TERMINAL_VELOCITY = 4096;
final float GRAVITY = 2048;
final float BOUNCE_CHANGE_DELAY = 0.05f;
if (bounceChangeTime > BOUNCE_CHANGE_DELAY) {
vertBounceDecay = VERT_BOUNCE_DECAY;
}
bounceChangeTime += dtime;
float friction = 0;
float floor = 0;
Vector3f acceleration = new Vector3f(0, GRAVITY, 0);
if (velocity.x != 0 && grounded) {
friction = -GROUNDED_DECELERATION * (velocity.x / Math.abs(velocity.x));
}
float absVelocityY = Math.abs(velocity.y());
if (absVelocityY > TERMINAL_VELOCITY) {
velocity.y = (velocity.y / absVelocityY) * TERMINAL_VELOCITY;
}
velocity.add(acceleration.mul((float) dtime, new Vector3f()));
float degradedVelocity = velocity.x() + friction * (float) dtime;
// If the acceleration due to friction would accelerate it past the speed floor set it to the speed floor
if ((degradedVelocity - floor) * (velocity.x() - floor) < 0) {
velocity.x = floor;
// otherwise just apply the friction
} else {
velocity.x = degradedVelocity;
}
// --- C O L L I S I O N --- //
Vector3f translation = velocity.mul((float) dtime, new Vector3f());
Vector3f translationCopy = new Vector3f(translation);
if (translation.y > 0) {
Vector3f bottomLeft = new Vector3f(position).add(0, height, 0);
Vector3f bottomRight = new Vector3f(position).add(width, height, 0);
for (int i = 0; i < platforms.length; ++i) {
Vector3f porigin = platforms[i].getOrigin();
Vector3f ptranslation = platforms[i].getTranslation();
float s1, t1, s2, t2;
if (translation.x != 0) {
s1 = ((porigin.y - bottomLeft.y) / translation.y - (porigin.x - bottomLeft.x) / translation.x) / (ptranslation.x / translation.x - ptranslation.y / translation.y);
s2 = ((porigin.y - bottomRight.y) / translation.y - (porigin.x - bottomRight.x) / translation.x) / (ptranslation.x / translation.x - ptranslation.y / translation.y);
} else {
s1 = (bottomLeft.x - porigin.x) / ptranslation.x;
s2 = (bottomRight.x - porigin.x) / ptranslation.x;
}
t1 = (ptranslation.y * s1 + porigin.y - bottomLeft.y) / translation.y;
t2 = (ptranslation.y * s1 + porigin.y - bottomRight.y) / translation.y;
if (s1 >= 0 && s1 <= 1 && t1 >= 0 && t1 <= 1) {
if (t2 < t1 && s2 >= 0 && s2 <= 1 && t2 >= 0 && t2 <= 1) {
translation.y *= t2;
} else {
translation.y *= t1;
}
} else if (s2 >= 0 && s2 <= 1 && t2 >= 0 && t2 <= 1) {
translation.y *= t2;
}
}
}
final float HORZ_BOUNCE_DECAY = 0.75f;
grounded = false;
if (!translation.equals(translationCopy, 0)) {
velocity.y *= -vertBounceDecay;
grounded = true;
}
position.add(translation);
// Check y bounds
if (position.y + height > camera.getHeight()) {
position.y = camera.getHeight() - height;
velocity.y *= -vertBounceDecay;
grounded = true;
} else {
if (position.y < 0) {
position.y = 0;
velocity.y *= -vertBounceDecay;
}
}
// Check X bounds
if (position.x < 0) {
position.x = 0;
velocity.x *= -HORZ_BOUNCE_DECAY;
} else if (position.x + width > camera.getWidth()) {
position.x = camera.getWidth() - width;
velocity.x *= -HORZ_BOUNCE_DECAY;
}
// --- E N D C O L L I S I O N --- //
}
private static final Vector2f SUBTEXTURE_DIMS = new Vector2f(0.2f, 1);
public void render() {
texture.bind();
shader.enable();
shader.setSubtexture(new Vector2f(0, 0), SUBTEXTURE_DIMS);
shader.setMVP(camera.getMatrix().translate(position).scale(WIDTH * scale, HEIGHT * scale, 1));
vao.render();
}
public void launch(Vector3f velocity) {
this.velocity.set(velocity);
vertBounceDecay = HIT_BOUNCE_DECAY;
bounceChangeTime = 0;
}
public Vector3f getOrigin() {
return position.add(width / 2, height / 2, 0, new Vector3f());
}
public float getRadius(float theta) {
return a + b * (float) Math.cos(2 * theta);
}
}

View file

@ -9,6 +9,7 @@ public class GamePanel {
private Camera camera; private Camera camera;
private Player player; private Player player;
private Egg egg;
private Platform[] platforms; private Platform[] platforms;
@ -17,20 +18,25 @@ public class GamePanel {
this.camera = camera; this.camera = camera;
player = new Player(window, camera); player = new Player(window, camera);
egg = new Egg(camera);
platforms = new Platform[] { platforms = new Platform[] {
new Platform(camera, 800, 800, 320) new Platform(camera, (camera.getWidth() / 4 - Platform.SEGMENT_WIDTH * 4 / 2), camera.getHeight() * 2 / 5 - Platform.HEIGHT / 2, 2),
new Platform(camera, (camera.getWidth() * 3 / 4 - Platform.SEGMENT_WIDTH * 4 / 2), camera.getHeight() * 2 / 5 - Platform.HEIGHT / 2, 2),
new Platform(camera, (camera.getWidth() / 2 - Platform.SEGMENT_WIDTH * 5 / 2), camera.getHeight() * 3 / 4 - Platform.HEIGHT / 2, 3)
}; };
} }
public void update() { public void update() {
player.update(platforms); egg.update(platforms);
player.update(platforms, egg);
} }
public void render() { public void render() {
for (int i = 0; i < platforms.length; ++i) { for (int i = 0; i < platforms.length; ++i) {
platforms[i].render(); platforms[i].render();
} }
egg.render();
player.render(); player.render();
} }
} }

View file

@ -10,6 +10,10 @@ public class Main {
public static int fps; public static int fps;
public static double dtime; public static double dtime;
public static double adtime;
private static double freezeDuration;
private static double freezeTime;
private ALManagement al; private ALManagement al;
@ -18,6 +22,11 @@ public class Main {
private GamePanel panel; private GamePanel panel;
public static void freeze(float duration) {
freezeDuration = duration;
freezeTime = 0;
}
public void start() { public void start() {
init(); init();
int frames = 0; int frames = 0;
@ -27,7 +36,15 @@ public class Main {
while(!window.shouldClose()) { while(!window.shouldClose()) {
curTime = System.nanoTime(); curTime = System.nanoTime();
if (curTime - pastTime > nspf) { if (curTime - pastTime > nspf) {
dtime = nspf / 1000000000d; adtime = nspf / 1000000000d;
if (freezeDuration > freezeTime + adtime) {
dtime = 0;
} else if (freezeDuration > freezeTime) {
dtime = adtime - (freezeDuration - freezeTime);
} else {
dtime = adtime;
}
freezeTime += adtime;
update(); update();
render(); render();
pastTime += nspf; pastTime += nspf;

View file

@ -1,33 +1,64 @@
package com.gnarwhal.ld46.game; package com.gnarwhal.ld46.game;
import com.gnarwhal.ld46.engine.display.Camera; import com.gnarwhal.ld46.engine.display.Camera;
import com.gnarwhal.ld46.engine.model.ColRect; import com.gnarwhal.ld46.engine.model.Rect;
import com.gnarwhal.ld46.engine.shaders.Shader;
import com.gnarwhal.ld46.engine.shaders.Shader2t;
import com.gnarwhal.ld46.engine.texture.Texture;
import org.joml.Vector2f;
import org.joml.Vector3f; import org.joml.Vector3f;
public class Platform { public class Platform extends Rect {
private Camera camera; public static final float SEGMENT_WIDTH = 96;
private ColRect rect; public static final float HEIGHT = 96;
public Platform(Camera camera, float x, float y, float width) { private static Texture texture;
this.camera = camera; private static Shader2t shader;
this.rect = new ColRect(camera, x, y, -0.05f, width, 12, 1, 1, 1, 1, false);
private int segmentSelection[];
public Platform(Camera camera, float x, float y, int internalSegments) {
super(camera, x, y, -0.5f, (internalSegments + 2) * SEGMENT_WIDTH, HEIGHT, 0, false);
segmentSelection = new int[internalSegments + 2];
segmentSelection[ 0] = 0;
segmentSelection[internalSegments + 1] = 4;
if (segmentSelection.length > 2) {
segmentSelection[1] = (int) (Math.random() * 3);
for (int i = 2; i < internalSegments + 1; ++i) {
segmentSelection[i] = segmentSelection[i - 1] + (int) (Math.random() * 2) + 1;
}
for (int i = 1; i < internalSegments + 1; ++i) {
segmentSelection[i] = segmentSelection[i] % 3 + 1;
}
}
if (texture == null) {
texture = new Texture("res/img/platform.png");
shader = Shader.SHADER2T;
}
} }
public void update() { public void update() {}
} private static final Vector2f SUBTEXTURE_DIMS = new Vector2f(0.2f, 1);
public void render() { public void render() {
rect.render(); texture.bind();
shader.enable();
for (int i = 0; i < segmentSelection.length; ++i) {
shader.setSubtexture(new Vector2f(segmentSelection[i] * SUBTEXTURE_DIMS.x, 0), SUBTEXTURE_DIMS);
shader.setMVP(camera.getMatrix().translate(position.add(SEGMENT_WIDTH / 2 + SEGMENT_WIDTH * i, height / 2, 0, new Vector3f())).scale(SEGMENT_WIDTH, HEIGHT, 1).translate(-0.5f, -0.5f, 0));
vao.render();
}
} }
public Vector3f getOrigin() { public Vector3f getOrigin() {
return new Vector3f(rect.getX(), rect.getY(), 0); return new Vector3f(position.x, position.y, 0);
} }
public Vector3f getTranslation() { public Vector3f getTranslation() {
return new Vector3f(rect.getWidth(), 0, 0); return new Vector3f(width, 0, 0);
} }
} }

View file

@ -1,7 +1,9 @@
package com.gnarwhal.ld46.game; package com.gnarwhal.ld46.game;
import com.gnarwhal.ld46.engine.audio.Sound;
import com.gnarwhal.ld46.engine.display.Camera; import com.gnarwhal.ld46.engine.display.Camera;
import com.gnarwhal.ld46.engine.display.Window; import com.gnarwhal.ld46.engine.display.Window;
import com.gnarwhal.ld46.engine.model.ColRect;
import com.gnarwhal.ld46.engine.model.Rect; import com.gnarwhal.ld46.engine.model.Rect;
import com.gnarwhal.ld46.engine.shaders.Shader2e; import com.gnarwhal.ld46.engine.shaders.Shader2e;
import com.gnarwhal.ld46.engine.shaders.Shader2t; import com.gnarwhal.ld46.engine.shaders.Shader2t;
@ -13,6 +15,7 @@ import org.joml.Vector4f;
import java.util.Vector; import java.util.Vector;
import static com.gnarwhal.ld46.engine.display.Window.BUTTON_PRESSED; import static com.gnarwhal.ld46.engine.display.Window.BUTTON_PRESSED;
import static com.gnarwhal.ld46.game.Main.adtime;
import static com.gnarwhal.ld46.game.Main.dtime; import static com.gnarwhal.ld46.game.Main.dtime;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;
@ -34,9 +37,35 @@ public class Player extends Rect {
new Vector3f(1, 0, 1 ) new Vector3f(1, 0, 1 )
}; };
private static final float
UP_ANGLE_DEVIATION = (float) Math.PI / 12.0f,
SIDE_ANGLE_DEVIATION = (float) Math.PI / 3.0f,
DOWN_ANGLE_DEVIATION = (float) Math.PI / 12.0f;
private static final float
UP_ANGLE_RANGE = (float) Math.PI * 2.0f / 3.0f,
SIDE_ANGLE_RANGE = (float) Math.PI * 3.0f / 4.0f,
DOWN_ANGLE_RANGE = (float) Math.PI * 2.0f / 3.0f;
// sour spot power, sweet spot power
private static final Vector2f
UP_ATTACK_POWER = new Vector2f(1024, 1600),
SIDE_ATTACK_POWER = new Vector2f(1024, 1280),
DOWN_ATTACK_POWER = new Vector2f(1024, 1600);
private static final float
LEFT_ANGLE_ORIGIN = (float) Math.PI * -5.0f / 6.0f,
RIGHT_ANGLE_ORIGIN = (float) Math.PI * -1.0f / 6.0f,
UP_ANGLE_ORIGIN = (float) Math.PI * -0.5f,
DOWN_ANGLE_ORIGIN = (float) Math.PI * 0.5f;
private static final Vector4f COLLISION_OFFSETS = new Vector4f(6.0f, 6.0f, 5.0f, 3.5f).div(24.0f); private static final Vector4f COLLISION_OFFSETS = new Vector4f(6.0f, 6.0f, 5.0f, 3.5f).div(24.0f);
// LEFT, RIGHT, TOP, BOTTOM // LEFT, RIGHT, TOP, BOTTOM
private static Sound sweet;
private static Sound sour;
private Vector4f scaledCollisionOffsets; private Vector4f scaledCollisionOffsets;
private int state; private int state;
@ -56,9 +85,21 @@ public class Player extends Rect {
private boolean grounded = false; private boolean grounded = false;
private Shader2e effectShader; private Shader2e effectShader;
private float attackTimer;
private float effectTime; private float effectTime;
private float attackTimer;
private float attackDelay;
private float attackAngle;
private float attackAngleRange;
private float angleDeviation;
private Vector2f attackPower;
private boolean hit;
private float jumpTime;
private boolean jumpReset;
//private ColRect rect;
public Player(Window window, Camera camera) { public Player(Window window, Camera camera) {
super(camera, 0, 0, -0.1f, 256, 256, 0, false); super(camera, 0, 0, -0.1f, 256, 256, 0, false);
this.window = window; this.window = window;
@ -87,65 +128,98 @@ public class Player extends Rect {
sprite = new Vector2f(); sprite = new Vector2f();
attackTimer = 10000; attackTimer = 10000;
hit = false;
jumpTime = 0;
jumpReset = true;
//rect = new ColRect(camera, 0, 0, 0, 100, 100, 1, 0, 0, 1, false);
if (sour == null) {
sweet = new Sound("res/audio/sweet.wav");
sour = new Sound("res/audio/sour.wav");
}
} }
public void update(Platform[] platforms) { public void update(Platform[] platforms, Egg egg) {
final float ATTACK_RESET = 0.0f; final float ATTACK_RESET = 0.0f;
if (state == STATE_REST && attackTimer >= ATTACK_RESET) { if (state == STATE_REST && attackTimer >= ATTACK_RESET) {
if (window.keyPressed(GLFW_KEY_LEFT) == BUTTON_PRESSED) { if (window.keyPressed(GLFW_KEY_LEFT) == BUTTON_PRESSED) {
state = STATE_LEFT; state = STATE_LEFT;
attackAngle = LEFT_ANGLE_ORIGIN;
angleDeviation = SIDE_ANGLE_DEVIATION;
attackPower = SIDE_ATTACK_POWER;
attackAngleRange = SIDE_ANGLE_RANGE;
//rect.setColor(1, 0, 0);
} else if (window.keyPressed(GLFW_KEY_RIGHT) == BUTTON_PRESSED) { } else if (window.keyPressed(GLFW_KEY_RIGHT) == BUTTON_PRESSED) {
state = STATE_RIGHT; state = STATE_RIGHT;
attackAngle = RIGHT_ANGLE_ORIGIN;
angleDeviation = SIDE_ANGLE_DEVIATION;
attackPower = SIDE_ATTACK_POWER;
attackAngleRange = SIDE_ANGLE_RANGE;
//rect.setColor(1, 0, 0);
} else if (window.keyPressed(GLFW_KEY_UP) == BUTTON_PRESSED) { } else if (window.keyPressed(GLFW_KEY_UP) == BUTTON_PRESSED) {
state = STATE_UP; state = STATE_UP;
attackAngle = UP_ANGLE_ORIGIN;
angleDeviation = UP_ANGLE_DEVIATION;
attackPower = UP_ATTACK_POWER;
attackAngleRange = UP_ANGLE_RANGE;
//rect.setColor(1, 0, 0);
} else if (window.keyPressed(GLFW_KEY_DOWN) == BUTTON_PRESSED) { } else if (window.keyPressed(GLFW_KEY_DOWN) == BUTTON_PRESSED) {
state = STATE_DOWN; state = STATE_DOWN;
attackAngle = DOWN_ANGLE_ORIGIN;
angleDeviation = DOWN_ANGLE_DEVIATION;
attackPower = DOWN_ATTACK_POWER;
attackAngleRange = DOWN_ANGLE_RANGE;
//rect.setColor(1, 0, 0);
} }
if (state != STATE_REST) { if (state != STATE_REST) {
attackTimer = 0; attackTimer = 0;
} }
} }
final float ATTACK_BEGIN = 0.05f;
final float ATTACK_ACTIVE = 0.25f;
final float ATTACK_HOLD = 0.3f;
final float ATTACK_END = 0.4f;
if (state != STATE_REST) { if (state != STATE_REST) {
final float ATTACK_BEGIN = 0.05f;
final float ATTACK_ACTIVE = 0.35f;
final float ATTACK_HOLD = 0.4f;
final float ATTACK_END = 0.5f;
if (attackTimer < ATTACK_BEGIN) { if (attackTimer < ATTACK_BEGIN) {
sprite.set(0, 0.2f * state); sprite.set(0, 0.2f * state);
effectTime = 0; effectTime = 0;
} else if (attackTimer < ATTACK_ACTIVE) { } else if (attackTimer < ATTACK_ACTIVE) {
sprite.set(0.5f, 0.2f * state); sprite.set(0.5f, 0.2f * state);
effectTime = Math.min((attackTimer - ATTACK_BEGIN) / (ATTACK_ACTIVE - ATTACK_BEGIN) * 4, 1); effectTime = Math.min((attackTimer - ATTACK_BEGIN) / (ATTACK_ACTIVE - ATTACK_BEGIN) * 4, 1);
} else if (attackTimer < ATTACK_HOLD) { } else if (attackTimer < ATTACK_HOLD + attackDelay) {
sprite.set(0.5f, 0.2f * state); sprite.set(0.5f, 0.2f * state);
effectTime = 1; effectTime = 1;
} else if (attackTimer < ATTACK_END) { } else if (attackTimer < ATTACK_END + attackDelay) {
sprite.set(0.5f, 0.2f * state); sprite.set(0.5f, 0.2f * state);
effectTime = 1 + (attackTimer - ATTACK_ACTIVE) / (ATTACK_END - ATTACK_ACTIVE); effectTime = 1 + (attackTimer - attackDelay - ATTACK_HOLD) / (ATTACK_END - ATTACK_HOLD);
} else { } else {
hit = false;
state = STATE_REST; state = STATE_REST;
attackTimer = 0; attackTimer = 0;
idleTime = 0; idleTime = 0;
attackDelay = 0;
} }
offset.set(0, 0, 0); offset.set(0, 0, 0);
} else { } else {
sprite.set(0, 0); sprite.set(0, 0);
} }
attackTimer += adtime;
final float JUMP_SPEED = 812;
final float DECELERATION = 1024; final float DECELERATION = 1024;
final float DIRECTIONAL_ACCELERATION = 2960; final float DIRECTIONAL_ACCELERATION = 4096;
final float HIGH_SPEED_DECELERATION = 1762; final float HIGH_SPEED_DECELERATION = 3120;
final float TERMINAL_VELOCITY = 1762; final float TERMINAL_VELOCITY = 1762;
final float GRAVITY = 1762; final float GRAVITY = 1762;
final float SPEED = 768; final float SPEED = 1024;
// R.I.P. STRONTCH_AND_SCRONTCH 2020-2020
float friction = 0; float friction = 0;
float floor = 0; float floor = 0;
Vector3f acceleration = new Vector3f(0, GRAVITY, 0); Vector3f acceleration = new Vector3f(0, GRAVITY, 0);
attackTimer += dtime;
if (window.keyPressed(GLFW_KEY_A) >= BUTTON_PRESSED) { if (window.keyPressed(GLFW_KEY_A) >= BUTTON_PRESSED) {
floor = -SPEED; floor = -SPEED;
if (velocity.x > -SPEED) { if (velocity.x > -SPEED) {
@ -171,7 +245,7 @@ public class Player extends Rect {
} }
} }
if (window.keyPressed(GLFW_KEY_S) == BUTTON_PRESSED && velocity.y >= 0) { if (window.keyPressed(GLFW_KEY_S) == BUTTON_PRESSED) {
velocity.y = TERMINAL_VELOCITY; velocity.y = TERMINAL_VELOCITY;
} else { } else {
float absVelocityY = Math.abs(velocity.y()); float absVelocityY = Math.abs(velocity.y());
@ -180,21 +254,46 @@ public class Player extends Rect {
} }
} }
final float HORIZONTAL_JUMP_INFLUENCE = 512; final float FULL_HOP_TIME = 5.0f / 60.0f;
if ((window.keyPressed(GLFW_KEY_W) == BUTTON_PRESSED final float SHORT_HOP_SPEED = 694;
|| window.keyPressed(GLFW_KEY_SPACE) == BUTTON_PRESSED)) { final float FULL_HOP_SPEED = 1024;
velocity.y = -JUMP_SPEED; final float HORIZONTAL_FULL_HOP_INFLUENCE = 512;
if (window.keyPressed(GLFW_KEY_A) >= BUTTON_PRESSED) { final float HORIZONTAL_SHORT_HOP_INFLUENCE = 382;
velocity.x -= HORIZONTAL_JUMP_INFLUENCE; if ((window.keyPressed(GLFW_KEY_W) >= BUTTON_PRESSED
if (velocity.x < -SPEED) { || window.keyPressed(GLFW_KEY_SPACE) >= BUTTON_PRESSED)) {
velocity.x = -SPEED; if (jumpTime >= FULL_HOP_TIME && jumpReset) {
} jumpReset = false;
} else if (window.keyPressed(GLFW_KEY_D) >= BUTTON_PRESSED) { velocity.y = -FULL_HOP_SPEED;
velocity.x += HORIZONTAL_JUMP_INFLUENCE; if (window.keyPressed(GLFW_KEY_A) >= BUTTON_PRESSED) {
if (velocity.x > SPEED) { velocity.x -= HORIZONTAL_FULL_HOP_INFLUENCE;
velocity.x = SPEED; if (velocity.x < -SPEED) {
velocity.x = -SPEED;
}
} else if (window.keyPressed(GLFW_KEY_D) >= BUTTON_PRESSED) {
velocity.x += HORIZONTAL_FULL_HOP_INFLUENCE;
if (velocity.x > SPEED) {
velocity.x = SPEED;
}
} }
} }
jumpTime += dtime;
} else if (jumpTime > 0) {
if (jumpTime < FULL_HOP_TIME) {
velocity.y = -SHORT_HOP_SPEED;
if (window.keyPressed(GLFW_KEY_A) >= BUTTON_PRESSED) {
velocity.x -= HORIZONTAL_SHORT_HOP_INFLUENCE;
if (velocity.x < -SPEED) {
velocity.x = -SPEED;
}
} else if (window.keyPressed(GLFW_KEY_D) >= BUTTON_PRESSED) {
velocity.x += HORIZONTAL_SHORT_HOP_INFLUENCE;
if (velocity.x > SPEED) {
velocity.x = SPEED;
}
}
}
jumpTime = 0;
jumpReset = true;
} }
if (velocity.x == 0 && grounded) { if (velocity.x == 0 && grounded) {
@ -207,7 +306,6 @@ public class Player extends Rect {
offset.y = 0; offset.y = 0;
} }
grounded = false;
velocity.add(acceleration.mul((float) dtime, new Vector3f())); velocity.add(acceleration.mul((float) dtime, new Vector3f()));
float degradedVelocity = velocity.x() + friction * (float) dtime; float degradedVelocity = velocity.x() + friction * (float) dtime;
// If the acceleration due to friction would accelerate it past the speed floor set it to the speed floor // If the acceleration due to friction would accelerate it past the speed floor set it to the speed floor
@ -248,7 +346,7 @@ public class Player extends Rect {
Vector3f translation = velocity.mul((float) dtime, new Vector3f()); Vector3f translation = velocity.mul((float) dtime, new Vector3f());
Vector3f translationCopy = new Vector3f(translation); Vector3f translationCopy = new Vector3f(translation);
if (window.keyPressed(GLFW_KEY_LEFT_SHIFT) < BUTTON_PRESSED && window.keyPressed(GLFW_KEY_RIGHT_SHIFT) < BUTTON_PRESSED && translation.y > 0) { if (window.keyPressed(GLFW_KEY_LEFT_SHIFT) < BUTTON_PRESSED && window.keyPressed(GLFW_KEY_RIGHT_SHIFT) < BUTTON_PRESSED && translation.y > 0 && (window.keyPressed(GLFW_KEY_S) != BUTTON_PRESSED || !grounded)) {
Vector3f bottomLeft = new Vector3f(position).add( scaledCollisionOffsets.x, height - scaledCollisionOffsets.w, 0); Vector3f bottomLeft = new Vector3f(position).add( scaledCollisionOffsets.x, height - scaledCollisionOffsets.w, 0);
Vector3f bottomRight = new Vector3f(position).add(width - scaledCollisionOffsets.y, height - scaledCollisionOffsets.w, 0); Vector3f bottomRight = new Vector3f(position).add(width - scaledCollisionOffsets.y, height - scaledCollisionOffsets.w, 0);
for (int i = 0; i < platforms.length; ++i) { for (int i = 0; i < platforms.length; ++i) {
@ -330,6 +428,46 @@ public class Player extends Rect {
positions[i].set(position); positions[i].set(position);
} }
} }
if (state != STATE_REST && attackTimer > ATTACK_BEGIN && attackTimer <= ATTACK_ACTIVE && !hit) {
final float HITBOX_RADIUS = 97.333f;
final float SWEET_SPOT_RADIUS = 20.0f;
Vector3f displacement = egg.getOrigin().sub(width / 2, height / 2, 0).sub(position);
displacement.z = 0;
//rect.setPosition(new Vector3f(position).add(displacement.mul(HITBOX_RADIUS / displacement.length(), new Vector3f())).add(width / 2, height / 2, 0));
float theta = (float) Math.atan2(displacement.y, displacement.x);
float difference = Math.abs(theta - attackAngle);
if (difference > Math.PI) {
difference = 2.0f * (float) Math.PI - difference;
}
if (difference < attackAngleRange) {
float radius = egg.getRadius(theta);
float distance = displacement.length();
float launchVelocity = 0;
float blah = distance - HITBOX_RADIUS;
if (-SWEET_SPOT_RADIUS < blah && blah < SWEET_SPOT_RADIUS) {
hit = true;
launchVelocity = attackPower.y;
sweet.play(false);
final float SWEET_SPOT_FREEZE_DURATION = 0.35f;
Main.freeze(SWEET_SPOT_FREEZE_DURATION);
attackDelay = SWEET_SPOT_FREEZE_DURATION;
} else if (-radius < blah && blah < radius) {
hit = true;
launchVelocity = attackPower.x;
sour.play(false);
}
if (launchVelocity != 0) {
//rect.setColor(0, 1, 0);
float launchAngle = (theta - attackAngle) / (float) Math.PI * 3.0f * angleDeviation + attackAngle;
egg.launch(new Vector3f(launchVelocity * (float) Math.cos(launchAngle), launchVelocity * (float) Math.sin(launchAngle), 0));
}
}
}
} }
public void render() { public void render() {
@ -349,5 +487,6 @@ public class Player extends Rect {
textures[3].bind(); textures[3].bind();
vao.render(); vao.render();
} }
//rect.render();
} }
} }

View file

@ -0,0 +1,13 @@
package com.gnarwhal.ld46.game;
import com.gnarwhal.ld46.engine.display.Camera;
import com.gnarwhal.ld46.engine.model.Rect;
public class Ripple extends Rect {
public Ripple(Camera camera, float x, float y, float r, float g, float b, float a) {
super(camera, x, y, -0.3f, 0, 0, 0, false);
}
}