-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_game.py
More file actions
48 lines (35 loc) · 1.01 KB
/
start_game.py
File metadata and controls
48 lines (35 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
41
42
43
44
45
46
47
48
import pyglet
from pyglet.window import key
import sys
from lib.Board import Board
from lib.Game import Game
BLOCK_IMG_FILE = 'img/block.png'
# these are the dimensions from the gameboy version
BOARD_WIDTH = 14
BOARD_HEIGHT = 20
block = pyglet.image.load(BLOCK_IMG_FILE)
block_sprite = pyglet.sprite.Sprite(block)
BLOCK_WIDTH = block.width
BLOCK_HEIGHT = block.height
window = pyglet.window.Window(width=BOARD_WIDTH*BLOCK_WIDTH,
height=BOARD_HEIGHT*BLOCK_HEIGHT)
board = Board(BOARD_WIDTH, BOARD_HEIGHT, block)
if len(sys.argv) > 1:
starting_level = int(sys.argv[1])
else:
starting_level = 1
game = Game(window, board, starting_level)
@window.event
def on_draw():
game.draw_handler()
@window.event
def on_text_motion(motion):
game.keyboard_handler(motion)
@window.event
def on_key_press(key_pressed, mod):
if key_pressed == key.P:
game.toggle_pause()
def update(dt):
game.cycle()
pyglet.clock.schedule_interval(update, 1 / game.frame_rate)
pyglet.app.run()