Commits

schlangen committed d4ae795

- implemented plattform params

Comments (0)

Files changed (4)

                 
         # "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
                     #! improve
                     cf = CONVERT_FUNCTIONS[param["type"]]
                     val = se.findtext(param["name"])
-                    params[param["name"]] = cf(val) or cf(param["default"])
+                    if val:
+                        params[param["name"]] = cf(val) or cf(param["default"])
                         
                 if name == "plattform":
                     Plattform(pos, size, params, self, self.allsprites,

gallox/settings.py

 
 
 # total number of minutes with boost on from 100% to 0% fuel
-BOOST_DURATION = 1.0
+BOOST_DURATION = 0.1
 # percentage points per minute
 MILEAGE = 100 / BOOST_DURATION
 
 """
 SPRITE_PARAMS = {
         "plattform":[
-               { "name": "refuel",
-                 "repr_name": "refuel",
-                 "type": BOOL,
-                 "default": True,
-                 "args": {}
+                # all [%] values here are related to the player tank
+                {"name": "tankSize",
+                 "repr_name": "tank size [%]",
+                 "type": FLOAT,
+                 "default": 20,
+                 "args": {"min_val":0,
+                          "max_val":100}
+                },
+                {"name": "fuelSpeed",
+                 "repr_name": "fuel speed [%/s]",
+                 "type": FLOAT,
+                 "default": 20,
+                 "args": {"min_val":0,
+                          "max_val":100}
+                },
+                {"name": "restockRate",
+                 "repr_name": "restock rate [%/s]",
+                 "type": FLOAT,
+                 "default": 10,
+                 "args": {"min_val":0,
+                          "max_val":100}
                 },
                     ],
         "gun":[

gallox/sprites/static.py

 import pygame
 
 from gallox.utils import load_image, load_sound
-
+                
 class Plattform(pygame.sprite.Sprite):
     def __init__(self, pos, size, params, map, *groups):
         pygame.sprite.Sprite.__init__(self, *groups)
         self.map = map
+        self.tank_size = self.fuel = params.get("tankSize", 20)
+        self.fuel_speed = params.get("fuelSpeed", 7)
+        self.restock_rate = params.get("restockRate", 3)
         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 = None
+        self.fueling = False
         
     def dock(self, ship):
         print "ship docked successfully"
         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
+            #! start fueling sound
+
     def undock(self):
         print "undocked"
-        self.docked_sound.stop()
+        self.docked_sound.stop()
+        self.docked = None
+        
+    def update(self, events, ticks):
+        if self.docked and self.fueling:
+            amount = min(self.fuel_speed * ticks / 1000., self.fuel)
+            self.fuel -= amount
+            self.docked.fuel += amount
+            # self empty or ship full
+            if self.fuel == 0 or self.docked.fuel == 100:
+                self.fueling = False
+        elif self.fuel != self.tank_size:
+            # restock
+            self.fuel += min(self.restock_rate * ticks / 1000., 
+                             self.tank_size - self.fuel)
+            
+            
+            
+