Commits

Daniel Pope committed fd0ff8b Draft

New: thruster

Comments (0)

Files changed (8)

korovic/__init__.py

+"""Monkey patch pyglet to pad the texture atlas to remove adjacency artifacts.
+
+Taken from http://markmail.org/message/qn65kjlieq6n333k
+"""
+import pyglet.image.atlas
+
+
+def _texture_atlas_add(self, img):
+    pad = 1
+    x, y = self.allocator.alloc(img.width + pad * 2, img.height + pad * 2)
+    self.texture.blit_into(img, x + pad, y + pad, 0)
+    region = self.texture.get_region(x + pad, y + pad, img.width, img.height)
+    return region
+
+pyglet.image.atlas.TextureAtlas.add = _texture_atlas_add

korovic/components/engines.py

     def force_angle(self):
         return self.force_angles[self.slot.flags]
     
-    @property
-    def angle(self):
-        return self.angles[self.slot.flags]
+    def attach_at_slot(self, slot):
+        self.angle = self.angles[slot.flags]
+        super(Propeller, self).attach_at_slot(slot)
 
     def controller(self):
         return PressController(self)
 
     def editor(self):
         return AngleEditor(self, min_angle=-10, max_angle=10)
+
+
+class Thruster(Propeller):
+    MASS = 2
+    FORCE = v(10000, 0)
+    sound = load_sound('data/sounds/hotairballoon.wav')
+
+    FUEL_CONSUMPTION = 3
+
+    angles = {
+        Slot.TOP: math.pi * 0.5,
+        Slot.BOTTOM: math.pi * 0.5,
+        Slot.NOSE: math.pi,
+        Slot.TAIL: 0
+    }
+
+    def editor(self):
+        a = int(math.degrees(self.angles[self.slot.flags]))
+        return AngleEditor(self, min_angle=a - 45, max_angle=a + 45)
+
+    def force_angle(self):
+        return self.angle

korovic/components/squid.py

         img = loader.image('data/sprites/squid-shadow.png') 
         w = img.width
         img.anchor_x = w * 0.5
+        img.anchor_y = img.height * 0.5
         cls.shadow_image = img
 
     def __init__(self, world):
 
     def draw_shadow(self):
         if self.body.position.y > SEA_LEVEL:
-            self.shadow.set_position(self.body.position.x, SEA_LEVEL)
+            self.shadow.set_position(self.body.position.x, SEA_LEVEL + 23)
             self.shadow.opacity = max(255 - self.body.position.y, 0)
             self.shadow.draw()
 

korovic/data/components/thruster.json

+{"points": [], "radius": 6, "name": "sprites/thruster.png", "offset": [-58, -11]}

korovic/data/sprites/thruster-on.png

Added
New image

korovic/data/sprites/thruster.png

Added
New image

korovic/editor.py

     def on_mouse_release(self, x, y, button, modifiers):
         ret = super(AngleEditor, self).on_mouse_release(x, y, button, modifiers)
         if ret:
+            e = self.component.editor()
+            self.min_angle = e.min_angle
+            self.max_angle = e.max_angle
             self.build_protractor()
             return ret
         if self.adjusting:
             self.click.play()
             p = v(x, y)
             angle = (p - self.protractor.centre).angle
+            if self.max_angle > 180 and angle < 0:
+                angle += 360
             angle = min(self.max_angle, max(self.min_angle, angle))
             self.component.angle = math.radians(angle)
             self.protractor.set_angle(angle)

korovic/editor_hud.py

     Item('Hang Glider', 100, components.HangGlider, 'And it vill keep ze sun off you!'),
     Item('Ekranoplan', 400, components.Ekranoplan, 'I stole zese from ze Russians.'),
     Item('Hot Air Balloon', 275, components.HotAirBalloon, 'Up, up and avay!'),
+    Item('Thruster', 150, components.Thruster, 'Zese may help you keep upright.'),
 ]
 
 GREY = (90, 90, 90, 255)