-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (66 loc) · 2.43 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
import sys
from map import *
from object_handler import *
from object_renderer import *
from pathfinding import *
from player import *
from raycasting import *
from sound import *
from weapon import *
class Game:
def __init__(self):
pg.init()
pg.mouse.set_visible(False) # Hiding the cursor from the Game Screen
self.screen=pg.display.set_mode(RES) #Initialize a window or screen for display
self.clock=pg.time.Clock() #create an object to help track time
self.delta_time=1
self.global_trigger = False
self.global_event = pg.USEREVENT + 0
pg.time.set_timer(self.global_event,80)
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)
# self.static_sprite = SpriteObject(self)
# self.animated_sprites = AnimatedSprite(self)
pg.mixer.music.play(-1)
def update(self):
self.player.update()
self.raycasting.update()
self.object_handler.update()
self.weapon.update()
# self.static_sprite.update()
# self.animated_sprites.update()
pg.display.flip() #Update the full display Surface to the screen
self.delta_time = self.clock.tick(FPS) #update the clock
pg.display.set_caption(f'{self.clock.get_fps():.1f}') #compute the clock framerate
def draw(self):
self.object_renderer.draw()
self.weapon.draw()
# self.screen.fill('black')
# 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() #uninitialize all pygame modules
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.new_game()
game.run()