-
Notifications
You must be signed in to change notification settings - Fork 261
/
main.py
74 lines (65 loc) · 2.03 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
import pygame as pg
import sys
from settings import *
from map import *
from player import *
from raycasting import *
from object_renderer import *
from sprite_object import *
from object_handler import *
from weapon import *
from sound import *
from pathfinding import *
class Game:
def __init__(self):
pg.init()
pg.mouse.set_visible(False)
self.screen = pg.display.set_mode(RES)
pg.event.set_grab(True)
self.clock = pg.time.Clock()
self.delta_time = 1
self.global_trigger = False
self.global_event = pg.USEREVENT + 0
pg.time.set_timer(self.global_event, 40)
self.new_game()
def new_game(self):
self.map = Map(self)
self.player = Player(self)
self.object_renderer = ObjectRenderer(self)
self.raycasting = RayCasting(self)
self.object_handler = ObjectHandler(self)
self.weapon = Weapon(self)
self.sound = Sound(self)
self.pathfinding = PathFinding(self)
pg.mixer.music.play(-1)
def update(self):
self.player.update()
self.raycasting.update()
self.object_handler.update()
self.weapon.update()
pg.display.flip()
self.delta_time = self.clock.tick(FPS)
pg.display.set_caption(f'{self.clock.get_fps() :.1f}')
def draw(self):
# self.screen.fill('black')
self.object_renderer.draw()
self.weapon.draw()
# self.map.draw()
# self.player.draw()
def check_events(self):
self.global_trigger = False
for event in pg.event.get():
if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
pg.quit()
sys.exit()
elif event.type == self.global_event:
self.global_trigger = True
self.player.single_fire_event(event)
def run(self):
while True:
self.check_events()
self.update()
self.draw()
if __name__ == '__main__':
game = Game()
game.run()