-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerup.py
72 lines (56 loc) · 2.03 KB
/
powerup.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import random
from colorama import Fore, Style
from base import DIMENSION, COLOR
class PowerUp:
def __init__(self, xcoord, ycoord):
self._xcoord = xcoord
self._ycoord = ycoord
self._dim = {}
self._dim['x'] = 1
self._dim['y'] = 2
self._shape = COLOR['powerup'] + '>' + Style.RESET_ALL
def place(self, grid):
for i in range(self._dim['x']):
for j in range(self._dim['y']):
grid[self._xcoord+i][self._ycoord+j] = self._shape
def get_xcoord(self):
return self._xcoord
def get_ycoord(self):
return self._ycoord
def get_dim(self):
return self._dim
def get_shape(self):
return self._shape
def create_powerups():
x = DIMENSION['sky_height'] + random.randint(5, 15)
y = random.randint(100, 120)
obj_list = []
while y < 3 * DIMENSION['width'] // 4:
powerup = PowerUp(x, y)
obj_list.append(powerup)
x = DIMENSION['sky_height'] + random.randint(5, 15)
y += random.randint(100, 300)
return obj_list
def place_powerups(obj_list, grid, xdis):
for powerup in obj_list:
if powerup.get_ycoord() > xdis + DIMENSION['frame_width']:
break
elif powerup.get_ycoord() < xdis - powerup.get_dim()['y']:
obj_list.remove(powerup)
else:
powerup.place(grid)
class Dragon_Power(PowerUp):
def __init__(self, xcoord, ycoord):
PowerUp.__init__(self, xcoord, ycoord)
self._shape = COLOR['dragon_powerup'] + 'D' + Style.RESET_ALL
def remove(self, grid):
for i in range(self._dim['x']):
for j in range(self._dim['y']):
grid[self._xcoord+i][self._ycoord+j] = ' '
def create_dragon_powerup():
x = DIMENSION['length'] - 2*DIMENSION['ground_height']
y = random.randint(DIMENSION['width'] // 3, 2 * DIMENSION['width'] // 3)
dragon_powerup = Dragon_Power(x, y)
return dragon_powerup
def place_dragon_powerup(dragon_powerup, grid):
dragon_powerup.place(grid)