-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sdlapp.py
More file actions
40 lines (32 loc) · 1.01 KB
/
test_sdlapp.py
File metadata and controls
40 lines (32 loc) · 1.01 KB
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
from random import randint
from sdlapp import SDL2Application, event_type, keys
class MyApp(SDL2Application):
def __init__(self):
super(MyApp, self).__init__()
self.player_x = 10
self.player_y = 10
def draw(self):
self.clear()
self.draw_char(self.player_x, self.player_y, 1)
self.flip()
app = MyApp()
app.init(1280, 720)
while app.is_running() is True:
app.update()
for e in app.poll_events():
print e.type
if e.type == event_type.QUIT:
app.quit()
if e.type == event_type.KEY_PRESS:
print e.scancode, e.keycode
if e.scancode == keys.KEY_ESC:
app.quit()
elif e.scancode == keys.KEY_UP:
app.player_y -= 1
elif e.scancode == keys.KEY_DOWN:
app.player_y += 1
elif e.scancode == keys.KEY_LEFT:
app.player_x -= 1
elif e.scancode == keys.KEY_RIGHT:
app.player_x += 1
app.draw()