Changeset 261:db7c8e74efb4


Ignore:
Timestamp:
Sep 4, 2013, 10:36:30 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

(really rubbish) bullets

Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • nagslang/constants.py

    r247 r261  
    1616COLLISION_TYPE_ENEMY = 5
    1717COLLISION_TYPE_DOOR = 6
     18COLLISION_TYPE_PROJECTILE = 7
    1819
    1920SWITCH_PUSHERS = [COLLISION_TYPE_PLAYER, COLLISION_TYPE_BOX]
  • nagslang/events.py

    r186 r261  
    4545    def post(cls, destination, dest_pos):
    4646        super(DoorEvent, cls).post(destination=destination, dest_pos=dest_pos)
     47
     48
     49class FireEvent(UserEvent):
     50    @classmethod
     51    def post(cls, source, impulse):
     52        super(FireEvent, cls).post(source=source, impulse=impulse)
  • nagslang/game_object.py

    r256 r261  
    66from nagslang.constants import (
    77    SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW,
    8     ZORDER_FLOOR, COLLISION_TYPE_DOOR)
     8    ZORDER_FLOOR, COLLISION_TYPE_DOOR, COLLISION_TYPE_PROJECTILE)
    99from nagslang.resources import resources
    1010from nagslang.events import DoorEvent
     
    293293        return [("name", "string"), ("end1", "coordinates"),
    294294                ("end2", "coordinates"), ("key_state", "puzzler")]
     295
     296
     297class Bullet(GameObject):
     298    def __init__(self, space, position, impulse):
     299        body = make_body(1, pymunk.inf, position)
     300        self.shape = pymunk.Circle(body, 1)
     301        self.shape.collision_type = COLLISION_TYPE_PROJECTILE
     302        super(Bullet, self).__init__(
     303            SingleShapePhysicser(space, self.shape),
     304            render.ImageRenderer(resources.get_image('objects', 'bullet.png')),
     305        )
     306        self.physicser.apply_impulse(impulse)
  • nagslang/protagonist.py

    r249 r261  
    77    WEREWOLF_SOAK_FACTOR, PROTAGONIST_HEALTH_MIN_LEVEL, \
    88    PROTAGONIST_HEALTH_MAX_LEVEL
     9from nagslang.events import FireEvent
    910from nagslang.game_object import GameObject, Physicser, make_body
    1011from nagslang.mutators import FLIP_H
     
    219220        """Attempt to hurt something.
    220221        """
    221         pass
     222        vec = Vec2d.unit()
     223        vec.angle = self.angle
     224        vec.length = 100
     225        FireEvent.post(self.physicser.position, vec)
     226        print "Biff", self.physicser.position, vec
    222227
    223228    def in_wolf_form(self):
  • nagslang/screens/area.py

    r258 r261  
    77from nagslang.constants import COLLISION_TYPE_PLAYER, CALLBACK_COLLIDERS, \
    88    COLLISION_TYPE_ENEMY
    9 from nagslang.events import ScreenChange, DoorEvent
     9from nagslang.events import ScreenChange, DoorEvent, FireEvent
    1010from nagslang.level import Level
    1111from nagslang.protagonist import Protagonist
    1212from nagslang.screens.base import Screen
     13from nagslang.game_object import Bullet
    1314
    1415
     
    131132                self.protagonist.toggle_form()
    132133                self.world.transformations += 1
     134            if ev.key == pygame.locals.K_SPACE:
     135                self.world.attacks += 1
     136                self.protagonist.attack()
    133137        elif DoorEvent.matches(ev):
    134138            self.protagonist.set_position(ev.dest_pos)
     
    141145            # else we're teleporting within the screen, and just the
    142146            # position change is enough
     147        elif FireEvent.matches(ev):
     148            bullet = Bullet(self.space, ev.source, ev.impulse)
     149            self._drawables.add(bullet)
    143150        self.keys.handle_event(ev)
    144151
  • nagslang/world.py

    r252 r261  
    1515
    1616    def reset(self):
     17        self.attacks = 0
    1718        self.transformations = 0
    1819        self.kills = 0
Note: See TracChangeset for help on using the changeset viewer.