forked from ericclack/pygamezero_candy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcandy2.py
37 lines (31 loc) · 888 Bytes
/
candy2.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
import random
WIDTH = 400
HEIGHT = 560
TITLE = 'Candy Crush'
cursor = Actor('selected', topleft=(0,0))
board = []
for row in range(14):
# Make a list of 10 random tiles
tiles = [random.randint(1,8) for _ in range(10)]
board.append(tiles)
def draw():
for y in range(14):
for x in range(10):
tile = board[y][x]
screen.blit(str(tile), (x * 40, y * 40))
cursor.draw()
def cursor_tile_pos():
return (int(cursor.x // 40)-1, int(cursor.y // 40))
def on_key_up(key):
x, y = cursor_tile_pos()
print(x,y)
if key == keys.LEFT and x > 0:
cursor.x -= 40
if key == keys.RIGHT and x < 8:
cursor.x += 40
if key == keys.UP and y > 0:
cursor.y -= 40
if key == keys.DOWN and y < 13:
cursor.y += 40
if key == keys.SPACE:
board[y][x], board[y][x+1] = board[y][x+1], board[y][x]