Ignore:
Timestamp:
09/05/13 14:43:25 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Rebase:
32343633386634616336303738386161323731353264643130653532663838666335343435383630
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        )
Note: See TracChangeset for help on using the changeset viewer.