added old man npc and AI
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user