Changeset 222:cc5f2a5ac501


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

Overlays belong in render

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r218 r222  
    99from nagslang.resources import resources
    1010from nagslang.events import DoorEvent
    11 from nagslang.widgets.text import LabelWidget
    1211
    1312
     
    8382        body.velocity_func = damping_velocity_func
    8483    return body
    85 
    86 
    87 class Overlay(object):
    88     def set_game_object(self, game_object):
    89         self.game_object = game_object
    90 
    91     def render(self, surface, display_offset):
    92         pass
    93 
    94     def is_visible(self):
    95         return self.game_object.puzzler.get_state()
    96 
    97 
    98 class TextOverlay(Overlay):
    99     def __init__(self, text):
    100         self.text = text
    101         self.widget = LabelWidget((20, 20), self.text)
    102 
    103     def render(self, surface, display_offset):
    104         x, y = 20, 20
    105         if display_offset[0] < 0:
    106             x += abs(display_offset[0])
    107         if display_offset[1] < 0:
    108             y += abs(display_offset[1])
    109         self.widget.rect.topleft = (x, y)
    110         self.widget.draw(surface)
    11184
    11285
     
    189162            render.ImageRenderer(resources.get_image('objects', 'note.png')),
    190163            puzzle.CollidePuzzler(),
    191             TextOverlay(message),
     164            render.TextOverlay(message),
    192165        )
    193166
  • nagslang/render.py

    r221 r222  
    55
    66from nagslang.options import options
     7from nagslang.widgets.text import LabelWidget
    78
    89
     
    171172        self.game_object.get_shape().color = color
    172173        super(ShapeStateRenderer, self).render(surface)
     174
     175
     176class Overlay(object):
     177    def set_game_object(self, game_object):
     178        self.game_object = game_object
     179
     180    def render(self, surface, display_offset):
     181        pass
     182
     183    def is_visible(self):
     184        return self.game_object.puzzler.get_state()
     185
     186
     187class TextOverlay(Overlay):
     188    def __init__(self, text):
     189        self.text = text
     190        self.widget = LabelWidget((20, 20), self.text)
     191
     192    def render(self, surface, display_offset):
     193        x, y = 20, 20
     194        if display_offset[0] < 0:
     195            x += abs(display_offset[0])
     196        if display_offset[1] < 0:
     197            y += abs(display_offset[1])
     198        self.widget.rect.topleft = (x, y)
     199        self.widget.draw(surface)
Note: See TracChangeset for help on using the changeset viewer.