@@ -18,6 +18,7 @@ public class MazeCharacter extends SerializableObject {
1818 public int max_path = -1 ;
1919 public int safe_distance = 10 ;
2020 public int minimum_distance = 1 ;
21+ public boolean move_randomly = false ;
2122
2223 protected MazeCell target_cell ;
2324 protected MazeCell escape_cell ;
@@ -68,17 +69,27 @@ public JSONObject save_object() {
6869 }
6970
7071 public void set_target (MazeCell target ) {
72+ if (this .target_cell == target ) return ;
7173 this .target_cell = target ;
7274 this .escape_cell = null ;
7375 this .path = this .path_to (this .target_cell );
7476 }
7577
78+ public void chase_player () {
79+ this .set_target (TMGE .current_cell ());
80+ }
81+
7682 public void set_escape_target (MazeCell target ) {
83+ if (this .escape_cell == target ) return ;
7784 this .escape_cell = target ;
7885 this .target_cell = null ;
7986 this .path = this .escape_path (this .escape_cell );
8087 }
8188
89+ public void escape_player () {
90+ this .set_escape_target (TMGE .current_cell ());
91+ }
92+
8293 public ArrayList <Integer > path_to (MazeCell target ) {
8394 return path_to (target , this .current_cell (), false );
8495 }
@@ -189,9 +200,13 @@ protected void draw_path() {
189200 TMGE .papplet ().popStyle ();
190201 }
191202
203+ public boolean ready_to_act () {
204+ return TMGE .papplet ().frameCount - slowness > last_acted ;
205+ }
206+
192207 public void act () {
193208 // This is to slow the movement of the character
194- if (TMGE . papplet (). frameCount - slowness < last_acted ) return ;
209+ if (! this . ready_to_act () ) return ;
195210 if (this .path == null || this .path .isEmpty () || this .maze .maze_layer_dirty ) {
196211 if (escape_cell != null ) {
197212 this .path = this .escape_path (this .target_cell );
@@ -203,6 +218,9 @@ else if (target_cell != null) {
203218 if (this .path != null && !this .path .isEmpty ()) {
204219 this .move_in_direction (this .path .remove (0 ));
205220 }
221+ else if (this .move_randomly ) {
222+ this .move_in_direction ((int )(Math .random () * 5 ));
223+ }
206224 last_acted = TMGE .papplet ().frameCount ;
207225 }
208226
@@ -223,7 +241,9 @@ public boolean move_in_direction(int direction) {
223241
224242 public boolean move_up () {
225243 if (this .maze == null ) return false ;
244+ if (!this .ready_to_act ()) return false ;
226245 if (!current_cell ().wall_up ()) {
246+ last_acted = TMGE .papplet ().frameCount ;
227247 y --;
228248 return true ;
229249 }
@@ -232,7 +252,9 @@ public boolean move_up() {
232252
233253 public boolean move_down () {
234254 if (maze == null ) return false ;
255+ if (!this .ready_to_act ()) return false ;
235256 if (!current_cell ().wall_down ()) {
257+ last_acted = TMGE .papplet ().frameCount ;
236258 y ++;
237259 return true ;
238260 }
@@ -241,7 +263,9 @@ public boolean move_down() {
241263
242264 public boolean move_left () {
243265 if (maze == null ) return false ;
266+ if (!this .ready_to_act ()) return false ;
244267 if (!current_cell ().wall_left ()) {
268+ last_acted = TMGE .papplet ().frameCount ;
245269 x --;
246270 return true ;
247271 }
@@ -250,7 +274,9 @@ public boolean move_left() {
250274
251275 public boolean move_right () {
252276 if (maze == null ) return false ;
277+ if (!this .ready_to_act ()) return false ;
253278 if (!current_cell ().wall_right ()) {
279+ last_acted = TMGE .papplet ().frameCount ;
254280 x ++;
255281 return true ;
256282 }
0 commit comments