-
Notifications
You must be signed in to change notification settings - Fork 1
/
16_diagonal_movement.py
55 lines (44 loc) · 1.23 KB
/
16_diagonal_movement.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
"""
Small snippet demonstrating diagonal pixel movement for Seubmarine on Discord.
Kris Pritchard / @krp
"""
import math
import pyxel
class App:
def __init__(self):
pyxel.init(160, 120)
pyxel.cls(0)
self.x = 60
self.y = 60
# Give run the update/draw callbacks
pyxel.run(self.update, self.draw)
def update(self):
if pyxel.btn(pyxel.KEY_W):
self.y -= 1
if pyxel.btn(pyxel.KEY_S):
self.y += 1
if pyxel.btn(pyxel.KEY_A):
self.x -= 1
if pyxel.btn(pyxel.KEY_D):
self.x += 1
if pyxel.btn(pyxel.KEY_Q):
self.x -= 1
self.y -= 1
if pyxel.btn(pyxel.KEY_E):
self.x += 1
self.y -= 1
if pyxel.btn(pyxel.KEY_Z):
self.x -= 1
self.y += 1
if pyxel.btn(pyxel.KEY_C):
self.x += 1
self.y += 1
def draw(self):
# Don't forget to clear screen on every frame!
pyxel.cls(0)
# Draw the pyxel location:
pyxel.text(5, 5, f'({self.x}, {self.y})', 7)
# Draw the text at position: (text_x, text_y)
pyxel.pset(self.x, self.y, 8)
if __name__ == "__main__":
App()