-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.py
127 lines (100 loc) · 4.46 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import pygame
import Player
import Boss
from lib import *
import time
from config import *
pygame.init() # Its a pygame thing. Idk. It tells me to call this first.
def main_menu(difficulty, win): # Draws the main menu. Once the user select an option, it returns the result.
menu_running = True # Is the menu running?
menu_quit = False # Did the user want to quit?
menu_spot = 0 # Position that the cursor is over
debug_state = False # Is debug(cheat) mode on?
last_toggle = time.time()
pygame.event.clear() # Prevents events from last round affecting the next round.
frame = 0
while menu_running:
frame += 1
pygame.event.pump() # pygame tells me that I should do this.
CLOCK.tick(FRAMERATE)
if not update_events_menu(): # Returns false if player selected quit or tried to close it
menu_quit = True
break
menu_spot, last_toggle, debug_state, menu_running, menu_quit = \
update_keyboard_menu(menu_spot, last_toggle, debug_state, frame)
draw_gui_menu(menu_spot, debug_state, win, difficulty)
pygame.display.flip() # This is apparently required for things to be rendered
return menu_quit, debug_state # Return if the user wanted to quit and if the user wanted to use debug mode
# This function is the actual game loop. It changes based on the difficulty and is debug mode is on
def game(difficulty, score, debug_state=False):
lasers = [] # List of all the lasers
game_quit = False # Does the user want to quit?
game_running = True # Is the game running?
game_state = ''
frame_count = 0
spray_toggle = False
timers = {
'time_start': time.time(),
'last_spray_toggle': time.time(),
'last_bomb_toggle': time.time(),
'last_nocollide_toggle': time.time(),
'last_ring_toggle': time.time(),
'last_tinyman_toggle': time.time(),
'last_bigbullets_toggle': time.time(),
'last_slowtime_toggle': time.time(),
'last_fasttime_toggle': time.time(),
'last_debug_toggle': time.time(),
'last_time_change': time.time()
}
debug_powerups = {
'ring': False,
'bomb': False,
'nocollide': False,
'tinyman': False,
'bigbullets': False,
'slowtime': False,
'fasttime': False,
'spray': False,
}
time_change = 0
powerups = []
# score = score
score_thresh = 10
pygame.event.clear() # Good for the environment
player_obj = Player.Player(WINDOW_X/2, WINDOW_Y/2, [], [])
player_obj.debug = debug_state
player_obj.refresh_debug()
if difficulty % 5 == 0:
boss_obj = Boss.Boss(difficulty * 5, (difficulty/5.0)/FRAMERATE)
else:
boss_obj = False
while game_running:
frame_count += 1
CLOCK.tick(FRAMERATE)
SCREEN.fill(COLOR_SCREEN)
if difficulty % 5 == 0:
update_shots(boss_obj.shots, time_change)
update_boss(boss_obj, player_obj, time_change)
score = boss_obj.health
check_collisions(lasers, player_obj, difficulty, boss_obj) # Do things touch other things?
else:
update_lasers(lasers, time_change)
make_lasers(lasers, difficulty) # If lasers despawn, make more to replace them
check_time(debug_state, timers, score, score_thresh)
score += check_collisions(lasers, player_obj, difficulty, boss_obj) # Do things touch other things?
if score >= score_thresh:
score = score_thresh
update_mouse(player_obj)
game_running, game_state, game_quit = \
update_events(game_running, game_state, game_quit, lasers)
debug_state, last_spray_toggle, spray_toggle, time_change, debug_powerups = \
update_keyboard(debug_state, timers, spray_toggle, player_obj, time_change, debug_powerups)
update_bombs(player_obj)
update_shots(player_obj.shots, time_change)
time_change, powerup_display = \
update_player(player_obj, debug_state)
spawn_powerups(POWERUP_CHANCE, powerups) # Chance that a powerup will spawn on any given second
update_powerups(powerups, player_obj, debug_powerups) # Draw powerups
draw_gui(timers, difficulty, powerup_display, score, score_thresh) # Show the powerups being used, the level, time, etc.
pygame.display.flip() # This is required by pygame to render the screen.
return game_state, game_quit