-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirst.py
52 lines (38 loc) · 1.72 KB
/
first.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
from wonderworld import *
PADDLE_VELOCITY: float = 180.0
class Paddle(Component):
pass
def setup():
commands = get_commands()
assets = get_resource(Assets)
# asset_server = get_resource(AssetServer)
# image_handle = asset_server.load("box.png");
image_handle = assets.add(create_image(color=pygame.Color('white'),
size=Vector2(10.0, 100.0)))
# camera
commands.spawn(Camera2dBundle(camera=Camera(),
transform=Transform(translation=Vector2(0,0),
rotation=0,
scale=Vector2(0, 0))))
# paddle
commands.spawn(SpriteBundle(sprite=Sprite(image=image_handle),
transform=Transform(translation=Vector2(100, 100),
rotation=0,
scale=Vector2(0, 0)),
visibility=Visibility(visible=True))) \
.insert(Paddle())
def input():
time = get_resource(Time)
keyboard_input = get_resource(Keyboard)
for transform, in Query(Transform, With(Paddle)):
paddle_move = time.delta_seconds * PADDLE_VELOCITY
if keyboard_input.pressed(K_UP):
transform.translation.y = transform.translation.y - paddle_move
if keyboard_input.pressed(K_DOWN):
transform.translation.y = transform.translation.y + paddle_move
if __name__ == "__main__":
App().insert_resource(ClearColor(color=pygame.Color('black'))) \
.add_plugins(DefaultPlugins()) \
.add_startup_system(setup) \
.add_system(input) \
.run()