-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.py
57 lines (45 loc) · 1.54 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
# IMPORTS
import pygame as pg
import colors as c
class enemy:
def __init__(self, surface, BS, BSI):
self.surface = surface
self.bs = BS
self.bsi = BSI
# for drawing the block
self.enemyblock = pg.Surface((BS, BS))
self.enemyblock.set_alpha(255)
self.enemyblock.fill(c.RED)
self.enemyblockdark = pg.Surface((BSI, BSI))
self.enemyblockdark.set_alpha(255)
self.enemyblockdark.fill(c.RED_DARK)
# for deleting blocks
self.blackblock = pg.Surface((BS, BS))
self.blackblock.set_alpha(255)
self.blackblock.fill(c.BLACK)
def setPos(self, posx, posy):
self.pos = [posx, posy]
def getPos(self):
return self.pos
def isEnemy():
return True
def move(self, move):
pos = self.getPos()
self.surface.blit(self.blackblock,
(pos[0] * self.bs, pos[1] * self.bs))
# update positions
if move == 1: # UP
pos = [pos[0], pos[1] - 1]
elif move == 2: # DOWN
pos = [pos[0], pos[1] + 1]
elif move == 3: # LEFT
pos = [pos[0] - 1, pos[1]]
elif move == 4: # RIGHT
pos = [pos[0] + 1, pos[1]]
self.pos = pos
def draw(self):
self.surface.blit(self.enemyblock,
(self.pos[0] * self.bs, self.pos[1] * self.bs))
self.surface.blit(self.enemyblockdark,
(self.pos[0] * self.bs + 1,
self.pos[1] * self.bs + 1))