-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
220 lines (181 loc) · 7.75 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import pygame
from pygame.locals import *
from pygame.math import Vector2
from time import time
from datetime import datetime, timedelta
import player
import stage_one
import stage_two
import stage_three
import yukari
import title
import results
import json
import sys
FPS = 60
SCREEN_WIDTH = 512
SCREEN_HEIGHT = 740
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
TURQUOISE = (0, 255, 255)
FAST = 5
SLOW = 2.5
vec = pygame.math.Vector2
running = True
def main():
pygame.init()
pygame.mixer.init()
pygame.joystick.init()
joysticks = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
for joystick in joysticks:
print(joystick.get_name())
clock = pygame.time.Clock()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT),
pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.SCALED, vsync=1)
pygame.display.set_caption("Touhou: Destitute Dreamscape (alpha demo)")
font = pygame.font.Font("res/misc/Symtext.ttf", 24)
sprites = pygame.sprite.Group()
bullets = pygame.sprite.Group()
players = pygame.sprite.Group()
bosses = pygame.sprite.Group()
circles = pygame.sprite.Group()
orbs = pygame.sprite.Group()
player_one = player.Player(256, 660)
sprites.add(player_one)
players.add(player_one)
magic_circle = yukari.MagicCircle(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3)
player_magic_circle = player.PlayerMagicCircle(256, 660)
sprites.add(magic_circle)
sprites.add(player_magic_circle)
circles.add(magic_circle)
circles.add(player_magic_circle)
boss = yukari.Yukari(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3)
sprites.add(boss)
bosses.add(boss)
lives = 2
total_points = 0
total_graze = 0
total_gems = 0
stage_clears = 0
stage_points = 0
stage_graze = 0
stage_gems = 0
stage_times = []
total_time = time() - time()
pause_differential = time() - time()
with open("res/misc/settings.json") as json_file:
settings = json.load(json_file)
auto_clear = False
global running
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT: # Handle window exit gracefully
running = False
if event.type == JOYDEVICEADDED:
joysticks = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
for joystick in joysticks:
print(joystick.get_name())
if event.type == JOYDEVICEREMOVED:
joysticks = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
# TITLE
continue_game, options = title.TitleScreen(clock, screen, joysticks, settings)
if not continue_game:
running = False
break
for option in options:
if option == "auto_clear":
auto_clear = True
# STAGE ONE
start_time = time()
continue_game, stage_points, stage_graze, stage_gems, stage_clears, pass_stage, lives, pause_differential,\
player_one, e10, e25, e50 = stage_one.StageOne(boss, magic_circle, bullets, sprites, players,
orbs, screen, font, clock, total_points, player_one,
player_magic_circle, lives, pause_differential,
joysticks, options)
end_time = time()
if not continue_game:
running = False
break
stage_times.append(end_time - start_time - pause_differential)
total_points += stage_points
total_graze += stage_graze
total_gems += stage_gems
# STAGE ONE RESULTS
continue_game = results.ShowResults(clock, screen, stage_points, total_points, stage_graze, total_graze,
stage_gems, lives, stage_clears, pass_stage, joysticks, options,
"STAGE ONE")
if not continue_game:
running = False
break
# STAGE TWO
if pass_stage:
player_one.pos = vec(256, 660)
start_time = time()
continue_game, stage_points, stage_graze, stage_gems, stage_clears, pass_stage, lives, pause_differential,\
player_one, e10, e25, e50 = stage_two.StageTwo(boss, magic_circle, bullets, sprites, players,
orbs, screen, font, clock, total_points, player_one,
player_magic_circle, lives, pause_differential,
joysticks, options, e10, e25, e50)
end_time = time()
if not continue_game:
running = False
break
stage_times.append(end_time - start_time - pause_differential)
total_points += stage_points
total_graze += stage_graze
total_gems += stage_gems
# STAGE TWO RESULTS
continue_game = results.ShowResults(clock, screen, stage_points, total_points, stage_graze, total_graze,
stage_gems, lives, stage_clears, pass_stage, joysticks, options,
"STAGE TWO")
if not continue_game:
running = False
break
# STAGE THREE
if pass_stage:
player_one.pos = vec(256, 660)
start_time = time()
continue_game, stage_points, stage_graze, stage_gems, stage_clears, pass_stage, lives, pause_differential,\
player_one, e10, e25, e50 = stage_three.StageThree(boss, magic_circle, bullets, sprites, players,
orbs, screen, font, clock, total_points, player_one,
player_magic_circle, lives, pause_differential,
joysticks, options, e10, e25, e50)
end_time = time()
if not continue_game:
running = False
break
stage_times.append(end_time - start_time - pause_differential)
total_points += stage_points
total_graze += stage_graze
total_gems += stage_gems
# STAGE THREE RESULTS
continue_game = results.ShowResults(clock, screen, stage_points, total_points, stage_graze,
total_graze,
stage_gems, lives, stage_clears, pass_stage, joysticks, options,
"STAGE THREE")
if not continue_game:
running = False
break
# RESET ON FAIL
if not pass_stage:
player_one = player.Player(256, 660)
sprites.add(player_one)
players.add(player_one)
lives = 2
total_points = 0
total_graze = 0
total_gems = 0
stage_clears = 0
stage_points = 0
stage_graze = 0
stage_gems = 0
stage_times = []
total_time = time() - time()
pause_differential = time() - time()
pygame.display.quit() # More graceful exit handling
pygame.mixer.quit()
pygame.quit()
sys.exit()
if __name__ == "__main__":
main()