changeset 261:db7c8e74efb4

(really rubbish) bullets
author Stefano Rivera <stefano@rivera.za.net>
date Thu, 05 Sep 2013 00:36:30 +0200
parents e723b313c958
children 521f73061872
files data/images/objects/bullet.png nagslang/constants.py nagslang/events.py nagslang/game_object.py nagslang/protagonist.py nagslang/screens/area.py nagslang/world.py source/images/objects/bullet.svg
diffstat 8 files changed, 150 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
Binary file data/images/objects/bullet.png has changed
--- a/nagslang/constants.py	Thu Sep 05 00:32:56 2013 +0200
+++ b/nagslang/constants.py	Thu Sep 05 00:36:30 2013 +0200
@@ -15,6 +15,7 @@
 COLLISION_TYPE_BOX = 4
 COLLISION_TYPE_ENEMY = 5
 COLLISION_TYPE_DOOR = 6
+COLLISION_TYPE_PROJECTILE = 7
 
 SWITCH_PUSHERS = [COLLISION_TYPE_PLAYER, COLLISION_TYPE_BOX]
 
--- a/nagslang/events.py	Thu Sep 05 00:32:56 2013 +0200
+++ b/nagslang/events.py	Thu Sep 05 00:36:30 2013 +0200
@@ -44,3 +44,9 @@
     @classmethod
     def post(cls, destination, dest_pos):
         super(DoorEvent, cls).post(destination=destination, dest_pos=dest_pos)
+
+
+class FireEvent(UserEvent):
+    @classmethod
+    def post(cls, source, impulse):
+        super(FireEvent, cls).post(source=source, impulse=impulse)
--- a/nagslang/game_object.py	Thu Sep 05 00:32:56 2013 +0200
+++ b/nagslang/game_object.py	Thu Sep 05 00:36:30 2013 +0200
@@ -5,7 +5,7 @@
 from nagslang import render
 from nagslang.constants import (
     SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW,
-    ZORDER_FLOOR, COLLISION_TYPE_DOOR)
+    ZORDER_FLOOR, COLLISION_TYPE_DOOR, COLLISION_TYPE_PROJECTILE)
 from nagslang.resources import resources
 from nagslang.events import DoorEvent
 
@@ -292,3 +292,15 @@
     def requires(cls):
         return [("name", "string"), ("end1", "coordinates"),
                 ("end2", "coordinates"), ("key_state", "puzzler")]
+
+
+class Bullet(GameObject):
+    def __init__(self, space, position, impulse):
+        body = make_body(1, pymunk.inf, position)
+        self.shape = pymunk.Circle(body, 1)
+        self.shape.collision_type = COLLISION_TYPE_PROJECTILE
+        super(Bullet, self).__init__(
+            SingleShapePhysicser(space, self.shape),
+            render.ImageRenderer(resources.get_image('objects', 'bullet.png')),
+        )
+        self.physicser.apply_impulse(impulse)
--- a/nagslang/protagonist.py	Thu Sep 05 00:32:56 2013 +0200
+++ b/nagslang/protagonist.py	Thu Sep 05 00:36:30 2013 +0200
@@ -6,6 +6,7 @@
 from nagslang.constants import COLLISION_TYPE_PLAYER, ZORDER_MID, \
     WEREWOLF_SOAK_FACTOR, PROTAGONIST_HEALTH_MIN_LEVEL, \
     PROTAGONIST_HEALTH_MAX_LEVEL
+from nagslang.events import FireEvent
 from nagslang.game_object import GameObject, Physicser, make_body
 from nagslang.mutators import FLIP_H
 from nagslang.resources import resources
@@ -218,7 +219,11 @@
     def attack(self):
         """Attempt to hurt something.
         """
-        pass
+        vec = Vec2d.unit()
+        vec.angle = self.angle
+        vec.length = 100
+        FireEvent.post(self.physicser.position, vec)
+        print "Biff", self.physicser.position, vec
 
     def in_wolf_form(self):
         return self.form == self.WOLF_FORM
--- a/nagslang/screens/area.py	Thu Sep 05 00:32:56 2013 +0200
+++ b/nagslang/screens/area.py	Thu Sep 05 00:36:30 2013 +0200
@@ -6,10 +6,11 @@
 
 from nagslang.constants import COLLISION_TYPE_PLAYER, CALLBACK_COLLIDERS, \
     COLLISION_TYPE_ENEMY
-from nagslang.events import ScreenChange, DoorEvent
+from nagslang.events import ScreenChange, DoorEvent, FireEvent
 from nagslang.level import Level
 from nagslang.protagonist import Protagonist
 from nagslang.screens.base import Screen
+from nagslang.game_object import Bullet
 
 
 class ControlKeys(object):
@@ -130,6 +131,9 @@
             if ev.key == pygame.locals.K_c:
                 self.protagonist.toggle_form()
                 self.world.transformations += 1
+            if ev.key == pygame.locals.K_SPACE:
+                self.world.attacks += 1
+                self.protagonist.attack()
         elif DoorEvent.matches(ev):
             self.protagonist.set_position(ev.dest_pos)
             if ev.destination != self.name:
@@ -140,6 +144,9 @@
                 return
             # else we're teleporting within the screen, and just the
             # position change is enough
+        elif FireEvent.matches(ev):
+            bullet = Bullet(self.space, ev.source, ev.impulse)
+            self._drawables.add(bullet)
         self.keys.handle_event(ev)
 
     def _calc_viewport(self, level_surface, display_surface):
--- a/nagslang/world.py	Thu Sep 05 00:32:56 2013 +0200
+++ b/nagslang/world.py	Thu Sep 05 00:36:30 2013 +0200
@@ -14,6 +14,7 @@
         self.reset()
 
     def reset(self):
+        self.attacks = 0
         self.transformations = 0
         self.kills = 0
         self.rooms = 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/images/objects/bullet.svg	Thu Sep 05 00:36:30 2013 +0200
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="200"
+   height="200"
+   id="svg7373"
+   version="1.1"
+   inkscape:version="0.48.4 r9939"
+   sodipodi:docname="bullet.svg">
+  <defs
+     id="defs7375">
+    <linearGradient
+       id="linearGradient7907">
+      <stop
+         style="stop-color:#008080;stop-opacity:1;"
+         offset="0"
+         id="stop7909" />
+      <stop
+         style="stop-color:#004284;stop-opacity:1;"
+         offset="1"
+         id="stop7911" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient7897">
+      <stop
+         style="stop-color:#70d9ff;stop-opacity:1;"
+         offset="0"
+         id="stop7899" />
+      <stop
+         style="stop-color:#0082ff;stop-opacity:1;"
+         offset="1"
+         id="stop7901" />
+    </linearGradient>
+    <filter
+       inkscape:collect="always"
+       id="filter4495"
+       color-interpolation-filters="sRGB">
+      <feGaussianBlur
+         inkscape:collect="always"
+         stdDeviation="5.1714288"
+         id="feGaussianBlur4497" />
+    </filter>
+    <filter
+       inkscape:collect="always"
+       id="filter4543"
+       x="-0.252"
+       width="1.5039999"
+       y="-0.252"
+       height="1.5039999"
+       color-interpolation-filters="sRGB">
+      <feGaussianBlur
+         inkscape:collect="always"
+         stdDeviation="27.150001"
+         id="feGaussianBlur4545" />
+    </filter>
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="0.7"
+     inkscape:cx="235.89163"
+     inkscape:cy="234.71247"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     inkscape:window-width="1339"
+     inkscape:window-height="768"
+     inkscape:window-x="27"
+     inkscape:window-y="0"
+     inkscape:window-maximized="0"
+     fit-margin-top="0"
+     fit-margin-left="0"
+     fit-margin-right="0"
+     fit-margin-bottom="0" />
+  <metadata
+     id="metadata7378">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(-32.977087,-819.38508)">
+    <path
+       transform="matrix(0.51428233,0,0,0.51428233,-37.838113,759.59021)"
+       d="m 461.42857,310.71429 c 0,71.40254 -57.88319,129.28573 -129.28572,129.28573 -71.40253,0 -129.28572,-57.88319 -129.28572,-129.28573 0,-71.40253 57.88319,-129.28572 129.28572,-129.28572 71.40253,0 129.28572,57.88319 129.28572,129.28572 z"
+       sodipodi:ry="129.28572"
+       sodipodi:rx="129.28572"
+       sodipodi:cy="310.71429"
+       sodipodi:cx="332.14285"
+       id="path4413"
+       style="fill:#ececec;fill-opacity:1;stroke:none;filter:url(#filter4543)"
+       sodipodi:type="arc" />
+  </g>
+</svg>