added old man npc and AI

This commit is contained in:
2025-11-28 17:05:23 +01:00
parent 1c23a1528e
commit c4d6539db7
4 changed files with 71 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import de.miaurizius.jgame2d.core.handlers.AssetSetter;
import de.miaurizius.jgame2d.core.handlers.CollisionHandler;
import de.miaurizius.jgame2d.core.handlers.KeyHandler;
import de.miaurizius.jgame2d.core.handlers.Sound;
import de.miaurizius.jgame2d.entity.Entity;
import de.miaurizius.jgame2d.entity.Player;
import de.miaurizius.jgame2d.object.SuperObject;
import de.miaurizius.jgame2d.tile.TileManager;
@@ -47,6 +48,7 @@ public class GamePanel extends JPanel implements Runnable {
// ENTITY AND OBJECT
public Player player = new Player(this, keyH);
public SuperObject[] obj = new SuperObject[10];
public Entity[] npc = new Entity[10];
// GAME STATE
public GameState gameState;
@@ -61,6 +63,7 @@ public class GamePanel extends JPanel implements Runnable {
public void setupGame() {
assetSetter.setObject();
assetSetter.setNPC();
playMusic(0); //Play main theme
gameState = GameState.PLAY;
}
@@ -103,6 +106,7 @@ public class GamePanel extends JPanel implements Runnable {
switch(gameState) {
case PLAY:
player.update();
for(Entity entity : npc) if(entity != null) entity.update();
break;
case PAUSE:
break;
@@ -117,9 +121,10 @@ public class GamePanel extends JPanel implements Runnable {
long drawStart = 0;
drawStart = System.nanoTime();
//Draw all components
// COMPONENTS
tileM.draw(graphics2d);
for (SuperObject superObject : obj) if (superObject != null) superObject.draw(graphics2d, this);
for(Entity npc : npc) if(npc != null) npc.draw(graphics2d);
player.draw(graphics2d);
ui.draw(graphics2d);