-
Notifications
You must be signed in to change notification settings - Fork 2
/
4.2.py
43 lines (30 loc) · 1.04 KB
/
4.2.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
from game2d import *
class FallingBall:
W, H = 20, 20
ARENA_W, ARENA_H = 1000,1000
def __init__(self, x: int, y: int):
self._x = x
self._y = y
self._dx = 5
self._dy = 5
self._g = 9.81
def move(self):
if not (0 <= self._x + self._dx <= FallingBall.ARENA_W - FallingBall.W):
self._dx = -self._dx
if not (0 <= self._y + self._dy <= FallingBall.ARENA_H - FallingBall.H):
self._dy = -self._dy
self._dy = -100
self._x += self._dx
self._y += self._dy
self._dy += self._g
def rect(self) -> (int, int, int, int):
return (self._x, self._y, FallingBall.W, FallingBall.H)
if __name__ == '__main__':
bf1 = FallingBall(40, 80)
print('FallingBall 1 @', bf1.rect())
canvas = canvas_init((1000,1000))
def update():
canvas_fill(canvas, (0, 0, 0))
bf1.move()
draw_rect(canvas, (0, 255, 255), (bf1.rect()))
set_interval(update, 1000 // 40)