added projectile system and sample fireball projectile

This commit is contained in:
2025-12-07 00:07:47 +01:00
parent d639e65c15
commit 5da7c43edf
17 changed files with 126 additions and 6 deletions

View File

@@ -49,6 +49,7 @@ public class GamePanel extends JPanel implements Runnable {
public Entity[] obj = new Entity[10];
public Entity[] npc = new Entity[10];
public Entity[] monster = new Entity[20];
public ArrayList<Entity> projectileList = new ArrayList<>();
ArrayList<Entity> entityList = new ArrayList<>();
// GAME STATE
@@ -109,6 +110,13 @@ public class GamePanel extends JPanel implements Runnable {
if(!m.alive) monster[i] = null;
}
}
for(int i = 0; i < projectileList.size(); i++) {
Entity m = projectileList.get(i);
if(m != null) {
if(m.alive) m.update();
else projectileList.remove(i);
}
}
break;
case PAUSE:
break;
@@ -136,6 +144,7 @@ public class GamePanel extends JPanel implements Runnable {
for(Entity entity : npc) if(entity != null) entityList.add(entity);
for(Entity entity : obj) if(entity != null) entityList.add(entity);
for(Entity entity : monster) if(entity != null) entityList.add(entity);
for(Entity entity : projectileList) if(entity != null) entityList.add(entity);
entityList.sort(Comparator.comparingInt(o -> o.worldY));
for(Entity entity : entityList) entity.draw(graphics2d);
entityList.clear();

View File

@@ -7,6 +7,7 @@ public enum EntityType {
MONSTER,
ITEM,
WORLD,
PROJECTILE,
WEAPON,
SHIELD;

View File

@@ -8,7 +8,7 @@ import java.awt.event.KeyListener;
public class KeyHandler implements KeyListener {
public boolean upPressed, downPressed, leftPressed, rightPressed, spacePressed;
public boolean upPressed, downPressed, leftPressed, rightPressed, spacePressed, shotKeyPressed;
public GamePanel panel;
public boolean debug;
@@ -49,6 +49,7 @@ public class KeyHandler implements KeyListener {
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = true;
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = true;
case KeyEvent.VK_SPACE -> spacePressed = true;
case KeyEvent.VK_F -> shotKeyPressed = true;
// DEBUG OPTIONS
case KeyEvent.VK_T -> debug = !debug;
@@ -142,6 +143,7 @@ public class KeyHandler implements KeyListener {
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = false;
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = false;
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = false;
case KeyEvent.VK_F -> shotKeyPressed = false;
}
}
}

View File

@@ -26,6 +26,7 @@ public class Sound {
load(7, "assets/sounds/blocked.wav");
load(8, "assets/sounds/levelup.wav");
load(9, "assets/sounds/cursor.wav");
load(10, "assets/sounds/burning.wav");
}
@Deprecated