-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_game2.py
55 lines (38 loc) · 1.47 KB
/
test_game2.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
import pygame
import os
import global_values as g
from microgame import Microgame
class TestGame2(Microgame):
def __init__(self):
super().__init__({"time":5, "show_cursor":True})
def run(self):
import random
self.target_y = random.randint(100,200)
self.bar_y = 0
self.raising = False
super().run()
def handle_input(self, event_list):
#check if we have clicked to fire
for event in event_list:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
self.raising = True
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
self.raising = False
def update(self, dt):
super().update(dt)
if self.raising:
print(dt)
self.bar_y += 0.5*dt
if self.bar_y >= self.metadata["height"]:
self.bar_y -= self.metadata["height"]
if abs(self.target_y-self.bar_y) <= 3:
self.win()
def draw(self):
self.surf.fill("gray")
#draw target
pygame.draw.line(self.surf, "black", (0,self.metadata["height"]-self.target_y), (self.metadata["width"],self.metadata["height"]-self.target_y), 4)
#draw current
pygame.draw.line(self.surf, "black", (0,self.metadata["height"]-self.bar_y), (self.metadata["width"],self.metadata["height"]-self.bar_y), 4)
return self.surf