-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnake.py
More file actions
executable file
·55 lines (38 loc) · 1.21 KB
/
Snake.py
File metadata and controls
executable file
·55 lines (38 loc) · 1.21 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pygame
import math
from GameObject import GameObject
from GameKinnect import GameKinnect
class Snake(GameObject):
length = 4
speed = 10
@staticmethod
def init():
Snake.image = pygame.image.load("images/circle.png").convert_alpha()
def __init__(self,x,y):
factor = 0.02
image = Snake.image
w,h = image.get_size()
# print(w,h)
image = pygame.transform.scale(image, (int(factor * w), int(factor * h)))
super(Snake, self).__init__(x,y,image,30)
self.test = GameKinnect(800, 500)
def update(self, keysDown, screenWidth, screenHeight,collideBarrier):
print(GameKinnect.cur_right_hand_x)
if GameKinnect.cur_right_hand_x < 0:
vx = -Snake.speed
vy = 0
self.velocity = (vx,vy)
super(Snake,self).update(screenWidth,screenHeight)
# print(self.x)
if GameKinnect.cur_right_hand_x > 0:
vx = Snake.speed
vy = 0
self.velocity = (vx ,vy)
super(Snake,self).update(screenWidth,screenHeight)
# print(self.x)
def moveLeft(self,screenWidth,screenHeight,speed):
self.velocity = (-speed,0)
super(Snake,self).update(screenWidth,screenHeight)
def moveRight(self,screenWidth,screenHeight,speed):
self.velocity = (speed,0)
super(Snake,self).update(screenWidth,screenHeight)