-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (69 loc) · 2.8 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pygame
from modules import *
import asyncio
import os
class Master:
def __init__(self):
self.app:App
# self.debug:Debug
self.dt:float
self.offset:pygame.Vector2
self.font_1 = pygame.font.Font("fonts/PixelOperator.ttf", 14)
self.font = pygame.font.Font("fonts/PixelOperator-Bold.ttf", 18)
self.font_big = pygame.font.Font("fonts/PixelOperator.ttf", 32)
class App:
MAIN_MENU = 2
IN_GAME = 3
def __init__(self):
pygame.init()
self.screen = pygame.display.set_mode((W, H), pygame.SCALED)
pygame.display.set_caption("Lost In Dimensions")
# icon = pygame.image.load("graphics/icon.png").convert()
# pygame.display.set_icon(icon)
self.clock = pygame.time.Clock()
pygame.event.set_blocked(None)
pygame.event.set_allowed((pygame.QUIT, pygame.KEYDOWN, pygame.KEYUP, pygame.MOUSEBUTTONDOWN,
pygame.FINGERDOWN, pygame.FINGERUP, pygame.FINGERMOTION))
self.state = self.MAIN_MENU
self.master = Master()
SoundSet(self.master)
self.master.app = self
self.debug = Debug()
self.master.debug = self.debug
self.game = Game(self.master)
self.main_menu = MainMenu(self.master)
self.fingers = {}
self.fingers_prev = {}
async def run(self):
while True:
pygame.display.update()
self.master.dt = self.clock.tick(FPS) / 16.667
if self.master.dt > 10: self.master.dt = 10
self.debug("FPS:", round(self.clock.get_fps(), 2))
for event in pygame.event.get((pygame.QUIT)):
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
await asyncio.sleep(0)
self.fingers_prev = self.fingers.copy()
for event in pygame.event.get((pygame.FINGERDOWN, pygame.FINGERUP, pygame.FINGERMOTION)):
if not self.game.touch_btns_enabled: continue
if event.type == pygame.FINGERDOWN:
self.fingers[event.finger_id] = (event.x*W, event.y*H)
if event.type == pygame.FINGERMOTION:
self.fingers[event.finger_id] = (event.x*W, event.y*H)
if event.type == pygame.FINGERUP:
try:
del self.fingers[event.finger_id]
except KeyError: pass
self.run_states()
self.debug.draw()
def run_states(self):
if self.state == self.MAIN_MENU:
self.main_menu.run()
elif self.state == self.IN_GAME:
self.game.run()
if __name__ == "__main__":
app = App()
# app.run()
asyncio.run(app.run())