-
Notifications
You must be signed in to change notification settings - Fork 0
/
obstacle.py
49 lines (36 loc) · 1.53 KB
/
obstacle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import arcade
import random
import os
obstacle = "sprites/wall.png"
class Obstacle(arcade.Sprite):
def __init__(self):
super().__init__()
@classmethod
def setup_obstacles(cls, bottom_list, top_list):
# place obstacle sprites by having the same 'x' and gape throughout, but gapes btwn top & bottom pipes are
# different ie randomized gap instead of placement
prev_wall_x = 0
max_centre_y = 60
min_centre_y = 0
min_gap = 50
for i in range(4):
cls.bottom_obstacle = arcade.Sprite("sprites/obstacle.png", 1)
if prev_wall_x == 0:
cls.bottom_obstacle.center_x = 100
prev_wall_x = cls.bottom_obstacle.center_x
else:
cls.bottom_obstacle.center_x = prev_wall_x + 300
prev_wall_x = cls.bottom_obstacle.center_x
cls.bottom_obstacle.center_y = random.randrange(min_centre_y, max_centre_y)
bottom_wall_y = cls.bottom_obstacle.center_y
bottom_list.append(cls.bottom_obstacle)
cls.top_obstacle = arcade.Sprite("sprites/obstacle.png", 1)
cls.top_obstacle.angle = 180
cls.top_obstacle.center_x = prev_wall_x
cls.top_obstacle.center_y = 500 - bottom_wall_y + min_gap
top_list.append(cls .top_obstacle)
return bottom_list, top_list
def kill_obstacles(obstacles_list):
while len(obstacles_list) != 0:
for obstacle in obstacles_list:
obstacle.kill()