Ignore:
Timestamp:
09/03/13 19:47:24 (8 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Phase:
public
Message:

Overlay notes

File:
1 edited

Legend:

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