-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
53 lines (42 loc) · 1.68 KB
/
game.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
import pygame
from scenemanager import *
# Import scenes
from menu_scene import *
from game_scene import *
# Game class. Keeps track of everything we need to know about the game state (players, map, enemies, powerups, etc.).
class Game():
# Constructor. Initialize any variables and game objects.
def __init__(self):
# Initially the game is running and unpaused.
self.running = True
self.paused = False
self.num_pigeons = 1
# Used to manage the various scenes in the game.
self.scene_manager = SceneManager()
# Add any scenes needed by the game here
self.scene_manager.add_scene("MenuScene", MenuScene(self))
self.scene_manager.add_scene("GameScene", GameScene(self))
# Make sure to set the initial scene!
self.scene_manager.set_scene("GameScene")
# Pauses the game. Pausing prevents any updates from being done.
def pause(self):
self.paused = True
# Unpauses the game. Unpausing allows the game state to be updated.
def unpause(self):
self.paused = False
# Render the current state of the game.
def render(self, screen):
# Get the current scene
scene = self.scene_manager.get_scene()
# Render the scene
scene.render(screen)
# Update the state of the game.
# delta: Time passed (in seconds) since the previous frame.
def update(self, delta):
if self.paused:
# The game is paused, so don't do any updates!
return
# Get the current scene
scene = self.scene_manager.get_scene()
# Update the scene
scene.update(delta)