-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMananangal Flight.py
251 lines (211 loc) · 8.69 KB
/
Mananangal Flight.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# ------------------------------------------------------------------------------------------
# Copyright (C) 2023 Aaron James R. Mission & Ellysa Mae Kayo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# ------------------------------------------------------------------------------------------
import pygame, math, os, webbrowser, pygame.font
from random import randint
pygame.init()
current_directory = os.path.dirname(__file__)
font_file = 'ScaryPumpkin-Rpwx3.ttf'
font_path = os.path.join(current_directory, 'Assets', font_file)
spooky_font = pygame.font.Font(font_path, 30)
def main():
global FPS, gravity, clock, dead, score, run, started, runs, obstacles, manananggal, manananggal_img
global obstacle_img, win, roof_img, indicator_font, bg_img, screen_width, screen_height, point_sound
global highscore, github_url, github_logo, logo_x, logo_y, logo_width, logo_height, game_over_sound
global music
pygame.init()
FPS = 45
gravity = 1
dead = False
score = -2
run = True
started = False
runs = 0
highscore = 0
obstacles = []
screen_width, screen_height = 800, 600
win = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Manananggal Flight: Urban Skies Adventure")
clock = pygame.time.Clock()
manananggal_img = pygame.image.load(os.path.join("Assets", 'manananggal.png'))
bg_img = pygame.image.load(os.path.join("Assets", 'background.png'))
obstacle_img = pygame.image.load(os.path.join("Assets", 'obstacle.png'))
roof_img = pygame.image.load(os.path.join("Assets", 'roof.png'))
github_logo = pygame.image.load(os.path.join("Assets", 'Github.png'))
point_sound = pygame.mixer.Sound(os.path.join("Assets", 'point.wav'))
game_over_sound = pygame.mixer.Sound(os.path.join("Assets", 'game_over.wav'))
music = pygame.mixer.Sound(os.path.join("Assets", 'music.wav'))
icon_path = os.path.join("Assets", 'icon.png')
indicator_font = pygame.font.SysFont('Comic Sans', 30)
github_url = "https://github.com/CptZee/Mananangal-Fly"
logo_width, logo_height = github_logo.get_rect().size
logo_x = screen_width - logo_width - 10
logo_y = screen_height - logo_height - 10
#Set the values for the mananangal
manananggal = Manananggal()
manananggal.x = 250
manananggal.y = 250
manananggal.vel = 0
icon_image = pygame.image.load(icon_path)
pygame.display.set_icon(icon_image)
music.play(loops=-1)
music.set_volume(0.2)
RestartGame()
while run:
RunGame()
pygame.quit()
def ObstaclePair() :
r = randint(75, 350)
obstacles.append(Obstacle("DOWN", 900, r))
obstacles.append(Obstacle("UP", 900, 600-(r+125)))
global score
score += 1
if score > 0:
point_sound.play()
def AnimateRoof() :
win.blit(roof_img, ((runs%111)*-7, 500))
def RunGame():
global run, runs, started, restart_timer, score, highscore
while run:
pygame.time.delay(5)
for event in pygame.event.get() :
if event.type == pygame.KEYDOWN :
if event.key == pygame.K_ESCAPE :
run = False
elif event.key == pygame.K_SPACE :
if not started :
started = True
if not dead :
Manananggal.jump()
elif event.type == pygame.QUIT :
run = False
elif event.type == pygame.MOUSEBUTTONDOWN:
mouse_x, mouse_y = pygame.mouse.get_pos()
if logo_x <= mouse_x <= logo_x + logo_width and logo_y <= mouse_y <= logo_y + logo_height:
webbrowser.open('https://github.com/CptZee/Manananggal-Flight')
if not started :
started = True
if not dead :
Manananggal.jump()
win.blit(bg_img, (0, 0))
if runs % 45 == 0 and started :
ObstaclePair()
for o in obstacles :
o.update()
o.checkCollide()
if started != True:
background_rect = pygame.Surface((screen_width, screen_height), pygame.SRCALPHA)
background_color = (0, 0, 0, 150)
pygame.draw.rect(background_rect, background_color, (0, 0, screen_width, screen_height))
win.blit(background_rect, (0, 0))
text_lines = ["Press 'space bar' or 'click' to start the game",
"Press 'esc' to exit the game"]
DisplayIndicator(text_lines, -100, spooky_font, "#880808")
if score >= 0:
text_lines = ["Score: " + str(score),
"Highscore: " + str(highscore)]
DisplayIndicator(text_lines, 220, spooky_font, "#880808")
else:
text_lines = ["Mananangal Flight",
"Highscore: " + str(highscore)]
DisplayIndicator(text_lines, 180, spooky_font, "#880808")
Manananggal.update()
win.blit(manananggal, (Manananggal.x,Manananggal.y))
AnimateRoof()
win.blit(github_logo, (logo_x, logo_y))
pygame.display.update()
clock.tick(FPS)
highscore = max(score, highscore)
if dead:
game_over_sound.play()
RestartGame()
if not dead:
runs += 1
def DisplayIndicator(text_lines, y_adjustment, font, text_color):
y_offset = (screen_height // 2 - len(text_lines) * font.get_linesize() // 2) - y_adjustment
for line in text_lines:
text_surface = font.render(line, True, pygame.Color(text_color)) # Use the provided hex color
text_rect = text_surface.get_rect(center=(screen_width/2, y_offset))
win.blit(text_surface, text_rect)
y_offset += font.get_linesize()
def RestartGame():
global dead, started, runs, score, obstacles, restart_timer
dead = False
started = False
runs = 0
score = -2
restart_timer = 0
obstacles.clear()
# Use the spooky font for this text
text_lines = ["Mananangal Flight", "Highscore: " + str(highscore)]
DisplayIndicator(text_lines, 180, spooky_font, "#880808")
Manananggal.x = 250
Manananggal.y = 250
Manananggal.vel = 0
##
## Different classes
## TODO: Migrate them to their own .py file
##
class Manananggal :
x = 250
y = 250
vel = 0
def update() :
if started :
if Manananggal.y < 475 :
Manananggal.y += Manananggal.vel
Manananggal.vel += gravity
else :
Manananggal.y = 475
global dead
dead = True
if Manananggal.y < 0 :
Manananggal.y = 0
Manananggal.vel = 0
else :
Manananggal.y = 250 + math.sin(runs/10)*15
Manananggal.getAngle()
def jump() :
Manananggal.vel = -10
def getAngle() :
global manananggal
manananggal = pygame.transform.rotate(manananggal_img, -3*Manananggal.vel)
class Obstacle() :
def __init__(self, dir, x, len) :
self.dir = dir
self.x = x
self.len = len
def update(self) :
if self.dir == "UP" :
win.blit(obstacle_img, (self.x, 600-self.len))
else :
win.blit(pygame.transform.rotate(obstacle_img, 180), (self.x, self.len-431))
if not dead :
self.x -= 7
def checkCollide(self) :
global dead
if self.dir == "DOWN" :
if Manananggal.x + 48 > self.x and self.x + 75 > Manananggal.x :
if Manananggal.y + 2 < self.len :
dead = True
else :
if Manananggal.x + 48 > self.x and self.x + 75 > Manananggal.x :
if Manananggal.y + 45 > 600-self.len :
dead = True
main()