Added sound and music.
This commit is contained in:
21
audio.py
21
audio.py
@@ -1,3 +1,24 @@
|
||||
############################################
|
||||
# Created on 1-23-2013. Miguel Angel Astor #
|
||||
############################################
|
||||
import pygame
|
||||
|
||||
try:
|
||||
import pygame.mixer as mixer
|
||||
except ImportError:
|
||||
import android_mixer as mixer
|
||||
|
||||
class CachedAudioManager:
|
||||
def __init__(self):
|
||||
self.cache = {}
|
||||
|
||||
def load_sound(self, path):
|
||||
if path not in self.cache:
|
||||
self.cache[path] = mixer.Sound(path)
|
||||
|
||||
def play_sound(self, path):
|
||||
if path not in self.cache:
|
||||
self.load_sound(path)
|
||||
self.cache[path].play()
|
||||
|
||||
cached_audio_manager = CachedAudioManager()
|
||||
|
16
ingame.py
16
ingame.py
@@ -11,10 +11,16 @@ try:
|
||||
except ImportError:
|
||||
android = None
|
||||
|
||||
try:
|
||||
import pygame.mixer as mixer
|
||||
except ImportError:
|
||||
import android_mixer as mixer
|
||||
|
||||
import math_utils
|
||||
import player
|
||||
import background
|
||||
import imloader
|
||||
import audio
|
||||
import actor
|
||||
import database
|
||||
from state import BaseState, VALID_STATES
|
||||
@@ -330,6 +336,7 @@ class InGameState(BaseState):
|
||||
huggable.toggle_scared()
|
||||
|
||||
self.npcs.add(huggable)
|
||||
audio.cached_audio_manager.play_sound('sfx/Explo_1.wav')
|
||||
|
||||
def create_new_enemy(self, position):
|
||||
play_img = imloader.cached_image_loader.get_image_to_screen_percent('gfx/ForeverAlone/Idle_front.png')
|
||||
@@ -377,6 +384,7 @@ class InGameState(BaseState):
|
||||
enemy.set_angle(math_utils.angle_vectors_2D(self.vec_1, vec_2))
|
||||
|
||||
self.enemies.add(enemy)
|
||||
audio.cached_audio_manager.play_sound('sfx/amiguito.wav')
|
||||
|
||||
def input(self):
|
||||
for event in pygame.event.get():
|
||||
@@ -423,6 +431,9 @@ class InGameState(BaseState):
|
||||
# Start the enemy creation timer.
|
||||
pygame.time.set_timer(pygame.USEREVENT + 3, 3000)
|
||||
|
||||
mixer.music.load('music/8-Bit_Easter/01-DANJYON KIMURA-TELEPORTER.mp3')
|
||||
mixer.music.play(-1)
|
||||
|
||||
if self.cancel and self.time_left > 0:
|
||||
# If the player pressed escape, force a timeout.
|
||||
self.time_left = 0
|
||||
@@ -437,6 +448,7 @@ class InGameState(BaseState):
|
||||
player.PLAYERS[1].kill()
|
||||
self.done = True
|
||||
self.create_explosion(self.player.get_position())
|
||||
audio.cached_audio_manager.play_sound('sfx/Explo_4.wav')
|
||||
|
||||
if not self.done:
|
||||
if self.cursor_x != self.screen_center[0] or self.cursor_y != self.screen_center[1]:
|
||||
@@ -507,11 +519,13 @@ class InGameState(BaseState):
|
||||
if self.player.is_moving() and npc.test_collision_with_actor(self.player):
|
||||
npc.make_invisible()
|
||||
self.create_explosion(npc.get_position())
|
||||
audio.cached_audio_manager.play_sound('sfx/Explo_4.wav')
|
||||
player.PLAYERS[1].inc_score_by_one()
|
||||
self.time_left += 1
|
||||
|
||||
if player.PLAYERS[1].get_score() % 25 == 0:
|
||||
self.wave += 1
|
||||
audio.cached_audio_manager.play_sound('sfx/new_stage_1.wav')
|
||||
|
||||
# If the npc exploded this turn, remove it.
|
||||
if not npc.is_visible():
|
||||
@@ -536,10 +550,12 @@ class InGameState(BaseState):
|
||||
enemy.make_invisible()
|
||||
self.create_explosion(enemy.get_position())
|
||||
removal.add(enemy)
|
||||
audio.cached_audio_manager.play_sound('sfx/Explo_2.wav')
|
||||
elif enemy.get_position()[1] <= self.constraints[2] or enemy.get_position()[1] >= self.constraints[3]:
|
||||
enemy.make_invisible()
|
||||
self.create_explosion(enemy.get_position())
|
||||
removal.add(enemy)
|
||||
audio.cached_audio_manager.play_sound('sfx/Explo_2.wav')
|
||||
|
||||
if len(removal) > 0 and len(self.enemies) >= self.max_npc:
|
||||
# If npcs dissapeared this cycle restart the timer.
|
||||
|
21
intro.py
21
intro.py
@@ -10,6 +10,11 @@ try:
|
||||
except ImportError:
|
||||
android = None
|
||||
|
||||
try:
|
||||
import pygame.mixer as mixer
|
||||
except ImportError:
|
||||
import android_mixer as mixer
|
||||
|
||||
from state import BaseState, VALID_STATES
|
||||
import actor
|
||||
import game
|
||||
@@ -21,6 +26,7 @@ class IntroState(BaseState):
|
||||
def __init__(self):
|
||||
BaseState.__init__(self)
|
||||
|
||||
self.play_music = True
|
||||
self.count = 0
|
||||
self.next_transition = VALID_STATES['STAY']
|
||||
|
||||
@@ -89,6 +95,16 @@ class IntroState(BaseState):
|
||||
self.next_transition = VALID_STATES['MENU']
|
||||
|
||||
def update(self):
|
||||
if self.play_music:
|
||||
mixer.music.load('music/YellowSubmarine.mp3')
|
||||
mixer.music.play(0)
|
||||
self.play_music = False
|
||||
|
||||
if self.next_transition != VALID_STATES['QUIT']:
|
||||
sm_position = self.sine_movement.get_position()
|
||||
if sm_position[0] > pygame.display.Info().current_w + self.w_extra:
|
||||
self.next_transition = VALID_STATES['MENU']
|
||||
|
||||
self.sine_movement.update()
|
||||
sm_position = self.sine_movement.get_position()
|
||||
self.submarine.set_position([sm_position[0],
|
||||
@@ -103,11 +119,6 @@ class IntroState(BaseState):
|
||||
print "Position: " + str(self.sine_movement.get_position())
|
||||
print self.sine_movement.is_moving()
|
||||
|
||||
if self.next_transition != VALID_STATES['QUIT']:
|
||||
sm_position = self.sine_movement.get_position()
|
||||
if sm_position[0] > pygame.display.Info().current_w + self.w_extra:
|
||||
self.next_transition = VALID_STATES['MENU']
|
||||
|
||||
return self.next_transition
|
||||
|
||||
def render(self, canvas):
|
||||
|
6
main.py
6
main.py
@@ -9,6 +9,11 @@ try:
|
||||
except ImportError:
|
||||
android = None
|
||||
|
||||
try:
|
||||
import pygame.mixer as mixer
|
||||
except ImportError:
|
||||
import android_mixer as mixer
|
||||
|
||||
import database
|
||||
from game import Game
|
||||
|
||||
@@ -20,6 +25,7 @@ def main():
|
||||
# Init PyGame.
|
||||
pygame.init()
|
||||
pygame.font.init()
|
||||
mixer.init()
|
||||
|
||||
if android:
|
||||
# Init pgs4a and map Android's back button to PyGame's escape key.
|
||||
|
31
menu.py
31
menu.py
@@ -8,8 +8,14 @@ try:
|
||||
except ImportError:
|
||||
android = None
|
||||
|
||||
try:
|
||||
import pygame.mixer as mixer
|
||||
except ImportError:
|
||||
import android_mixer as mixer
|
||||
|
||||
import database
|
||||
import player
|
||||
import audio
|
||||
from constants import DEBUG
|
||||
from imloader import cached_image_loader
|
||||
from actor import BaseActor
|
||||
@@ -21,7 +27,7 @@ class MenuState(BaseState):
|
||||
def __init__(self):
|
||||
BaseState.__init__(self)
|
||||
|
||||
self.next_transition = VALID_STATES['STAY']
|
||||
self.next_transition = VALID_STATES['INTRO']
|
||||
self.current_menu = MENUS['MAIN']
|
||||
self.story_time = 0
|
||||
self.story_timeout = 7000 # 7 seconds.
|
||||
@@ -185,14 +191,8 @@ class MenuState(BaseState):
|
||||
self.user_click = True
|
||||
|
||||
def update(self):
|
||||
if android is None:
|
||||
pygame.mouse.set_visible(True)
|
||||
|
||||
player.PLAYERS[1].reset_score()
|
||||
|
||||
if self.next_transition != VALID_STATES['QUIT']:
|
||||
if self.next_transition != VALID_STATES['STAY']:
|
||||
# Set next_transition to STAY if the game gets to this state from ScoreState.
|
||||
self.next_transition = VALID_STATES['STAY']
|
||||
# Reset the scores label to force a database reload.
|
||||
self.score_1 = None
|
||||
@@ -200,6 +200,17 @@ class MenuState(BaseState):
|
||||
self.score_3 = None
|
||||
self.score_4 = None
|
||||
self.score_5 = None
|
||||
if android is None:
|
||||
pygame.mouse.set_visible(True)
|
||||
player.PLAYERS[1].reset_score()
|
||||
|
||||
if self.current_menu == MENUS['MAIN'] or self.current_menu == MENUS['INTRO']:
|
||||
mixer.music.load('music/Press_Start_Infinitoooooooo.mp3')
|
||||
mixer.music.play(-1)
|
||||
else:
|
||||
mixer.music.load('music/Wind_Waker_Main (Remix).mp3')
|
||||
mixer.music.play(-1)
|
||||
|
||||
|
||||
if self.current_menu == MENUS['MAIN']:
|
||||
# Check for mouse (tap) collisions with the main menu buttons.
|
||||
@@ -210,16 +221,22 @@ class MenuState(BaseState):
|
||||
# Collision with the high scores button.
|
||||
self.current_menu = MENUS['SCORE']
|
||||
self.reload_scores()
|
||||
mixer.music.load('music/Wind_Waker_Main (Remix).mp3')
|
||||
mixer.music.play(-1)
|
||||
elif self.new_button.rect.collidepoint(self.cursor_x, self.cursor_y):
|
||||
# Collision with the new game button.
|
||||
self.current_menu = MENUS['INTRO']
|
||||
self.then = pygame.time.get_ticks()
|
||||
mixer.music.stop()
|
||||
audio.cached_audio_manager.play_sound('sfx/press_start_2.wav')
|
||||
|
||||
elif self.current_menu == MENUS['SCORE']:
|
||||
# Check for mouse (tap) collisions with the high scores menu buttons.
|
||||
if self.back_button.rect.collidepoint(self.cursor_x, self.cursor_y):
|
||||
# Collision with the go back button.
|
||||
self.current_menu = MENUS['MAIN']
|
||||
mixer.music.load('music/Press_Start_Infinitoooooooo.mp3')
|
||||
mixer.music.play(-1)
|
||||
|
||||
elif self.current_menu == MENUS['INTRO']:
|
||||
# Wait for a timeout before going to the game.
|
||||
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
11
score.py
11
score.py
@@ -9,8 +9,14 @@ try:
|
||||
except ImportError:
|
||||
android = None
|
||||
|
||||
try:
|
||||
import pygame.mixer as mixer
|
||||
except ImportError:
|
||||
import android_mixer as mixer
|
||||
|
||||
import player
|
||||
import database
|
||||
import audio
|
||||
from constants import DEBUG
|
||||
from imloader import cached_image_loader
|
||||
from actor import BaseActor
|
||||
@@ -21,7 +27,7 @@ class ScoreState(BaseState):
|
||||
BaseState.__init__(self)
|
||||
|
||||
self.background_color = (125, 158, 192)
|
||||
self.next_transition = VALID_STATES['STAY']
|
||||
self.next_transition = VALID_STATES['MENU']
|
||||
self.cursor_x = 0
|
||||
self.cursor_y = 0
|
||||
|
||||
@@ -97,6 +103,9 @@ class ScoreState(BaseState):
|
||||
if self.next_transition != VALID_STATES['STAY']:
|
||||
# Set next_transition to STAY if the game gets to this state from GameState a second or third time, etc.
|
||||
self.next_transition = VALID_STATES['STAY']
|
||||
mixer.music.stop()
|
||||
audio.cached_audio_manager.play_sound('sfx/Game_Over_2.wav')
|
||||
|
||||
|
||||
if self.letter_index < 3:
|
||||
# If not all initials are set, check taps on every letter.
|
||||
|
Reference in New Issue
Block a user