Changeset 191:e080fcd07fa9


Ignore:
Timestamp:
Sep 3, 2013, 7:47:24 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Overlay notes

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • data/levels/level1

    r189 r191  
    4747  classname: FloorLight
    4848  name: door_light
     49- args:
     50  - [290, 160]
     51  - Run around, press some buttons, have fun!
     52  classname: Note
    4953polygons:
    5054  1:
  • nagslang/game_object.py

    r188 r191  
    1111from nagslang.resources import resources
    1212from nagslang.events import DoorEvent
     13from nagslang.widgets.text import TextWidget
    1314
    1415
     
    321322
    322323
     324class Overlay(object):
     325    def set_game_object(self, game_object):
     326        self.game_object = game_object
     327
     328    def render(self, surface):
     329        pass
     330
     331    def is_visible(self):
     332        return self.game_object.puzzler.get_state()
     333
     334
     335class TextOverlay(Overlay):
     336    def __init__(self, text):
     337        self.text = text
     338        self.widget = TextWidget((20, 20), self.text)
     339
     340    def render(self, surface):
     341        self.widget.draw(surface)
     342
     343
    323344class GameObject(object):
    324345    """A representation of a thing in the game world.
     
    329350    zorder = ZORDER_LOW
    330351
    331     def __init__(self, physicser, renderer, puzzler=None):
     352    def __init__(self, physicser, renderer, puzzler=None, overlay=None):
    332353        self.physicser = physicser
    333354        physicser.set_game_object(self)
     
    338359        if puzzler is not None:
    339360            puzzler.set_game_object(self)
     361        self.overlay = overlay
     362        if overlay is not None:
     363            self.overlay.set_game_object(self)
    340364
    341365    def get_space(self):
     
    381405            }),
    382406            CollidePuzzler(*SWITCH_PUSHERS),
     407        )
     408
     409
     410class Note(GameObject):
     411    zorder = ZORDER_FLOOR
     412
     413    def __init__(self, space, position, message):
     414        body = make_body(None, None, position)
     415        self.shape = pymunk.Circle(body, 30)
     416        self.shape.sensor = True
     417        super(Note, self).__init__(
     418            SingleShapePhysicser(space, self.shape),
     419            ImageRenderer(resources.get_image('objects', 'note.png')),
     420            CollidePuzzler(),
     421            TextOverlay(message),
    383422        )
    384423
  • nagslang/level.py

    r168 r191  
    3030        self._exterior = False
    3131        self._glue = go.PuzzleGlue()
    32         self._drawables = []
     32        self.drawables = []
     33        self.overlay_drawables = []
    3334        self._game_objects = []
    3435        self._enemies = []
     
    7273        elif issubclass(cls, go.GameObject):
    7374            gobj = cls(space, *args)
    74             self._drawables.append(gobj)
     75            self.drawables.append(gobj)
     76            if gobj.overlay:
     77                self.overlay_drawables.append(gobj.overlay)
    7578        else:
    7679            raise TypeError(
     
    8487        if issubclass(cls, go.GameObject):
    8588            gobj = cls(space, *args)
    86             self._drawables.append(gobj)
     89            self.drawables.append(gobj)
    8790        else:
    8891            raise TypeError(
     
    130133    def get_walls(self):
    131134        return self.polygons.values()
    132 
    133     def get_drawables(self):
    134         return self._drawables
    135135
    136136    def _draw_walls(self):
  • nagslang/screens/area.py

    r190 r191  
    111111
    112112    def add_game_objects(self):
    113         for drawable in self._level.get_drawables():
     113        for drawable in self._level.drawables:
    114114            self._drawables.add(drawable)
    115115
     
    169169        render_rect = self._calc_viewport(mysurface, surface)
    170170        surface.blit(mysurface, (0, 0), render_rect)
     171        for overlay in self._level.overlay_drawables:
     172            if overlay.is_visible():
     173                overlay.render(surface)
    171174
    172175    def tick_protagonist(self):
Note: See TracChangeset for help on using the changeset viewer.