Changeset 378:8069c9be1c3e


Ignore:
Timestamp:
Sep 6, 2013, 9:07:27 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
rebase_source:
0609dd8f064faac1dcda9fcc5212078fe9c3f062
Message:

Create a nagslang.collectable module for collectables

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • data/levels/level1

    r359 r378  
    1919- args:
    2020  - [300, 600]
    21   classname: Gun
     21  classname: collectable.Gun
    2222- args:
    2323  - [300, 500]
  • data/levels/level2

    r369 r378  
    4040  - [400, 200]
    4141  - keycard_red
    42   classname: KeyCard
     42  classname: collectable.KeyCard
    4343  name: keycard_red
    4444lines: []
  • nagslang/game_object.py

    r377 r378  
    487487
    488488
    489 class CollectibleGameObject(GameObject):
    490     zorder = ZORDER_LOW
    491 
    492     def __init__(self, space, name, shape, renderer):
    493         self._name = name
    494         shape.sensor = True
    495         super(CollectibleGameObject, self).__init__(
    496             SingleShapePhysicser(space, shape),
    497             renderer,
    498             interactible=environment.Interactible(
    499                 environment.Action(
    500                     self._collect, environment.HumanFormCondition())),
    501         )
    502 
    503     def _collect(self, protagonist):
    504         protagonist.add_item(self._name)
    505         # TODO: Make this less hacky.
    506         self.physicser.remove_from_space()
    507         self.renderer = render.NullRenderer()
    508 
    509 
    510 class Gun(CollectibleGameObject):
    511     def __init__(self, space, position):
    512         body = make_body(None, None, position)
    513         self.shape = pymunk.Circle(body, 20)
    514         super(Gun, self).__init__(
    515             space, 'gun', self.shape,
    516             render.ImageRenderer(resources.get_image('objects', 'gun.png')),
    517         )
    518 
    519 
    520489class ClawAttack(GameObject):
    521490    def __init__(self, space, pos, vector, damage):
     
    599568    def apply_effect(self, protagonist):
    600569        protagonist.force_wolf_form()
    601 
    602 
    603 class KeyCard(CollectibleGameObject):
    604     def __init__(self, space, position, name):
    605         body = make_body(None, None, position)
    606         self.shape = pymunk.Circle(body, 20)
    607         super(KeyCard, self).__init__(
    608             space, name, self.shape,
    609             render.ImageRenderer(
    610                 resources.get_image('objects', '%s.png' % (name,))),
    611         )
    612 
    613     @classmethod
    614     def requires(cls):
    615         return [("name", "string"), ("position", "coordinates"),
    616                 ("item_name", "string")]
  • nagslang/level.py

    r348 r378  
    22import pygame.locals as pgl
    33
     4from nagslang import collectable
    45from nagslang import game_object as go
    56from nagslang import enemies
     
    8384    def _create_game_object(self, space, classname, args, name=None):
    8485        modules = {
     86            'collectable': collectable,
    8587            'game_object': go,
    8688            'puzzle': puzzle,
Note: See TracChangeset for help on using the changeset viewer.