-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameEngine.py
59 lines (44 loc) · 1.68 KB
/
gameEngine.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
# -*- coding: utf-8 -*-
import pyglet
import game
import time
class GameEngine(pyglet.window.Window):
W_WIDTH = 1024
W_HEIGHT = 640
def __init__(self):
super(GameEngine, self).__init__(width=self.W_WIDTH, height=self.W_HEIGHT, resizable=False)
self.game = game.Game()
# - Options generales -
self.set_vsync(True)
self.set_caption(u"Capoué")
self.set_mouse_visible(False)
self.set_exclusive_mouse(True)
# - Couleur de fond -
pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
pyglet.gl.glClearColor(0.2, 0.2, 0.2, 1)
# - Physique -
pyglet.clock.schedule_interval(lambda x: False, 1 / 100000000.0) # Debridage complet des FPS
pyglet.clock.schedule_interval(self.physicEngine, 1 / 100.0)
def physicEngine(self, dt):
self.game.simulate(dt)
def on_mouse_motion(self, x, y, dx, dy):
self.game.on_mouse_motion(x, y, dx, dy)
def on_mouse_press(self, button, x, y, modifiers):
self.game.on_mouse_press(button, x, y, modifiers)
def on_mouse_release(self, x, y, button, modifiers):
self.game.on_mouse_release(x, y, button, modifiers)
def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
self.on_mouse_motion(x, y, dx, dy)
self.on_mouse_press(button, x, y, modifiers)
def on_key_press(self, key, modifiers):
if key == pyglet.window.key.ESCAPE:
self.close()
else:
self.game.on_key_press(key, modifiers)
def on_draw(self):
# start = time.time()
self.clear()
self.game.render()
# print(1 / (time.time() - start))
def start(self):
pyglet.app.run()