-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2DGame first projectwork.py
64 lines (53 loc) · 1.39 KB
/
2DGame first projectwork.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
from pico2d import *
def handle_events():
global running
global x
global y
global r
global pivotx
global pivoty
events = get_events()
for event in events:
if event.type == SDL_QUIT:
running = False
elif event.type == SDL_MOUSEMOTION:
pivotx, pivoty = event.x, 600 - event.y
elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
running = False
elif event.type == SDL_KEYDOWN:
if event.key == SDLK_RIGHT:
pivotx += 10
elif event.key == SDLK_LEFT:
pivotx -= 10
elif event.key == SDLK_DOWN:
pivoty -= 10
elif event.key == SDLK_UP:
pivoty += 10
elif event.key == SDLK_a:
if r < 300 :
r += 50;
elif event.key == SDLK_d:
if 20 < r:
r -= 50;
# fill here
open_canvas()
grass = load_image('grass.png')
character = load_image('run_animation.png')
running = True
x = 300
y = 300
r = 100
pivotx = 400
pivoty = 300
frame = 0
while (running):
clear_canvas()
grass.draw(400, 30)
character.clip_draw(frame * 100, 0, 100, 100, r* math.cos(x) + pivotx, r* math.sin(x) + pivoty)
update_canvas()
frame = (frame + 1) % 8
delay(0.1)
handle_events()
x += 1
y += 1
close_canvas()