-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
65 lines (53 loc) · 1.68 KB
/
player.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
# IMPORTS
import pygame as pg
import colors as c
# DIRECTIONS
NONE = 0
UP = 1
DOWN = 2
LEFT = 3
RIGHT = 4
class player:
# constructor
def __init__(self, surface, POSX, POSY, BS, BSI):
self.surface = surface
self.pos = [POSX, POSY]
self.bs = BS
self.bsi = BSI
self.direction = NONE
# for drawing the block
self.playerblock = pg.Surface((BS, BS))
self.playerblock.set_alpha(255)
self.playerblock.fill(c.YELLOW)
self.playerblockdark = pg.Surface((BSI, BSI))
self.playerblockdark.set_alpha(255)
self.playerblockdark.fill(c.YELLOW_DARK)
# for deleting blocks
self.blackblock = pg.Surface((BS, BS))
self.blackblock.set_alpha(255)
self.blackblock.fill(c.BLACK)
def getPos(self):
return self.pos
def getDirection(self):
return self.direction
def move(self, move):
pos = self.getPos()
self.surface.blit(self.blackblock,
(pos[0] * self.bs, pos[1] * self.bs))
self.direction = move
# 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.playerblock,
(self.pos[0] * self.bs, self.pos[1] * self.bs))
self.surface.blit(self.playerblockdark,
(self.pos[0] * self.bs + 1,
self.pos[1] * self.bs + 1))