Changeset 286:248b8fdb160c


Ignore:
Timestamp:
Sep 5, 2013, 2:43:25 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
rebase_source:
24638f4ac60788aa27152dd10e52f88fc5445860
Message:

Collect gun (which currently looks like a bullet) to shoot.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • data/levels/level1

    r282 r286  
    1717  classname: ToggleSwitch
    1818  name: door_switch
     19- args:
     20  - [300, 600]
     21  classname: Gun
    1922- args:
    2023  - [300, 500]
  • nagslang/game_object.py

    r282 r286  
    335335    def __init__(self, space, position, impulse):
    336336        body = make_body(1, pymunk.inf, position)
    337         self.shape = pymunk.Circle(body, 1)
     337        self.shape = pymunk.Circle(body, 2)
    338338        self.shape.collision_type = COLLISION_TYPE_PROJECTILE
    339339        super(Bullet, self).__init__(
     
    342342        )
    343343        self.physicser.apply_impulse(impulse)
     344
     345
     346class CollectibleGameObject(GameObject):
     347    zorder = ZORDER_LOW
     348
     349    def __init__(self, space, name, shape, renderer):
     350        self._name = name
     351        shape.sensor = True
     352        super(CollectibleGameObject, self).__init__(
     353            SingleShapePhysicser(space, shape),
     354            renderer,
     355            interactible=environment.Interactible(
     356                environment.Action(
     357                    self._collect, environment.HumanFormCondition())),
     358        )
     359
     360    def _collect(self, protagonist):
     361        protagonist.inventory[self._name] = self
     362        # TODO: Make this less hacky.
     363        self.physicser.remove_from_space()
     364        self.renderer = render.NullRenderer()
     365
     366
     367class Gun(CollectibleGameObject):
     368    def __init__(self, space, position):
     369        body = make_body(None, None, position)
     370        self.shape = pymunk.Circle(body, 20)
     371        super(Gun, self).__init__(
     372            space, 'gun', self.shape,
     373            render.ImageRenderer(resources.get_image('objects', 'bullet.png')),
     374        )
  • nagslang/protagonist.py

    r285 r286  
    254254            pass
    255255        else:
    256             vec = Vec2d.unit()
    257             vec.angle = self.angle
    258             vec.length = 100
    259             FireEvent.post(self.physicser.position, vec)
    260             print "Biff", self.physicser.position, vec
     256            self.shoot()
     257
     258    def shoot(self):
     259        if not self.has_item('gun'):
     260            return
     261        vec = Vec2d.unit()
     262        vec.angle = self.angle
     263        vec.length = 100
     264        FireEvent.post(self.physicser.position, vec)
     265        print "Biff", self.physicser.position, vec
    261266
    262267    def in_wolf_form(self):
  • nagslang/render.py

    r230 r286  
    3636    def animate(self):
    3737        # Used by time animatations to advance the clock
     38        pass
     39
     40
     41class NullRenderer(Renderer):
     42    def render(self, surface):
    3843        pass
    3944
Note: See TracChangeset for help on using the changeset viewer.