-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsauteed meat.py
160 lines (126 loc) · 5.31 KB
/
sauteed meat.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import pygame
import Leap, sys, thread, time
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture
class PygameGame(object):
def init(self):
self.controller = Leap.Controller()
self.win = pygame.display.set_mode((500,500))
self.controller.enable_gesture(Leap.Gesture.TYPE_SWIPE)
self.openHand = pygame.image.load("openHand.png")
self.handPan = pygame.image.load("panfull.png")
self.panfull = pygame.image.load("panflip.png")
self.smallMeat = pygame.image.load("smallMeat.png")
self.fistKnife = pygame.image.load("fistknife.png")
self.background = pygame.image.load("background.png")
self.stove = pygame.image.load("stove.png")
self.backgroundDim = 100
pygame.transform.scale(self.background,(self.backgroundDim,self.backgroundDim))
self.knifeX = 50
self.knifeY = 250
self.steakX = 100
self.steakY = 150
self.panFlipped = False
self.isClosed = False
def mousePressed(self, x, y):
pass
def mouseReleased(self, x, y):
pass
def mouseMotion(self, x, y):
pass
def mouseDrag(self, x, y):
pass
def keyPressed(self, keyCode, modifier):
pass
def keyReleased(self, keyCode, modifier):
pass
def timerFired(self, dt):
frame = self.controller.frame()
for gesture in frame.gestures():
if gesture.type is Leap.Gesture.TYPE_SWIPE:
print("swipe")
for hand in frame.hands:
normalized = frame.interaction_box.normalize_point(hand.palm_position, True)
currentX = int(normalized[0]*500)
currentY = int(500-normalized[1]*500)
currentZ = normalized[2]*0.5 + 0.5
if hand.grab_strength > 0.5:
smallImg = pygame.transform.rotozoom(self.handPan, 0,currentZ)
if hand.palm_velocity[1] > 200:
self.swipe = True
self.panFlipped = True
smallImg = pygame.transform.rotozoom(self.panfull, 0,currentZ)
if hand.palm_velocity[1] < 0:
self.swipe = False
self.panFlipped = False
smallImg = pygame.transform.rotozoom(self.handPan, 0,currentZ)
else:
self.panFlipped = False
knife = pygame.transform.rotozoom(self.smallMeat, 0,0.5)
self.knifeX=150
self.knifeY=250
self.win.blit(knife,(self.knifeX,self.knifeY))
smallImg = pygame.transform.rotozoom(self.openHand,0,currentZ)
if self.panFlipped == True:
pass
#yeet
self.win.blit(smallImg,(int(normalized[0]*500),500-int(normalized[1]*500)))
if len(frame.hands) == 0:
knife = pygame.transform.rotozoom(self.smallMeat, 0,0.5)
self.knifeX=150
self.knifeY=250
self.win.blit(knife,(self.knifeX,self.knifeY))
pygame.display.update()
def redrawAll(self, screen):
self.win.blit(self.background, (0,0))
self.win.blit(self.stove, (125,200))
def isKeyPressed(self, key):
''' return whether a specific key is being held '''
return self._keys.get(key, False)
def __init__(self, width=600, height=400, fps=50, title="112 Pygame Game"):
self.width = width
self.height = height
self.fps = fps
self.title = title
self.bgColor = (255, 255, 255)
pygame.init()
def run(self):
clock = pygame.time.Clock()
screen = pygame.display.set_mode((self.width, self.height))
# set the title of the window
pygame.display.set_caption(self.title)
# stores all the keys currently being held down
self._keys = dict()
# call game-specific initialization
self.init()
playing = True
while playing:
time = clock.tick(self.fps)
self.timerFired(time)
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
self.mousePressed(*(event.pos))
elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
self.mouseReleased(*(event.pos))
elif (event.type == pygame.MOUSEMOTION and
event.buttons == (0, 0, 0)):
self.mouseMotion(*(event.pos))
elif (event.type == pygame.MOUSEMOTION and
event.buttons[0] == 1):
self.mouseDrag(*(event.pos))
elif event.type == pygame.KEYDOWN:
self._keys[event.key] = True
self.keyPressed(event.key, event.mod)
elif event.type == pygame.KEYUP:
self._keys[event.key] = False
self.keyReleased(event.key, event.mod)
elif event.type == pygame.QUIT:
playing = False
screen.fill(self.bgColor)
self.redrawAll(screen)
pygame.display.flip()
pygame.quit()
def main():
game = PygameGame()
game.run()
if __name__ == '__main__':
main()