1. Dominic Kexel
  2. pymissile

Commits

Dominic Kexel  committed 79becf2 Draft

sounds

  • Participants
  • Parent commits 1b37a06
  • Branches default

Comments (0)

Files changed (3)

File Noise 004.wav

  • Ignore whitespace
Binary file added.

File battle.py

View file
  • Ignore whitespace
 from constants import *
 from vector import *
 from physic import space, to_pymunk, to_pygame
+from sound import *
 
 city_data = \
 """
         
     if explode:
       self._moving = False
+      play_explosion()
       Explosion(start_pos=self._current, speed=18, size=300, shrapnels=False, scene=self.scene)
       Explosion(start_pos=self._current, speed=3, size=40, scene=self.scene, kills=True)
       self.die()
   def __init__(self, game):
     super(Battle, self).__init__(game)
     self._state = GameState()
-    self._event_handler = {pygame.MOUSEBUTTONUP: self._fire_rocket}
+    self._event_handler = {pygame.MOUSEBUTTONUP: self._fire_rocket,
+                           pygame.KEYUP: self._handle_key}
     self._background = pygame.transform.scale(pygame.image.load('back.jpg'), (SCREEN_WIDTH, SCREEN_HEIGHT)).convert()
     self._silos = {}
     self._cities = {}
     self._initialized = False
     self._enemy_timeout = r(10, 300)
-
+    self.paused = False
+    
+  def _handle_key(self, event):
+    if event.key == pygame.K_SPACE:
+      self.paused = not self.paused
+    
   def enter(self):
     if self._initialized: return
     for inx, city in enumerate(self._state.cities):
     silo.fire()
   
   def update_state(self):
+    if self.paused: return
     super(Battle, self).update_state()
     self._enemy_timeout -= 1
     if not self._enemy_timeout:

File sound.py

View file
  • Ignore whitespace
+import pygame
+#from random import choice
+
+pygame.mixer.init()
+
+_sounds = {}
+_noise = 'Noise 004.wav'
+
+#for n in _noise:
+_sounds[_noise] = pygame.mixer.Sound(n)
+
+def play_explosion():
+  _sounds[_noise].play()