Commits

schlangen committed 52a9cf9

Add old changes

  • Participants
  • Parent commits d4ae795

Comments (0)

Files changed (18)

File data/gui/icons/applications-development.png

Added
New image

File data/gui/icons/applications-graphics.png

Added
New image

File data/gui/icons/applications-multimedia.png

Added
New image

File data/gui/icons/applications-office.png

Added
New image

File data/gui/icons/preferences-desktop-peripherals.png

Added
New image

File data/gui/icons/system-search.png

Added
New image

File data/gui/icons/system-shutdown.png

Added
New image

File data/sounds/alarm.wav

Binary file added.

File data/sounds/fueling.wav

Binary file added.

File data/sounds/sound_authors.txt

 plattform.mp3 - 62170_IFartInUrGeneralDirection_ALERT.mp3 
 plattform2 - 1526_nicStage_highVoltageDrone.wav
-photo - 7310__bebeto__Photo_Click.wav
+photo - 7310__bebeto__Photo_Click.wav
+fueling.wav - 620__virotic__nanomecano01.wav
+alarm.wav - 32987__HardPCM__Alarm003.wav

File gallox/main.py

                 
         # "menu" or "game" or "editor" or "gamemenu"
         self.state = "menu"
-        self.fade_to(self.menu)
-#        self.start_game("testlevel")
+#        self.fade_to(self.menu)
+        self.start_game("testlevel")
 #        self.start_editor()
         self.photo_sound = load_sound("photo.wav")
         self.c = 0

File gallox/map.py

+import math
+
 import xml.etree.ElementTree as ET
 from xml.dom.minidom import parseString
 
 import pygame
 
 from gallox.sprites import *
-from gallox.utils import load_image
+from gallox.utils import load_image, load_sound, nearest_point, dist_pr
 from gallox.settings import *
 
 class Map(object):
         self.plattforms = pygame.sprite.Group()
         self.surf = None
         self.ship = None
+        # channel - source rect mapping
+        self.sounds = {}
+        self._cached_ship_pos = None
         self.load(path)
         
         
+        
     def update(self, events, ticks):
         self.allsprites.update(events, ticks)
         
         self.allsprites.draw(self.surf)
         # self.surf.blit(self.fg_image, (0,0))
         
-        return events, [self.rect]
-       
+        if self.ship.rect.center != self._cached_ship_pos:
+            self._cached_ship_pos = sx, sy = self.ship.rect.center
+            for channel, rect in self.sounds.items():            
+                if channel.get_busy():
+                    rx,ry = nearest_point(rect, (sx,sy))
+                    
+                    dist = math.hypot(rx-sx, ry-sy) or 0.0
+#                    angle = math.atan2(sy-ry, sx-rx)
+                    # hoerereignisrichtung
+#                    sound_dir = 173.2 * math.tan(math.radians(angle))
+                    
+#                    #dist = math.hypot(x - pos[0], y - pos[1])
+#                    ldist = dist_pr((sx-50,sy), rect) or 0.001
+#                    rdist = dist_pr((sy+50, sy), rect) or 0.001
+#                    #! just a test -> improve
+#                    lvolume = min(max(1.0 * 10. / ldist , 0), 1)
+#                    rvolume = min(max(1.0 * 10. / rdist, 0), 1)
+#                    channel.set_volume(lvolume, rvolume)
+                    
+                    volume = min(max(1.0 * 10. / dist, 0), 1)
+                    channel.set_volume(volume)
+                    
+                else:
+                    del self.sounds[channel]
+        
+        
+        
+        return events, [self.rect]      
         
         
     def collides(self, object):
                     print "#"*30
                     print "ship killed"
                     print "#"*30
+                    
+    def sound(self, name, source):
+        """
+        source may be a rect, pos or object that has a rect attribute
+        """
+        if len(source) == 2:
+            rect = pygame.Rect(source, (1,1))
+        else:
+            rect = pygame.Rect(source)
+        s = SOUNDS[name]
+        c = load_sound(s["name"]).play(loops=s.get("loops", 0),
+                                       fade_ms=s.get("fade_ms", 0))
+        if c:
+            self.sounds[c] = rect
+        return c
+    
+    def hush(self, channel):
+        if channel in self.sounds:
+            del self.sounds[channel]
+            channel.stop()
+        
+                    
    
     def load(self, path):
         tree = ET.parse(os.path.join(path, "level.xml"))

File gallox/settings.py

 
 # game settings
 FPS = 40
-SAFE_COLOR = 128, 0, 0
+#SAFE_COLOR = 128, 0, 0
 ALPHA_COLOR = 255, 0, 255
 BULLET_HOLE_RADIUS = 15  # < level/map dependent?
 
 
 # ===== internal ===== #
 
+SOUNDS = {"fueling":
+                    {"name":"fueling.wav",
+                     "loops":-1,
+                     "fade_ms": 500},
+          
+          "alarm":
+                    {"name":"alarm.wav",
+                     "loops":-1,
+                     "fade_ms": 500}
+          }
+
 DEFAULT_SPRITE_ATTRS = {"fix_no":False, "turnable":False, "resizable":False}
 SPRITES = {
         "plattform":{"resizable":True},

File gallox/sprites/static.py

         self.image, self.rect = load_image("plattform")
         self.image = pygame.transform.scale(self.image, size)
         self.rect = self.image.get_rect(topleft=pos)
-        self.docked_sound = load_sound("plattform2.wav")
+#        self.docked_sound = load_sound("plattform2.wav")
+        self.fueling_channel = None
         self.docked = None
         self.fueling = False
         
     def dock(self, ship):
         print "ship docked successfully"
-        self.docked_sound.play(loops=-1)
+#        self.docked_sound.play(loops=-1)
         self.docked = ship
         
         # check for fuelling
         if ship.fuel < 100 and self.fuel > 0 and self.fuel_speed:
             self.fueling = True
+            self.fueling_channel = self.map.sound("fueling", self.rect.center)
             #! start fueling sound
 
     def undock(self):
         print "undocked"
-        self.docked_sound.stop()
+#        self.docked_sound.stop()
         self.docked = None
+        # stop sound (don't care if its actually still playing)
+        self.map.hush(self.fueling_channel)
+        self.fueling_chanel = None
         
     def update(self, events, ticks):
         if self.docked and self.fueling:
             # self empty or ship full
             if self.fuel == 0 or self.docked.fuel == 100:
                 self.fueling = False
+                # stop sound
+                self.map.hush(self.fueling_channel)
+                self.fueling_chanel = None
+                
         elif self.fuel != self.tank_size:
             # restock
             self.fuel += min(self.restock_rate * ticks / 1000., 

File gallox/ui/game.py

         pygame.draw.aaline(screen, (0,0,0), start, stop1, 1)
         # draw the arrow head
         for a,b in ((p1,p2), (p2,stop2), (stop2,p1)):
-            pygame.draw.aaline(screen, (0,0,0), a, b, 1)
-       
-import Numeric as N
-import pygame.surfarray as surfarray
-
-def blur(image):
-    rgbarray = surfarray.array3d(image)
-
-    soften = N.array(rgbarray)*1
-    soften[1:,:]  += rgbarray[:-1,:]*8
-    soften[:-1,:] += rgbarray[1:,:]*8
-    soften[:,1:]  += rgbarray[:,:-1]*8
-    soften[:,:-1] += rgbarray[:,1:]*8
-    soften /= 33
-    return soften
+            pygame.draw.aaline(screen, (0,0,0), a, b, 1)

File gallox/utils.py

 import os
 import sys
+import math
 
 import pygame
 from gallox.settings import *
         raise SystemExit, message
     return sound
 
+def nearest_point(rect, point):
+    """
+    return the nearest point of rect to point
+    """
+    px, py = point
+    if px < rect.left:
+        x = rect.left
+    elif px > rect.right:
+        x = rect.right
+    else:
+        x = px
+    if py < rect.top:
+        y = rect.top
+    elif py > rect.bottom:
+        y = rect.bottom
+    else:
+        y = py
+    return x,y
+
+def dist_pr(point, rect):
+    x,y = point
+    rx,ry = nearest_point(rect, point)
+    return math.hypot(rx-x, ry-y)
 
 class Fader(object):
     def __init__(self, time=1, color=(0,0,0), direction="out", 

File gallox/world.py

 
 from gallox.map import Map
 from gallox.camera import Camera
-from gallox.ui.game import StatusOverlay, blur
+from gallox.ui.game import StatusOverlay
 from gallox.ui.menu import GameMenu
 from gallox.replay import Recorder, Player
 from gallox.sprites import *
             
         self.paused = False
         self.unpause = False
-        self._blur_step = 0
         self._ticks_before_pause = 0
         
     def update(self, events):
             else:
                 events, drects = self.menu.update(events)
             
-#        if self.paused:
-#            if self._blur_step:
-#                drects.append(self.cam.rect)
-#        else:
         else:
             not_used = []
             for event in events:
                     if event.key == pygame.K_ESCAPE:
                         self._ticks_before_pause = ticks
                         self.paused = True
-                        self._blur_step = 10
                         continue
                 not_used.append(event)
             events = not_used
 
     def blit(self, screen):
         if self.paused:
-#            if self._blur_step:
-#                pygame.surfarray.blit_array(screen, blur(screen))
-#                self._blur_step -= 1
             self.cam.draw(screen)
             self.ui.draw(screen)
             self.menu.blit(screen)

File testlevel/level.xml

       <rotRange>60</rotRange>
       <shotFreq>20</shotFreq>
     </sprite>
-    <sprite degrees="-130" type="ship">
-      <position x="239" y="184" />
+    <sprite degrees="-60" type="ship">
+      <position x="230" y="196" />
       <size h="25" w="25" />
     </sprite>
     <sprite type="plattform">
-      <position x="214" y="283" />
-      <size h="22" w="75" />
-      <refuel>True</refuel>
+      <position x="216" y="283" />
+      <size h="23" w="77" />
+      <restockRate>10</restockRate>
+      <tankSize>20</tankSize>
+      <fuelSpeed>20</fuelSpeed>
     </sprite>
     <sprite type="plattform">
       <position x="498" y="344" />
       <size h="13" w="73" />
-      <refuel>True</refuel>
+      <restockRate>10</restockRate>
+      <tankSize>20</tankSize>
+      <fuelSpeed>20</fuelSpeed>
     </sprite>
     <sprite degrees="10" type="gun">
       <position x="789" y="490" />
     <sprite type="plattform">
       <position x="818" y="611" />
       <size h="7" w="60" />
-      <refuel>True</refuel>
+      <restockRate>10</restockRate>
+      <tankSize>20</tankSize>
+      <fuelSpeed>20</fuelSpeed>
     </sprite>
     <sprite type="plattform">
       <position x="144" y="474" />
       <size h="11" w="47" />
-      <refuel>True</refuel>
+      <restockRate>10</restockRate>
+      <tankSize>20</tankSize>
+      <fuelSpeed>20</fuelSpeed>
     </sprite>
     <sprite type="plattform">
       <position x="895" y="729" />
       <size h="32" w="44" />
-      <refuel>True</refuel>
+      <restockRate>10</restockRate>
+      <tankSize>20</tankSize>
+      <fuelSpeed>20</fuelSpeed>
     </sprite>
     <sprite degrees="-160" type="gun">
       <position x="342" y="552" />