-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
45 lines (35 loc) · 1.22 KB
/
app.py
File metadata and controls
45 lines (35 loc) · 1.22 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
import pygame
from typing import Callable
def readFile(name: str):
with open(name, encoding='utf-8') as f:
return f.read()
def run(title: str, init: Callable[[], None], update: Callable[[float, float], None] = None, screenSize=[512, 512]):
pygame.init()
displayFlags = pygame.DOUBLEBUF | pygame.OPENGL
# use a core ogl profile for cross-platform compatibility
pygame.display.gl_set_attribute(
pygame.GL_CONTEXT_PROFILE_MASK, pygame.GL_CONTEXT_PROFILE_CORE)
# create and display the window
pygame.display.set_mode(screenSize, displayFlags, vsync=1)
pygame.display.set_caption(title)
init()
pygame.display.flip()
clock = pygame.time.Clock()
clock.tick(60)
time = 0
running = True
pause = False
while running:
# Handle events
for event in pygame.event.get():
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
pause = not pause
if event.type == pygame.QUIT:
running = False
dt = clock.tick(60) / 1000.0
if not pause:
time += dt
if update is not None:
update(dt, time)
pygame.display.flip()
pygame.quit()