This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a main menu and start sequence with it's own background music
- Loading branch information
1 parent
f3f5822
commit d75cb94
Showing
4 changed files
with
62 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,14 @@ | |
# @Author: tasdik | ||
# @Date: 2016-01-17 | ||
# @Email: [email protected] Github username: @prodicus | ||
# @Last Modified by: tasdik | ||
# @Last Modified time: 2016-01-18 | ||
# @Last Modified by: Branden | ||
# @Last Modified time: 2016-01-20 | ||
# MIT License. You can find a copy of the License @ http://prodicus.mit-license.org | ||
|
||
## Game music Attribution | ||
##Frozen Jam by tgfcoder <https://twitter.com/tgfcoder> licensed under CC-BY-3 <http://creativecommons.org/licenses/by/3.0/> | ||
##Frozen Jam by tgfcoder <https://twitter.com/tgfcoder> licensed under CC-BY-3 <http://creativecommons.org/licenses/by/3.0/>' | ||
## | ||
## Additional assets by: Branden M. Ardelean | ||
|
||
import pygame | ||
import random | ||
|
@@ -46,6 +48,39 @@ | |
|
||
font_name = pygame.font.match_font('arial') | ||
|
||
def main_menu(): | ||
global screen | ||
|
||
menu_song = pygame.mixer.music.load(path.join(sound_folder, "menu.ogg")) | ||
pygame.mixer.music.play(-1) | ||
|
||
title = pygame.image.load(path.join(img_dir, "main.png")).convert() | ||
title = pygame.transform.scale(title, (WIDTH, HEIGHT), screen) | ||
|
||
screen.blit(title, (0,0)) | ||
pygame.display.update() | ||
|
||
while True: | ||
ev = pygame.event.poll() | ||
if ev.type == pygame.KEYDOWN: | ||
if ev.key == pygame.K_RETURN: | ||
break | ||
elif ev.key == pygame.K_q: | ||
pygame.quit() | ||
quit() | ||
else: | ||
draw_text(screen, "Press [ENTER] To Begin", 30, WIDTH/2, HEIGHT/2) | ||
draw_text(screen, "or [Q] To Quit", 30, WIDTH/2, (HEIGHT/2)+40) | ||
pygame.display.update() | ||
|
||
#pygame.mixer.music.stop() | ||
ready = pygame.mixer.Sound(path.join(sound_folder,'getready.ogg')) | ||
ready.play() | ||
screen.fill((0,0,0)) | ||
draw_text(screen, "GET READY!", 40, WIDTH/2, HEIGHT/2) | ||
pygame.display.update() | ||
|
||
|
||
def draw_text(surf, text, size, x, y): | ||
## selecting a cross platform font to display the score | ||
font = pygame.font.Font(font_name, size) | ||
|
@@ -146,9 +181,10 @@ def update(self): | |
keystate = pygame.key.get_pressed() | ||
if keystate[pygame.K_LEFT]: | ||
self.speedx = -5 | ||
if keystate[pygame.K_RIGHT]: | ||
elif keystate[pygame.K_RIGHT]: | ||
self.speedx = 5 | ||
|
||
#Fire weapons by holding spacebar | ||
if keystate[pygame.K_SPACE]: | ||
self.shoot() | ||
|
||
|
@@ -373,8 +409,8 @@ def update(self): | |
for sound in ['expl3.wav', 'expl6.wav']: | ||
expl_sounds.append(pygame.mixer.Sound(path.join(sound_folder, sound))) | ||
## main background music | ||
pygame.mixer.music.load(path.join(sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg')) | ||
pygame.mixer.music.set_volume(0.2) | ||
#pygame.mixer.music.load(path.join(sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg')) | ||
pygame.mixer.music.set_volume(0.5) | ||
|
||
player_die_sound = pygame.mixer.Sound(path.join(sound_folder, 'rumble1.ogg')) | ||
################################################### | ||
|
@@ -402,18 +438,36 @@ def update(self): | |
## TODO: make the game music loop over again and again. play(loops=-1) is not working | ||
# Error : | ||
# TypeError: play() takes no keyword arguments | ||
pygame.mixer.music.play() | ||
#pygame.mixer.music.play() | ||
|
||
############################# | ||
## Game loop | ||
running = True | ||
menu_display = True | ||
while running: | ||
if menu_display: | ||
main_menu() | ||
pygame.time.wait(3000) | ||
|
||
#Stop menu music | ||
pygame.mixer.music.stop() | ||
#Play the gameplay music | ||
pygame.mixer.music.load(path.join(sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg')) | ||
pygame.mixer.music.play() | ||
|
||
menu_display = False | ||
|
||
#1 Process input/events | ||
clock.tick(FPS) ## will make the loop run at the same speed all the time | ||
for event in pygame.event.get(): # gets all the events which have occured till now and keeps tab of them. | ||
## listening for the the X button at the top | ||
if event.type == pygame.QUIT: | ||
running = False | ||
|
||
## Press ESC to exit game | ||
if event.type == pygame.KEYDOWN: | ||
if event.key == pygame.K_ESCAPE: | ||
running = False | ||
# ## event for shooting the bullets | ||
# elif event.type == pygame.KEYDOWN: | ||
# if event.key == pygame.K_SPACE: | ||
|
@@ -490,4 +544,4 @@ def update(self): | |
## Done after drawing everything to the screen | ||
pygame.display.flip() | ||
|
||
pygame.quit() | ||
pygame.quit() |
d75cb94
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Could it be possible to loop over to the main menu for asking the player "to continue or to quit" once all the lives are over.
I mean, to display the same menu image, but looped when all the lives are lost. This would prevent from abruptly closing the game window.
What do you think @bardlean86