-
Notifications
You must be signed in to change notification settings - Fork 2
/
4.3.py
65 lines (46 loc) · 1.69 KB
/
4.3.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
from game2d import *
class SimpleActor:
def move(self): pass
def rect(self) -> (int,int,int,int): pass
class FallingBall(SimpleActor):
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)
class Plane(SimpleActor):
W, H = 35, 35
ARENA_W, ARENA_H = 1000,1000
def __init__(self, x: int, y: int):
self._x = x
self._y = y
self._dx = 10
def move(self):
if not (0 <= self._x + self._dx <= Plane.ARENA_W - Plane.W):
self._dx = -self._dx
self._x += self._dx
def rect(self) -> (int, int, int, int):
return (self._x, self._y, Plane.W, Plane.H)
def update():
canvas_fill(canvas, (0, 0, 0))
for i in ballsandplanes:
i.move()
x1, y1, aw, ah = i.rect()
draw_rect(canvas, (0, 255, 255), (x1, y1, 40, 40))
canvas = canvas_init((1000,1000))
ballsandplanes = [Plane(1,200), Plane(1,250), Plane(1,300), FallingBall(10,10), FallingBall(70,70)]
set_interval(update, 1000 // 30)