-
Notifications
You must be signed in to change notification settings - Fork 0
/
plane.py
106 lines (95 loc) · 3.05 KB
/
plane.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
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
import explosion
import pyxel
from explosion import Explosion
import enemybullet
from enemybullet import Enemybullet
class Plane:
"""
This class will contain all the common attributes of all the enemy planes and player plane.
"""
def __init__(self, xpos, ypos):
# Both positions on board have to be updated
self.x_pos = xpos
self.y_pos = ypos
# Size won't change
self.x_size = 16
self.y_size = 16
# Position on file will change when movement change
self.x_pos_infile = 0
self.y_pos_infile = 0
# Health has to be updated
self.hp = 1
# This attribute will store the framecount at the start of the loop
self.framecount = 0
# framecount property and setter
@property
def framecount(self):
return self.__framecount
@framecount.setter
def framecount(self, value):
if type(value) != int and type(value) != float:
raise TypeError("framecount must be a number")
else:
self.__framecount = value
# x pos property and setter #
@property
def x_pos(self):
return self.__x_pos
@x_pos.setter
def x_pos(self, value):
if type(value) != int and type(value) != float:
raise TypeError("Position must be a number")
else:
self.__x_pos = value
# y pos property and setter #
@property
def y_pos(self):
return self.__y_pos
@y_pos.setter
def y_pos(self, value):
if type(value) != int and type(value) != float:
raise TypeError("Position must be a number")
else:
self.__y_pos = value
# x pos_infile property and setter #
@property
def x_pos_infile(self):
return self.__x_pos_infile
@x_pos_infile.setter
def x_pos_infile(self, value):
if type(value) != int and type(value) != float:
raise TypeError("Position must be a number")
else:
self.__x_pos_infile = value
# y pos_infile property and setter #
@property
def y_pos_infile(self):
return self.__y_pos_infile
@y_pos_infile.setter
def y_pos_infile(self, value):
if type(value) != int and type(value) != float:
raise TypeError("Position must be a number")
else:
self.__y_pos_infile = value
# hp property and setter
@property
def hp(self):
return self.__hp
@hp.setter
def hp(self, value):
if type(value) != int and type(value) != float:
raise TypeError("Health must be a number")
else:
self.__hp = value
def damage(self):
"""
This function damages the plane when asked, lowering health by one and creating an explosion
"""
self.hp += -1
if self.hp <= 0:
explosion.explosions.append(Explosion(self.x_pos, self.y_pos, self.x_size))
def fire(self, xpos, ypos):
"""
This function creates a bullet on the enemybulletlist
"""
enemybullet.enemybulletlist.append(Enemybullet(xpos,ypos))