Skip to content

Commit ef22e70

Browse files
committed
final boids: keys 0 and 1 allow to remove / reinstate obstacles
1 parent dece46e commit ef22e70

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

notebooks/tps/boids/.teacher/boids.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ def populate_obstacles(self):
318318
pos_x, pos_y = OBSTACLES_RADIUS * math.cos(angle), OBSTACLES_RADIUS * math.sin(angle)
319319
self.obstacles.append(Obstacle(WIDTH//2+pos_x, HEIGHT//2+pos_y))
320320

321+
def remove_obstacles(self):
322+
"""
323+
remove all obstacles
324+
"""
325+
self.obstacles = SpriteList()
326+
321327
def on_draw(self):
322328
arcade.start_render()
323329
self.boids.draw()
@@ -366,6 +372,10 @@ def on_key_release(self, symbol: int, modifiers: int):
366372
global DEBUG
367373
DEBUG = not DEBUG
368374
self.display_current_settings()
375+
elif symbol == arcade.key.KEY_0:
376+
self.remove_obstacles()
377+
elif symbol == arcade.key.KEY_1:
378+
self.populate_obstacles()
369379
else:
370380
return super().on_key_release(symbol, modifiers)
371381

@@ -431,6 +441,8 @@ def main():
431441
* SPACE to suspend/resume
432442
* f to slow down/speed up frame rate
433443
* d to toggle debugging
444+
* 0 remove all obstacles
445+
* 1 reinstate obstacles
434446
435447
use the following mouse events
436448
* right-click to add obstacle

0 commit comments

Comments
 (0)