-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuman.py
31 lines (27 loc) · 1.01 KB
/
human.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
from snake import Snake
from pygame.locals import *
from constants import *
class Human(Snake): ### class name now matches module name!
def __init__(self,body=[(0,0)] , direction=(1,0), name="Human"):
super().__init__(body,direction,name=name)
#assign the keys to control the human snake
self.upkey=K_UP
self.downkey=K_DOWN
self.rightkey=K_RIGHT
self.leftkey=K_LEFT
def processkey(self,key):
#we check the old direction not the new direction.
if key==self.upkey:
if self.direction != down:
self.newdirection=up
elif key==self.downkey:
if self.direction != up:
self.newdirection=down
elif key==self.rightkey:
if self.direction != left:
self.newdirection=right
elif key==self.leftkey:
if self.direction != right:
self.newdirection=left
### An alias for the class name, to keep backward compatibility.
HumanSnake = Human