-
Notifications
You must be signed in to change notification settings - Fork 5
/
enemy.py
34 lines (28 loc) · 951 Bytes
/
enemy.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
class Enemy:
def __init__(self, x0, y0, x1, y1, speedx=10, speedy=10, tag="enemy", couleur="blue"):
self.x0 = x0
self.y0 = y0
self.x1 = x1
self.y1 = y1
self.tag = tag
self.couleur = couleur
self.speedx = speedx
self.speedy = speedy
def moving_around(self, limitx1, limity1):
if self.x0 >= limitx1:
self.speedx *= (-1)
elif self.x0 <= 0:
self.speedx *= (-1)
elif self.y0 >= limity1:
self.speedy *= (-1)
elif self.y0 <= 0:
self.speedy *= (-1)
self.x0 += self.speedx
self.x1 += self.speedx
self.y0 += self.speedy
self.y1 += self.speedy
m = (self.tag, self.speedx, self.speedy)
return m
def draw(self, canvas):
id = canvas.create_oval(self.x0, self.y0, self.x1, self.y1, fill=self.couleur, tags=(self.tag))
return id