forked from Amegma/Galaxy-Attack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
177 lines (138 loc) · 5.65 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
import sys
import pygame
import argparse
from utils.assets import Assets
from screens.game import game
from screens.controls import controls
from screens.score_board import score_board
from screens.ships import ships
from screens.settings import settings
from screens.background import slow_bg_obj
from models.button import Button
from models.icon_button import IconButton
from models.controls import audio_cfg, display_cfg
from config import config
from constants import Path, Image, Font, Colors, Text
# parsing arguments
ag = argparse.ArgumentParser()
ag.add_argument("--mute", help="disable all sounds", action="store_true")
args = vars(ag.parse_args())
if args["mute"]:
audio_cfg.toggle_mute()
pygame.font.init()
pygame.display.set_caption(config.TITLE)
pygame.display.set_icon(Image.PLAYER_SPACE_SHIP)
def main():
title_font = pygame.font.Font(Font.edit_undo_font, 82)
audio_cfg.play_music(Path.MENU_MUSIC_PATH)
mouse_btn = Button(Colors.BACKGROUND_BLACK, Colors.WHITE, "MOUSE")
keyboard_btn = Button(Colors.BACKGROUND_BLACK, Colors.WHITE, "KEYBOARD")
control_btn = IconButton(Image.CONTROL_IMAGE, Text.CONTROLS)
ships_btn = IconButton(Image.SHIPS_IMAGE, Text.SHIPS)
trophy_btn = IconButton(Image.TROPHY_IMAGE, Text.SCOREBOARD)
settings_btn = IconButton(Image.TOOLBOX_IMAGE, Text.SETTINGS)
exit_btn = IconButton(Image.EXIT_IMAGE)
run = True
while run:
pygame.mouse.set_visible(True)
slow_bg_obj.update()
slow_bg_obj.render()
# Ships
Assets.image.draw(Image.BOSS_SHIP, (config.center_x, 110), True)
Assets.image.draw(Image.FLAME_LASER, (config.center_x, 360), True)
Assets.image.draw(Image.PLAYER_SPACE_SHIP, (config.center_x-46, 575))
Assets.image.draw(Image.PLAYER_LASER, (config.center_x, 490), True)
mouse_btn.draw(
(config.center_x - 210, config.center_y + 42), (195, 66))
keyboard_btn.draw(
(config.center_x + 15, config.center_y + 42), (195, 66))
Assets.text.draw('Start Game', title_font, Colors.WHITE,
(config.center_x, config.center_y-10), True, True)
# Control Page
control_btn.draw((config.starting_x + 65, 53), True, True)
# ScoreBoard Page
trophy_btn.draw((config.ending_x - 65, 55), True, True)
# Settings Page
settings_btn.draw((config.ending_x - 65, 165), True, True)
# Ships Page
ships_btn.draw((config.starting_x + 65, 165), True, True)
audio_cfg.display_volume()
exit_btn.draw((config.ending_x - 75, config.ending_y - 40), True, True)
Assets.image.draw(Image.TITLE_LOGO, (config.center_x, 50), True)
pygame.display.flip()
config.clock.tick(config.FPS) # capping frame rate to 60
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.VIDEORESIZE:
if not display_cfg.fullscreen:
config.update(event.w, event.h)
# Keyboard events
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_m:
audio_cfg.toggle_mute()
if event.key == pygame.K_PLUS or event.key == pygame.K_EQUALS:
audio_cfg.inc_volume(5)
if event.key == pygame.K_MINUS:
audio_cfg.dec_volume(5)
if event.key == pygame.K_f:
config.update(
config.monitor_size[0], config.monitor_size[1])
display_cfg.toggle_full_screen()
# Mouse click events
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if mouse_btn.isOver():
game(True)
if keyboard_btn.isOver():
game()
if control_btn.isOver():
controls()
if trophy_btn.isOver():
score_board()
if ships_btn.isOver():
ships()
if settings_btn.isOver():
settings()
if exit_btn.isOver():
run = False
# Mouse hover events
if event.type == pygame.MOUSEMOTION:
if mouse_btn.isOver():
mouse_btn.outline = True
else:
mouse_btn.outline = False
if keyboard_btn.isOver():
keyboard_btn.outline = True
else:
keyboard_btn.outline = False
if control_btn.isOver():
control_btn.outline = True
else:
control_btn.outline = False
if trophy_btn.isOver():
trophy_btn.outline = True
else:
trophy_btn.outline = False
if settings_btn.isOver():
settings_btn.outline = True
else:
settings_btn.outline = False
if ships_btn.isOver():
ships_btn.outline = True
else:
ships_btn.outline = False
if exit_btn.isOver():
exit_btn.outline = True
else:
exit_btn.outline = False
keys = pygame.key.get_pressed()
if keys[pygame.K_ESCAPE] or keys[pygame.K_q]:
run = False
if keys[pygame.K_c]:
controls()
if keys[pygame.K_s]:
score_board()
pygame.quit()
sys.exit(0)
main()