@@ -139,7 +139,9 @@ def perform(self) -> None:
139139 if not self .is_setup or not self .engine .game_map .visible [self .entity .x , self .entity .y ]:
140140 return WaitAction (self .entity ).perform ()
141141
142-
142+ # If we are on the flee position, set it to none
143+ if self .flee_position and self .entity .x == self .flee_position [0 ] and self .entity .y == self .flee_position [1 ]:
144+ self .flee_position = None
143145
144146 # If the spawn timer is greater than the spawn rate, spawn a new enemy.
145147 if self .spawn_timer >= self .spawn_rate :
@@ -171,26 +173,26 @@ def perform(self) -> None:
171173 # If the distance is less than 5, move away from the player.
172174 if distance < 5 :
173175 if not self .flee_position :
174- # Get a flee position, that is more than 5 tiles away from the player, but less than 20 tiles away.
176+ # Get a flee position, that is around 20 tiles away.
175177 self .flee_position = (
176- self .entity .x + random .randint (- 5 , 20 ),
177- self .entity .y + random .randint (- 5 , 20 ),
178+ self .entity .x + random .randint (- 20 , 20 ),
179+ self .entity .y + random .randint (- 20 , 20 ),
178180 )
179181
180182 while not self .engine .game_map .in_bounds (* self .flee_position ) or self .engine .game_map .get_blocking_entity_at_location (* self .flee_position ) or self .engine .game_map .tiles ["walkable" ][self .flee_position [0 ], self .flee_position [1 ]] == False :
181183 self .flee_position = (
182- self .entity .x + random .randint (- 5 , 20 ),
183- self .entity .y + random .randint (- 5 , 20 ),
184+ self .entity .x + random .randint (- 20 , 20 ),
185+ self .entity .y + random .randint (- 20 , 20 ),
184186 )
185- else :
186- # Get the direction to the flee position.
187- self .path = self .get_path_to (self .flee_position [0 ], self .flee_position [1 ])
188-
189- if self .path :
190- dest_x , dest_y = self .path .pop (0 )
191- return MovementAction (
192- self .entity , dest_x - self .entity .x , dest_y - self .entity .y ,
193- ).perform ()
187+
188+ # Get the direction to the flee position.
189+ self .path = self .get_path_to (self .flee_position [0 ], self .flee_position [1 ])
190+
191+ if self .path :
192+ dest_x , dest_y = self .path .pop (0 )
193+ return MovementAction (
194+ self .entity , dest_x - self .entity .x , dest_y - self .entity .y ,
195+ ).perform ()
194196
195197 # Add 1 to the spawn timer.
196198 self .spawn_timer += 1
0 commit comments