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

@@ -3,6 +3,8 @@ package de.miaurizius.jgame2d.entity;
import de.miaurizius.jgame2d.core.enums.Direction;
import de.miaurizius.jgame2d.core.GamePanel;
import java.util.Random;
public class OldManNPC extends Entity {
public OldManNPC(GamePanel panel) {
@@ -24,4 +26,17 @@ public class OldManNPC extends Entity {
right2 = initEntitySprites("npc/oldman_right_2");
}
public void setAction() {
actionLock++;
if(actionLock != 120) return; //lock action for x frames
Random rand = new Random();
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
if(i <= 25) direction = Direction.UP;
if(i > 25 && i <= 50) direction = Direction.DOWN;
if(i > 50 && i <= 75) direction = Direction.LEFT;
if(i > 75) direction = Direction.RIGHT;
actionLock = 0;
}
}