-
Notifications
You must be signed in to change notification settings - Fork 0
/
Box.py
40 lines (33 loc) · 1.04 KB
/
Box.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
import pygame
import conf
class Box(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
def getDirection(self):
return self.direction
def setDirection(self, direction):
# self.directionChanged = 1
self.direction = direction
def update(self):
if self.direction == 1:
self.y -= 1
elif self.direction == 2:
self.x += 1
elif self.direction == 3:
self.y += 1
elif self.direction == 4:
self.x -= 1
def blit(self):
relX = self.x * self.blockSize
relY = self.y * self.blockSize
pygame.draw.rect(self.screen, self.color, (relX, relY, self.blockSize, self.blockSize))
if self.back is not None:
self.back.setDirection(self.direction)