forked from Hetarth-Parikh/Pac-man
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.py
74 lines (62 loc) · 2.18 KB
/
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
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
from CONSTANT import *
class Enemy:
def __init__(self, Id):
self.Id = Id
self.flag=self.set_flag(self.Id)
self.E = ENEMY[Id]
self.X = ENEMYX[Id]
self.Y = ENEMYY[Id]
self.direction = 'UP'
def set_flag(self,Id):
if Id==0 or Id==2:
return True
return False
def draw(self):
SCREEN2.blit(self.E, (self.X, self.Y))
def move(self):
if self.flag and self.Id == 0 and self.X < ENEMYX[self.Id+1]:
if self.Valid(self.X+ENEMY_VELOCITY,self.Y):
self.move_right()
elif self.flag and self.Id == 2 and self.X > ENEMYX[self.Id-1]:
if self.Valid(self.X-ENEMY_VELOCITY,self.Y):
self.move_left()
else:
self.flag=False
self.original_move()
def original_move(self):
if not (self.Valid(self.X + DX[CH[self.direction]] * ENEMY_VELOCITY, self.Y + DY[CH[self.direction]]*ENEMY_VELOCITY)):
if self.direction == 'UP' or self.direction == 'DOWN':
global HORIZONTALID
self.direction = HORIZONTAL[HORIZONTALID]
HORIZONTALID += 1
HORIZONTALID %= 2
else:
global VERTICALID
self.direction = VERTICAL[VERTICALID]
VERTICALID += 1
VERTICALID %= 2
else:
if self.direction == 'UP':
self.move_up()
if self.direction == 'DOWN':
self.move_down()
if self.direction == 'LEFT':
self.move_left()
if self.direction == 'RIGHT':
self.move_right()
def move_right(self):
self.X = self.X + ENEMY_VELOCITY
def move_up(self):
self.Y = self.Y - ENEMY_VELOCITY
def move_down(self):
self.Y = self.Y + ENEMY_VELOCITY
def move_left(self):
self.X = self.X - ENEMY_VELOCITY
def Valid(self, X, Y):
if X < 50 or X > 910:
return False
for x in range(X, X + ENEMYWIDTH + 1):
for y in range(Y, Y + ENEMYHEIGHT + 1):
if MAZE[x][y] == '1':
return False
return True