Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.py
More file actions
Latest commit
40 lines (33 loc) · 1.04 KB
/
Copy pathBox.py
File metadata and controls
40 lines (33 loc) · 1.04 KB
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
importpygame
importconf
classBox(object):
def__init__(self, screen, blockSize, x, y, bType='body'):
self.screen=screen
self.blockSize=blockSize
self.direction=2
self.bType=bType
self.x=x
self.y=y
self.color=conf.SNAKE_COLOR
self.back=None
self.directionChanged=0
defgetDirection(self):
returnself.direction
defsetDirection(self, direction):
# self.directionChanged = 1
self.direction=direction
defupdate(self):
ifself.direction==1:
self.y-=1
elifself.direction==2:
self.x+=1
elifself.direction==3:
self.y+=1
elifself.direction==4:
self.x-=1
defblit(self):
relX=self.x*self.blockSize
relY=self.y*self.blockSize
pygame.draw.rect(self.screen, self.color, (relX, relY, self.blockSize, self.blockSize))
ifself.backisnotNone:
self.back.setDirection(self.direction)