-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaste_gravity.py
67 lines (56 loc) · 1.51 KB
/
taste_gravity.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
import sys, pygame
from time import time, sleep
from heavyobject import HeavyObject
pygame.init()
size = width, height = 1000, 600
speed = [0.0,1.0]
black = 0,0,0
gravity = -0.01
screen = pygame.display.set_mode(size)
dir(screen)
balls = [
HeavyObject(
screen, 'ball.gif',
position = (0, 0),
speed = (2.0, 0.0),
mass = 2.0
),
HeavyObject(
screen,
'ball.gif',
(width/2, 0),
(0.0, 0.0),
1.0
)
]
flickTime = 0.0
sleepTime = 0.01
downPoint = (0,0)
flickTime = 0.0
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
downPoint = event.pos
for ball in balls:
if ball.rect().collidepoint(downPoint):
flickTime = time()
clickedThing = ball
break
else:
flickTime = 0.0
if event.type == pygame.MOUSEBUTTONUP:
if flickTime != 0.0:
clickTime = (time() - flickTime) / sleepTime
upPoint = event.pos
speed = ( (upPoint[0] - downPoint[0]) / clickTime,
(upPoint[1] - downPoint[1]) / clickTime )
clickedThing.speed( speed )
flickTime = 0.0
if event.type == pygame.MOUSEMOTION:
pass
screen.fill(black)
for ball in balls:
ball.move()
pygame.display.flip()
sleep(sleepTime)