-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
97 lines (77 loc) · 2.38 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
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
97
###################################################################################
# Game.py
#
# The kickoff script/main loop. Sets up the different game systems, and then
# enters the main loop. Runs until we receive a system event to quit the game
#
# Command Line Arguments
###################################################################################
# System level imports
from optparse import OptionParser
import sys
import os
import math
import pygame
import random
from pygame.locals import *
# App level imports
from GameKernel import *
from GameStateManager import *
from GS_Editor import *
from GS_MainMenu import *
from GS_EditorMenu import *
from GS_Game import *
from GS_LevelSelect import *
from GS_Tutorial import *
from HighScores import *
import Balloon
import Bee
import BlueCap
import BottleCap
import Box
import Hive
import RedCap
import GoldCap
#random.seed(0)
#########################
# Start Main
#########################
#### Parse command line arguments
optionParser = OptionParser()
optionParser.add_option("-e", "--editlevel", help="Edit the level with a specified filename. If no such level exists, create a new one.")
optionParser.add_option("-l", "--levellength", help="When editing a level, this is the length of the level")
(options, args) = optionParser.parse_args()
#### Kick off the graphics/window system
kernel = GameKernel()
screenSurface = kernel.InitializeDisplay((800, 600))
ticker = kernel.Ticker()
#### Initialize game states
gsm = GameStateManager()
gsm.RegisterState(GS_MainMenu(kernel, gsm))
gsm.RegisterState(GS_EditorMenu(kernel, gsm))
gsm.RegisterState(GS_Game(kernel, gsm))
gsm.RegisterState(HighScores(kernel, gsm))
gsm.RegisterState(GS_LevelSelect(kernel, gsm))
gsm.RegisterState(GS_Tutorial(kernel, gsm))
if (options.editlevel):
gsm.RegisterState(GS_Editor(kernel, gsm, options.editlevel))
gsm.SwitchState("Editor")
else:
gsm.SwitchState("MainMenu")
font = pygame.font.SysFont("Helvetica", 12)
## Main Loop
while (1):
delta = ticker.get_time()
gsm.Update(delta)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
else:
gsm.GetActiveState().HandleEvent(event)
FPSSurf = font.render("FPS: " + str(int(ticker.get_fps())), True, (255, 255, 255))
FPSRect = FPSSurf.get_rect()
FPSRect.topright = screenSurface.get_rect().topright
screenSurface.blit(FPSSurf, FPSRect)
kernel.FlipDisplay()
ticker.tick(60)