Changeset 520:3f79a77ef1e3 for nagslang


Ignore:
Timestamp:
Sep 7, 2013, 6:20:25 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Ephemeral messages

Location:
nagslang
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nagslang/events.py

    r440 r520  
    5151    def post(cls, destination, dest_pos):
    5252        super(DoorEvent, cls).post(destination=destination, dest_pos=dest_pos)
     53
     54
     55class AddDrawableEvent(UserEvent):
     56    '''When you are in a corner and can't return a Result'''
     57    @classmethod
     58    def post(cls, drawable):
     59        super(AddDrawableEvent, cls).post(drawable=drawable)
  • nagslang/game_object.py

    r519 r520  
    157157        self.lifetime = 0
    158158        self.physicser = physicser
    159         physicser.set_game_object(self)
    160         self.physicser.add_to_space()
     159        if physicser is not None:
     160            physicser.set_game_object(self)
     161            self.physicser.add_to_space()
    161162        self.renderer = renderer
    162163        renderer.set_game_object(self)
     
    298299        return [("name", "string"), ("position", "coordinates"),
    299300                ("message", "text")]
     301
     302
     303class EphemeralNote(GameObject):
     304    def __init__(self, message, timeout):
     305        super(EphemeralNote, self).__init__(
     306            None,
     307            render.NullRenderer(),
     308            puzzle.YesPuzzler(),
     309            render.TextOverlay(message),
     310        )
     311        self.add_timer('timeout', timeout)
     312        self.start_timer('timeout')
     313
     314    def update(self, dt):
     315        super(EphemeralNote, self).update(dt)
     316        if not self.check_timer('timeout'):
     317            return Result(remove=[self])
    300318
    301319
  • nagslang/protagonist.py

    r440 r520  
    1111    CMD_TOGGLE_FORM, CMD_ACTION)
    1212from nagslang.game_object import (
    13     GameObject, Physicser, Result, Bullet, ClawAttack, make_body)
     13    GameObject, Physicser, Result, Bullet, ClawAttack, EphemeralNote,
     14    make_body)
    1415from nagslang.mutators import FLIP_H
    1516from nagslang.resources import resources
    16 from nagslang.events import DeathEvent
     17from nagslang.events import AddDrawableEvent, DeathEvent
    1718from nagslang.utils import vec_from_angle, vec_with_length
    1819
     
    301302    def shoot(self):
    302303        if not self.has_item('gun'):
     304            AddDrawableEvent.post(EphemeralNote('You are not armed', 1))
    303305            return
    304306        vec = vec_from_angle(self.angle, BULLET_SPEED)
  • nagslang/screens/area.py

    r512 r520  
    1010    COLLISION_TYPE_FURNITURE, COLLISION_TYPE_WEREWOLF_ATTACK,
    1111    CMD_TOGGLE_FORM, CMD_ACTION)
    12 from nagslang.events import ScreenChange, DoorEvent, QuitEvent, DeathEvent
     12from nagslang.events import (
     13    AddDrawableEvent, DeathEvent, DoorEvent, QuitEvent, ScreenChange)
    1314from nagslang.level import Level
    1415from nagslang.screens.base import Screen
     
    204205            self.protagonist.set_position(pos)
    205206            ScreenChange.post(level)
    206 
     207        elif AddDrawableEvent.matches(ev):
     208            self._drawables.add(ev.drawable)
     209            if ev.drawable.overlay:
     210                self._level.overlay_drawables.append(ev.drawable.overlay)
    207211        self.keys.handle_event(ev)
    208212
     
    248252        # Maximum width we allow for overlays
    249253        max_width = min(render_rect.width, self._surface.get_width())
    250         for overlay in self._level.overlay_drawables:
     254        for overlay in reversed(self._level.overlay_drawables):
    251255            if overlay.is_visible():
    252256                overlay.render(surface, render_rect.topleft, max_width)
     257                break
    253258        self.render_health_bar(surface)
    254259
     
    269274            for drawable in result.add:
    270275                self._drawables.add(drawable)
     276                if drawable.overlay:
     277                    self._level.overlay_drawables.add(drawable.overlay)
    271278            for drawable in result.remove:
    272279                self._drawables.remove(drawable)
     280                if drawable.overlay:
     281                    self._level.overlay_drawables.remove(drawable.overlay)
    273282
    274283    def render_health_bar(self, surface, damage_experienced=None):
Note: See TracChangeset for help on using the changeset viewer.