-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform_game.py
77 lines (54 loc) · 1.34 KB
/
platform_game.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
66
67
68
69
70
71
72
73
74
75
76
77
from platform_builder import BuilderCell, BuilderBoard
from cellboard import CantScroll
CELL_WIDTH = 70
CELL_HEIGHT = 70
CELL_CT_W = 5
CELL_CT_H = 5
class Cell(BuilderCell):
images = [
'blank',
'grass-left',
'grass-mid',
'grass-right',
'grass-center',
'liquid-water',
'liquid-water-center',
]
class Board(BuilderBoard):
#offset = (CELL_WIDTH, CELL_HEIGHT)
cell_class = Cell
WIDTH = CELL_WIDTH * CELL_CT_W + 2 * Board.margin[0] + Board.controles_width
HEIGHT = max(CELL_HEIGHT * CELL_CT_H + 2 * Board.margin[1], Board.controles_height)
dx = 0
dy = 0
board = Board(CELL_CT_W, CELL_CT_H, CELL_WIDTH, CELL_HEIGHT)
board.status = 1
def draw():
screen.clear()
board.draw(screen)
def update():
global dx, dy
if dx != 0 or dy!= 0:
try:
board.scroll(dx, dy)
except CantScroll:
print("Can't scroll")
board.update()
def on_key_up(key):
global dx, dy
if key == keys.RIGHT or key == keys.LEFT:
dx = 0
elif key == keys.UP or key == keys.DOWN:
dy = 0
def on_key_down(key):
global dx, dy
if key == keys.RIGHT:
dx = 1
elif key == keys.LEFT:
dx = -1
elif key == keys.UP:
dy = -1
elif key == keys.DOWN:
dy = 1
def on_mouse_down(pos):
board.click(pos)