-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobjects.py
More file actions
126 lines (97 loc) · 3.64 KB
/
objects.py
File metadata and controls
126 lines (97 loc) · 3.64 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'''
contains the structure of each object
'''
import config
from config import x_fac, y_fac
import numpy as np
class Object:
'''# bombs, walls, bricks all will be of this type'''
def __init__(self, x, y, ch=config._empty):
'''# the x and y coords wrt top left of board'''
self._x = x
self._y = y
self.width = 4
self.height = 2
self.is_killable = False
self._ch = ch
self.structure = np.chararray((self.height, self.width))
self.structure[:, :] = self._ch
self._type = config.types[self._ch]
def get_type(self):
'''# returns whether "Bomber", "Enemy", etc'''
return self._type
def get_size(self):
'''# returns (height, willdth)'''
return self.structure.shape
def get_coords(self):
'''# returns (x, y)'''
return (self._x, self._y)
def update_location(self, board, new_x, new_y, init=False):
'''# update the location of the person'''
if board.draw_obj(type(self)(new_x, new_y)):
# if initial update, will not clear original
if not init:
board.clear_obj(self)
self._x, self._y = new_x, new_y
return True
return False
class Wall(Object):
'''# this is the repr of the wall object
it implements no methods and some data about each wall element'''
def __init__(self, n, m):
'''# preferred size = 2 x 4'''
super(Wall, self).__init__(n, m, config._wall)
self.height = int(m)
self.width = int(n)
def __repr__(self):
''' repr '''
for r in range(self.height):
print("\n")
for c in range(self.width):
try:
print(self.structure[r, c].decode(), end="")
except UnicodeDecodeError:
print(self.structure[r, c], end="")
return ""
class Bomb(Object):
'''# this class implements the bomb object'''
def __init__(self, x, y):
''' init '''
super(Bomb, self).__init__(x, y, config._bomb)
self.timer = 0
self.active = False
self.is_killable = True
self.structure[:, :] = np.matrix([['[', self._ch, self._ch, ']'],
['[', self._ch, self._ch, ']']])
self.blast_radius = [(x + 1 * x_fac, y), (x + 2 * x_fac, y),
(x - 1 * x_fac, y), (x - 2 * x_fac, y), (x,
y + 1 * y_fac), (x, y + 2 * y_fac),
(x, y - 1 * y_fac), (x, y - 2 * y_fac)]
self.owner = None
def detonate(self, time):
'''# begin detonating the bomb (happens one frame after)'''
self.active = True
self.timer = time
def countdown(self):
''' countdown the bomb when active '''
if self.active:
self.timer -= 1
self.structure[:, 1:3] = str(self.timer)
return True
if not self.timer:
self.structure[:, :] = config._expl
def __repr__(self):
''' repr '''
return "<Bomb (%d, %d) | Active : %s | %d frames left>" % \
(self._x, self._y, self.active, self.timer)
class Bricks(Object):
'''# this class implements the bricks Object'''
def __init__(self, x, y):
''' init '''
super(Bricks, self).__init__(x, y, config._bricks)
self.is_killable = True
self.structure[:, :] = self._ch
def __repr__(self):
''' repr '''
return "<Bomb (%d, %d) | Active : %s | %d frames left>" % \
(self._x, self._y, self.active, self.timer)