Final project

This commit is contained in:
Gnarwhal 2024-08-07 05:04:19 +00:00
parent 0e85a338c5
commit 8a6d28bf20
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
14 changed files with 463 additions and 143 deletions

BIN
DJam 2.jar Normal file

Binary file not shown.

BIN
res/img/ui/begin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
res/img/ui/dead.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
res/img/ui/win.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -0,0 +1,210 @@
16
4
10 10 0
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
17 0.12903225806
1 0.38709677418
11 0.12903225806
4
10 10 0.624
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
14 0.12903225806
1 0.38709677418
14 0.12903225806
4
10 10 1.25
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
17 0.12903225806
1 0.38709677418
11 0.12903225806
4
10 10 1.875
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
17 0.12903225806
1 0.38709677418
11 0.12903225806
4
10 10 2.5
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
21 0.12903225806
1 0.38709677418
7 0.12903225806
4
10 10 3.125
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
16 0.12903225806
1 0.38709677418
12 0.12903225806
4
10 10 3.75
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
15 0.12903225806
1 0.38709677418
13 0.12903225806
4
10 10 4.375
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
12 0.12903225806
1 0.38709677418
16 0.12903225806
4
10 10 5.0
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
7 0.12903225806
1 0.38709677418
21 0.12903225806
4
10 10 5.625
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
9 0.12903225806
1 0.38709677418
19 0.12903225806
4
10 10 6.25
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
14 0.12903225806
1 0.38709677418
14 0.12903225806
4
10 10 6.875
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
17 0.12903225806
1 0.38709677418
11 0.12903225806
4
10 10 7.5
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
15 0.12903225806
1 0.38709677418
13 0.12903225806
4
10 10 8.125
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
12 0.12903225806
1 0.38709677418
16 0.12903225806
4
10 10 8.75
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
13 0.12903225806
1 0.38709677418
15 0.12903225806
4
10 10 9.375
4 1 4 1
732 0
0 32
-732 0
0 -32
30 1
1 5
17 0.12903225806
1 0.38709677418
11 0.12903225806

3
src/META-INF/MANIFEST.MF Normal file
View file

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.gnarly.game.Main

View file

@ -100,6 +100,8 @@ public class BulletList {
enemies.remove(j); enemies.remove(j);
--j; --j;
} }
bullets.remove(i);
--i;
} }
} }
bullet.position.add(deltaV); bullet.position.add(deltaV);
@ -120,8 +122,11 @@ public class BulletList {
Vector2f deltaV = bullet.velocity.mul((float) Main.dtime, new Vector2f()); Vector2f deltaV = bullet.velocity.mul((float) Main.dtime, new Vector2f());
Collision.Bounds bounds = player.getBounds(); Collision.Bounds bounds = player.getBounds();
Vector2f[] segments = player.getSegments(); Vector2f[] segments = player.getSegments();
if (Collision.collide(bounds, segments, player.getVelocity(), bullet)) if (Collision.collide(bounds, segments, player.getVelocity(), bullet)) {
player.damage(bullet.damage); player.damage(bullet.damage);
bullets.remove(i);
--i;
}
bullet.position.add(deltaV); bullet.position.add(deltaV);
bullet.boundingPosition.add(deltaV); bullet.boundingPosition.add(deltaV);

View file

@ -42,7 +42,6 @@ public class Collision {
Vector2f scaledBV = bullet.velocity.mul((float) Main.dtime, new Vector2f()); Vector2f scaledBV = bullet.velocity.mul((float) Main.dtime, new Vector2f());
Bounds bounds = getBounds(position, dimensions, boundVelocity); Bounds bounds = getBounds(position, dimensions, boundVelocity);
Bounds bulletBounds = getBounds(bullet.boundingPosition, bullet.bounds, scaledBV); Bounds bulletBounds = getBounds(bullet.boundingPosition, bullet.bounds, scaledBV);
GamePanel.show.set(position.x, position.y, bounds.dimensions.x, bounds.dimensions.y);
if (overlap(bounds, bulletBounds)) { if (overlap(bounds, bulletBounds)) {
Vector2f[] boundsSegments = new Vector2f[] { Vector2f[] boundsSegments = new Vector2f[] {
position, position,
@ -97,52 +96,48 @@ public class Collision {
public static boolean segmentCollision(Vector2f P1, Vector2f D1, Vector2f V1, Vector2f P2, Vector2f D2, Vector2f V2) { public static boolean segmentCollision(Vector2f P1, Vector2f D1, Vector2f V1, Vector2f P2, Vector2f D2, Vector2f V2) {
final float EPSILON = 0.000001f; final float EPSILON = 0.000001f;
if ((V1.length() == 0 && V2.length() > 0) if (V1.length() > 0) {
|| (V2.length() == 0 && V1.length() > 0) float b = (P1.x - P2.x + (V1.x - V2.x) * (P2.y - P1.y) / (V1.y - V2.y)) / (D2.x - D2.y * (V1.x - V2.x) / (V1.y - V2.y));
|| Math.abs(V1.angle(V2)) > EPSILON) { if (rangeCheck(b)) {
if (V1.length() > 0) { float t;
float b = (P1.x - P2.x + (V1.x - V2.x) * (P2.y - P1.y) / (V1.y - V2.y)) / (D2.x - D2.y * (V1.x - V2.x) / (V1.y - V2.y)); if (V1.y == 0)
if (rangeCheck(b)) { t = (P1.x + D1.x - P2.x - D2.x * b) / (V2.x - V1.x);
float t; else
if (V1.y == 0) t = (P1.y + D1.y - P2.y - D2.y * b) / (V2.y - V1.y);
t = (P1.x + D1.x - P2.x - D2.x * b) / (V2.x - V1.x); if (rangeCheck(t))
else return true;
t = (P1.y + D1.y - P2.y - D2.y * b) / (V2.y - V1.y);
if (rangeCheck(t))
return true;
}
b = (P1.x + D1.x - P2.x + (V1.x - V2.x) * (P2.y - P1.y - D1.y) / (V1.y - V2.y)) / (D2.x - D2.y * (V1.x - V2.x) / (V1.y - V2.y));
if (rangeCheck(b)) {
float t;
if (V1.y == 0)
t = (P1.x + D1.x - P2.x - D2.x * b) / (V2.x - V1.x);
else
t = (P1.y + D1.y - P2.y - D2.y * b) / (V2.y - V1.y);
if (rangeCheck(t))
return true;
}
} }
if (V2.length() > 0) { b = (P1.x + D1.x - P2.x + (V1.x - V2.x) * (P2.y - P1.y - D1.y) / (V1.y - V2.y)) / (D2.x - D2.y * (V1.x - V2.x) / (V1.y - V2.y));
float a = (P2.x - P1.x - (V1.x - V2.x) * (P1.y - P2.y) / (V2.y - V1.y)) / (D1.x + D1.y * (V1.x - V2.x) / (V2.y - V1.y)); if (rangeCheck(b)) {
if (rangeCheck(a)) { float t;
float t; if (V1.y == 0)
if (V2.y == 0) t = (P1.x + D1.x - P2.x - D2.x * b) / (V2.x - V1.x);
t = (P1.x + D1.x * a - P2.x - D2.x) / (V2.x - V1.x); else
else t = (P1.y + D1.y - P2.y - D2.y * b) / (V2.y - V1.y);
t = (P1.y + D1.y * a - P2.y - D2.y) / (V2.y - V1.y); if (rangeCheck(t))
if (rangeCheck(t)) return true;
return true; }
} }
a = (P2.x + D2.x - P1.x - (V1.x - V2.x) * (P1.y - P2.y - D2.y) / (V2.y - V1.y)) / (D1.x + D1.y * (V1.x - V2.x) / (V2.y - V1.y)); if (V2.length() > 0) {
if (rangeCheck(a)) { float a = (P2.x - P1.x - (V1.x - V2.x) * (P1.y - P2.y) / (V2.y - V1.y)) / (D1.x + D1.y * (V1.x - V2.x) / (V2.y - V1.y));
float t; if (rangeCheck(a)) {
if (V2.y == 0) float t;
t = (P1.x + D1.x * a - P2.x - D2.x) / (V2.x - V1.x); if (V2.y == 0)
else t = (P1.x + D1.x * a - P2.x - D2.x) / (V2.x - V1.x);
t = (P1.y + D1.y * a - P2.y - D2.y) / (V2.y - V1.y); else
if (rangeCheck(t)) t = (P1.y + D1.y * a - P2.y - D2.y) / (V2.y - V1.y);
return true; if (rangeCheck(t))
} return true;
}
a = (P2.x + D2.x - P1.x - (V1.x - V2.x) * (P1.y - P2.y - D2.y) / (V2.y - V1.y)) / (D1.x + D1.y * (V1.x - V2.x) / (V2.y - V1.y));
if (rangeCheck(a)) {
float t;
if (V2.y == 0)
t = (P1.x + D1.x * a - P2.x - D2.x) / (V2.x - V1.x);
else
t = (P1.y + D1.y * a - P2.y - D2.y) / (V2.y - V1.y);
if (rangeCheck(t))
return true;
} }
} }
return false; return false;

View file

@ -2,16 +2,23 @@ package com.gnarly.game;
import com.gnarly.engine.display.Camera; import com.gnarly.engine.display.Camera;
import com.gnarly.engine.display.Window; import com.gnarly.engine.display.Window;
import com.gnarly.engine.model.ColRect; import com.gnarly.engine.model.TexRect;
import com.gnarly.game.enemies.BasicEnemy;
import com.gnarly.game.enemies.Enemy; import com.gnarly.game.enemies.Enemy;
import org.joml.Vector2f;
import java.util.ArrayList; import java.util.ArrayList;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE; import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE;
public class GamePanel extends Panel { public class GamePanel {
private static final int
STATE_PRE = 0x00,
STATE_PLAYING = 0x01,
STATE_DEAD = 0x02,
STATE_WIN = 0x03;
private static final float
DELAY = 0.75f;
private Window window; private Window window;
private Camera camera; private Camera camera;
@ -24,79 +31,99 @@ public class GamePanel extends Panel {
private ArrayList<Enemy> enemies; private ArrayList<Enemy> enemies;
public static ColRect show; private Level level;
private int state = STATE_PRE;
private TexRect begin;
private TexRect dead;
private TexRect win;
private boolean restart = false;
private float time;
public GamePanel(Window window, Camera camera) { public GamePanel(Window window, Camera camera) {
this.window = window; this.window = window;
this.camera = camera; this.camera = camera;
enemies = new ArrayList<Enemy>(); enemies = new ArrayList<Enemy>();
enemies.add(new BasicEnemy(camera, 200, 200, 4,
new float[] {
3, 1, 3, 1
},
new Vector2f[] {
new Vector2f( 300, 0),
new Vector2f( 0, 100),
new Vector2f(-300, 0),
new Vector2f( 0, -100),
}
));
enemies.add(new BasicEnemy(camera, 200, 200, 0,
new float[] {
3, 1, 3, 1
},
new Vector2f[] {
new Vector2f( 300, 0),
new Vector2f( 0, 100),
new Vector2f(-300, 0),
new Vector2f( 0, -100),
}
));
playerBullets = new BulletList(camera); playerBullets = new BulletList(camera);
enemyBullets = new BulletList(camera); enemyBullets = new BulletList(camera);
enemyBullets.spawnBullet(new Vector2f(camera.getWidth() / 2, 25), (float) Math.PI, BulletList.TYPE_SMOL, 400, 1);
level = new Level(camera, "res/levels/level1.txt", enemies, enemyBullets);
background = new Background(camera); background = new Background(camera);
player = new Player(window, camera, playerBullets); player = new Player(window, camera, playerBullets);
state = Main.GAME_PANEL; begin = new TexRect(camera, "res/img/ui/begin.png", 0, 0, 0, camera.getWidth(), camera.getHeight(), 0, false);
dead = new TexRect(camera, "res/img/ui/dead.png", 0, 0, 0, camera.getWidth(), camera.getHeight(), 0, false);
show = new ColRect(camera, 0, 0, 0, 100, 100, 1, 0, 0, 0.5f, false); win = new TexRect(camera, "res/img/ui/win.png", 0, 0, 0, camera.getWidth(), camera.getHeight(), 0, false);
} }
public void update() { public void update() {
background.update(); background.update();
player.update(); if (state == STATE_PRE) {
for (int i = 0; i < enemies.size(); ++i) player.updateAnim();
enemies.get(i).update();
playerBullets.update(enemies); if (window.keyPressed(GLFW_KEY_SPACE) == Window.BUTTON_PRESSED)
enemyBullets.update(player); state = STATE_PLAYING;
}
else if (state == STATE_PLAYING) {
player.update();
for (int i = 0; i < enemies.size(); ++i)
enemies.get(i).update();
player.applyMovement(); playerBullets.update(enemies);
for (int i = 0; i < enemies.size(); ++i) enemyBullets.update(player);
enemies.get(i).applyMovement();
if (player.getHealth() <= 0) {
state = STATE_DEAD;
}
else if (enemies.size() == 0) {
state = STATE_WIN;
}
player.applyMovement();
for (int i = 0; i < enemies.size(); ++i)
enemies.get(i).applyMovement();
}
else if (state == STATE_DEAD) {
time += Main.dtime;
if (window.keyPressed(GLFW_KEY_SPACE) == Window.BUTTON_PRESSED && time > DELAY)
restart = true;
}
else if (state == STATE_WIN) {
player.updateAnim();
time += Main.dtime;
if (window.keyPressed(GLFW_KEY_SPACE) == Window.BUTTON_PRESSED && time > DELAY)
restart = true;
}
} }
public void render() { public void render() {
background.render(); background.render();
enemyBullets.render(); if (state == STATE_PRE) {
playerBullets.render(); player.render();
for(int i = 0; i < enemies.size(); ++i) begin.render();
enemies.get(i).render(); }
player.render(); else if (state == STATE_PLAYING) {
show.render(); enemyBullets.render();
playerBullets.render();
for (int i = 0; i < enemies.size(); ++i)
enemies.get(i).render();
player.render();
}
else if (state == STATE_DEAD) {
dead.render();
}
else if (state == STATE_WIN) {
player.render();
win.render();
}
} }
public void reset() {
} public boolean restart() {
return restart;
public int checkState() {
int state = this.state;
this.state = Main.GAME_PANEL;
return state;
} }
} }

View file

@ -0,0 +1,58 @@
package com.gnarly.game;
import com.gnarly.engine.display.Camera;
import com.gnarly.game.enemies.BasicEnemy;
import com.gnarly.game.enemies.Enemy;
import org.joml.Vector2f;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Level {
private String path;
private Camera camera;
private ArrayList<Enemy> enemies;
public Level(Camera camera, String path, ArrayList<Enemy> enemies, BulletList bullets) {
try {
FileInputStream stream = new FileInputStream(path);
Scanner scanner = new Scanner(stream);
int numShips = scanner.nextInt();
for (int i = 0; i < numShips; ++i) {
int numPath = scanner.nextInt();
float x = scanner.nextFloat();
float y = scanner.nextFloat();
float timeOffset = scanner.nextFloat();
float[] times = new float[numPath];
for (int j = 0; j < numPath; ++j)
times[j] = scanner.nextFloat();
Vector2f[] shipPath = new Vector2f[numPath];
for (int j = 0; j < numPath; ++j)
shipPath[j] = new Vector2f(scanner.nextFloat(), scanner.nextFloat());
int fireCount = scanner.nextInt();
float padEnd = scanner.nextFloat();
float[] fireTimes = new float[fireCount + 1];
for (int writeIndex = 0; writeIndex < fireCount;) {
int reps = scanner.nextInt();
float delta = scanner.nextFloat();
for (int j = writeIndex; j < writeIndex + reps; ++j)
fireTimes[j] = delta;
writeIndex += reps;
}
fireTimes[fireCount] = padEnd;
enemies.add(new BasicEnemy(camera, x, y, timeOffset, times, shipPath, fireTimes, bullets));
}
scanner.close();
stream.close();
this.camera = camera;
this.path = path;
this.enemies = enemies;
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -12,19 +12,14 @@ import java.io.IOException;
public class Main { public class Main {
public static int fps; public static int fps;
public static double dtime; public static double dtime;
public static final int
NUM_PANELS = 1,
GAME_PANEL = 0;
private ALManagement al; private ALManagement al;
private Window window; private Window window;
private Camera camera; private Camera camera;
private Panel[] panels; private GamePanel panel;
private int panel;
private Sound sound; private Sound sound;
@ -59,15 +54,28 @@ public class Main {
} }
private void init() { private void init() {
int position = 15;
for (int i = 0; i < 16; ++i) {
int movement = (int) (Math.random() * 11) - 5;
if (position + movement < 5 || position + movement > 27)
position -= movement;
else
position += movement;
/*System.out.println(" --- ");
System.out.println("30 1");
System.out.println("1 5");
System.out.println(position + " 0.12903225806");
System.out.println("1 0.38709677418 ");
System.out.println((28 - position) + " 0.12903225806");*/
}
al = new ALManagement(); al = new ALManagement();
//window = new Window("Gamer Time", true); window = new Window("Gamer Time", true);
window = new Window(768, 432, "Gamer Time", true, true, true); //window = new Window(768, 432, "Gamer Time", true, true, true);
camera = new Camera(768, 432); camera = new Camera(768, 432);
Shader.init(); Shader.init();
panels = new Panel[NUM_PANELS]; panel = new GamePanel(window, camera);
panels[GAME_PANEL] = new GamePanel(window, camera);
panel = GAME_PANEL;
sound = new Sound("res/audio/theme.wav"); sound = new Sound("res/audio/theme.wav");
sound.play(true); sound.play(true);
@ -75,22 +83,15 @@ public class Main {
private void update() { private void update() {
window.update(); window.update();
int state = panels[panel].checkState(); panel.update();
if (state != panel) { if (panel.restart())
switch (state) { panel = new GamePanel(window, camera);
case GAME_PANEL:
GamePanel game = (GamePanel) panels[GAME_PANEL];
game.reset();
}
panel = state;
}
panels[panel].update();
camera.update(); camera.update();
} }
private void render() { private void render() {
window.clear(); window.clear();
panels[panel].render(); panel.render();
window.swap(); window.swap();
} }

View file

@ -1,10 +0,0 @@
package com.gnarly.game;
public abstract class Panel {
protected int state;
public abstract void update();
public abstract void render();
public abstract int checkState();
}

View file

@ -15,7 +15,7 @@ public class Player extends TexRect {
private double spf = 1.0 / 14.0; private double spf = 1.0 / 14.0;
private double time = 0; private double time = 0;
private int frame = 0; private int frame = 0;
private float speed = 150; private float speed = 250;
private int health = 5; private int health = 5;
private Vector2f velocity = new Vector2f(); private Vector2f velocity = new Vector2f();
@ -24,7 +24,7 @@ public class Player extends TexRect {
private BulletList bullets; private BulletList bullets;
public Player(Window window, Camera camera, BulletList bullets) { public Player(Window window, Camera camera, BulletList bullets) {
super(camera, (Texture) null, camera.getWidth() / 2 - 16, camera.getHeight() / 2 - 16, -0.1f, 32, 32, 0, false); super(camera, (Texture) null, camera.getWidth() / 2 - 16, camera.getHeight() * 3 / 4 - 16, -0.1f, 32, 32, 0, false);
this.window = window; this.window = window;
this.bullets = bullets; this.bullets = bullets;
@ -42,7 +42,7 @@ public class Player extends TexRect {
public void update() { public void update() {
float speedMultiplier = 1; float speedMultiplier = 1;
if (window.keyPressed(GLFW_KEY_LEFT_SHIFT) >= Window.BUTTON_PRESSED) if (window.keyPressed(GLFW_KEY_LEFT_SHIFT) >= Window.BUTTON_PRESSED)
speedMultiplier *= 1.5; speedMultiplier *= 2;
else if (window.keyPressed(GLFW_KEY_LEFT_CONTROL) >= Window.BUTTON_PRESSED) else if (window.keyPressed(GLFW_KEY_LEFT_CONTROL) >= Window.BUTTON_PRESSED)
speedMultiplier *= 0.5; speedMultiplier *= 0.5;
@ -67,15 +67,19 @@ public class Player extends TexRect {
else if (position.y + height + velocity.y >= camera.getHeight()) else if (position.y + height + velocity.y >= camera.getHeight())
velocity.y = camera.getHeight() - height - position.y; velocity.y = camera.getHeight() - height - position.y;
updateAnim();
if (window.keyPressed(GLFW_KEY_SPACE) == Window.BUTTON_PRESSED)
bullets.spawnBullet(new Vector2f(position.x + width / 2, position.y - BulletList.getHeight(BulletList.TYPE_PLAYER)), 0, BulletList.TYPE_PLAYER, 400, 1);
}
public void updateAnim() {
time += Main.dtime; time += Main.dtime;
while (time >= spf) { while (time >= spf) {
time -= spf; time -= spf;
frame = (frame + 1) % frames.length; frame = (frame + 1) % frames.length;
setTexture(frames[frame]); setTexture(frames[frame]);
} }
if (window.keyPressed(GLFW_KEY_SPACE) == Window.BUTTON_PRESSED)
bullets.spawnBullet(new Vector2f(position.x + width / 2, position.y - BulletList.getHeight(BulletList.TYPE_PLAYER)), 0, BulletList.TYPE_PLAYER, 400, 1);
} }
public Collision.Bounds getBounds() { public Collision.Bounds getBounds() {

View file

@ -4,6 +4,7 @@ import com.gnarly.engine.display.Camera;
import com.gnarly.engine.shaders.Shader; import com.gnarly.engine.shaders.Shader;
import com.gnarly.engine.shaders.Shader2t; import com.gnarly.engine.shaders.Shader2t;
import com.gnarly.engine.texture.TextureSet; import com.gnarly.engine.texture.TextureSet;
import com.gnarly.game.BulletList;
import com.gnarly.game.Main; import com.gnarly.game.Main;
import org.joml.Vector2f; import org.joml.Vector2f;
@ -13,6 +14,9 @@ public class BasicEnemy extends Enemy {
public static final float DIMS = 16; public static final float DIMS = 16;
private static final Vector2f FIRE_OFFSET = new Vector2f(DIMS / 2, DIMS);
private static TextureSet textures = null; private static TextureSet textures = null;
private Shader2t shader = Shader.SHADER2T; private Shader2t shader = Shader.SHADER2T;
@ -25,7 +29,13 @@ public class BasicEnemy extends Enemy {
private Vector2f start; private Vector2f start;
private Vector2f origin; private Vector2f origin;
public BasicEnemy(Camera camera, float x, float y, float timeOffset, float[] times, Vector2f[] path) { private float pastFire;
private int fireIndex;
private float[] fireTimes;
private BulletList bullets;
public BasicEnemy(Camera camera, float x, float y, float timeOffset, float[] times, Vector2f[] path, float[] fireTimes, BulletList bullets) {
super(camera, 0, 0, DIMS, DIMS, 1); super(camera, 0, 0, DIMS, DIMS, 1);
this.timing = times; this.timing = times;
this.path = path; this.path = path;
@ -44,13 +54,20 @@ public class BasicEnemy extends Enemy {
passedTime += times[timeIndex]; passedTime += times[timeIndex];
start.add(path[timeIndex]); start.add(path[timeIndex]);
} }
timeOffset = time;
for (; (timeOffset -= fireTimes[fireIndex]) >= 0; fireIndex = (fireIndex + 1) % fireTimes.length)
pastFire += fireTimes[fireIndex];
origin = new Vector2f(x, y); origin = new Vector2f(x, y);
this.fireTimes = fireTimes;
this.bullets = bullets;
} }
@Override @Override
public void update() { public void update() {
position.sub(origin.x, origin.y, 0);
time += Main.dtime; time += Main.dtime;
position.sub(origin.x, origin.y, 0);
float interp; float interp;
while ((interp = (time - passedTime) / timing[timeIndex]) > 1) { while ((interp = (time - passedTime) / timing[timeIndex]) > 1) {
passedTime += timing[timeIndex]; passedTime += timing[timeIndex];
@ -59,7 +76,17 @@ public class BasicEnemy extends Enemy {
} }
velocity = path[timeIndex].mul(interp, new Vector2f()).add(start).sub(position.x, position.y); velocity = path[timeIndex].mul(interp, new Vector2f()).add(start).sub(position.x, position.y);
position.add(origin.x, origin.y, 0); position.add(origin.x, origin.y, 0);
System.out.println(position);
if (time - pastFire > fireTimes[fireIndex]) {
if (fireIndex != fireTimes.length - 1)
fire();
pastFire += fireTimes[fireIndex];
fireIndex = (fireIndex + 1) % fireTimes.length;
}
}
public void fire() {
bullets.spawnBullet(new Vector2f(position.x, position.y).add(FIRE_OFFSET), (float) Math.PI, BulletList.TYPE_SMOL, 200, 1);
} }
@Override @Override