77 lines
No EOL
1.9 KiB
Python
77 lines
No EOL
1.9 KiB
Python
import pyglet
|
|
import engine
|
|
import unittest
|
|
from pyglet.window import key
|
|
from enum import Enum
|
|
import time
|
|
|
|
unittest.main(exit=False)
|
|
|
|
print("Hello!!!")
|
|
|
|
engine.data.load_mods()
|
|
|
|
engine.screen.init_window()
|
|
window = engine.screen.window
|
|
|
|
scene_batch = pyglet.graphics.Batch()
|
|
|
|
label = pyglet.text.Label('Hello, world',
|
|
font_name='Times New Roman',
|
|
font_size=window.height//8,
|
|
x=window.width//2, y=window.height//2,
|
|
anchor_x='center', anchor_y='center',
|
|
batch=scene_batch)
|
|
|
|
def center_image(image):
|
|
image.anchor_x = image.width // 2
|
|
image.anchor_y = image.height // 2
|
|
return image
|
|
|
|
player_image = center_image(pyglet.resource.image('tex/test1.png'))
|
|
player_sprite = pyglet.sprite.Sprite(player_image, x=200, y=200, batch=scene_batch)
|
|
|
|
def move_player(x, y):
|
|
player_sprite.x += x
|
|
player_sprite.y += y
|
|
|
|
music_player = pyglet.media.Player()
|
|
music_player.loop = True
|
|
music_player.queue(pyglet.resource.media('music/menu.mp3'))
|
|
music_player.play()
|
|
|
|
class Actions(Enum):
|
|
Quit = 0
|
|
Up = 1
|
|
Down = 2
|
|
Left = 3
|
|
Right = 4
|
|
|
|
action_map = {
|
|
Actions.Quit: lambda: pyglet.app.exit(),
|
|
Actions.Up: lambda: move_player(0, 1),
|
|
Actions.Down: lambda: move_player(0, -1),
|
|
Actions.Left: lambda: move_player(-1, 0),
|
|
Actions.Right: lambda: move_player(1, 0)
|
|
}
|
|
|
|
engine.binding.bind(key.Q, Actions.Quit)
|
|
engine.binding.bind(key.W, Actions.Up)
|
|
engine.binding.bind(key.S, Actions.Down)
|
|
engine.binding.bind(key.A, Actions.Left)
|
|
engine.binding.bind(key.D, Actions.Right)
|
|
|
|
@window.event
|
|
def on_draw():
|
|
engine.screen.window.clear()
|
|
scene_batch.draw()
|
|
|
|
def handle_input(clock):
|
|
engine.binding.process_keys(clock)
|
|
for action in engine.binding.actions:
|
|
action_map[action]()
|
|
|
|
|
|
pyglet.clock.schedule_interval(handle_input, engine.binding.fixed_rate)
|
|
|
|
pyglet.app.run() |