Ignore:
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • nagslang/enemies.py

    r235 r229  
    99from nagslang.mutators import FLIP_H
    1010from nagslang.resources import resources
    11 
    12 
    13 def get_editable_enemies():
    14     classes = []
    15     for cls_name, cls in globals().iteritems():
    16         if isinstance(cls, type) and issubclass(cls, Enemy):
    17             if hasattr(cls, 'requires'):
    18                 classes.append((cls_name, cls))
    19     return classes
    2011
    2112
     
    4233    def attack(self):
    4334        raise NotImplementedError
    44 
    45     @classmethod
    46     def requires(cls):
    47         return [("name", "string"), ("position", "coordinates")]
    4835
    4936
     
    126113        self.set_direction(x_step, y_step)
    127114        super(PatrollingAlien, self).animate()
    128 
    129     @classmethod
    130     def requires(cls):
    131         return [("name", "string"), ("position", "coordinates"),
    132                 ("end_position", "coordinates")]
  • nagslang/engine.py

    r238 r180  
    88from nagslang.screens.area import AreaScreen
    99from nagslang.events import ScreenChange
    10 from nagslang.world import World
    1110
    1211
     
    1716        self._fps = constants.FPS
    1817        self._dt = 1. / self._fps
    19         self._world = World()
     18        self._world = None  # TODO: create the world
    2019        self._current_screen = None
    2120        self._screens = {
  • nagslang/game_object.py

    r235 r229  
    99from nagslang.resources import resources
    1010from nagslang.events import DoorEvent
    11 
    12 
    13 def get_editable_game_objects():
    14     classes = []
    15     for cls_name, cls in globals().iteritems():
    16         if isinstance(cls, type) and hasattr(cls, 'requires'):
    17             classes.append((cls_name, cls))
    18     return classes
    1911
    2012
     
    145137        return True
    146138
    147     @classmethod
    148     def requires(cls):
    149         """Hints for the level editor"""
    150         return [("name", "string")]
    151 
    152139
    153140class FloorSwitch(GameObject):
     
    168155        )
    169156
    170     @classmethod
    171     def requires(cls):
    172         return [("name", "string"), ("position", "coordinates")]
    173 
    174157
    175158class Note(GameObject):
     
    186169            render.TextOverlay(message),
    187170        )
    188 
    189     @classmethod
    190     def requires(cls):
    191         return [("name", "string"), ("position", "coordinates"),
    192                 ("message", "text")]
    193171
    194172
     
    209187            puzzle.StateProxyPuzzler(state_source),
    210188        )
    211 
    212     @classmethod
    213     def requires(cls):
    214         return [("name", "string"), ("position", "coordinates"),
    215                 ("state_source", "puzzler")]
    216189
    217190
     
    228201        )
    229202
    230     @classmethod
    231     def requires(cls):
    232         return [("name", "string"), ("position", "coordinates"),
    233                 ("state_source", "puzzler")]
    234 
    235203
    236204class Door(GameObject):
     
    258226        if self.puzzler.get_state():
    259227            DoorEvent.post(self.destination, self.dest_pos)
    260 
    261     @classmethod
    262     def requires(cls):
    263         return [("name", "string"), ("position", "coordinates"),
    264                 ("destination", "level name"), ("dest_pos", "coordinate"),
    265                 ("key_state", "puzzler")]
    266228
    267229
     
    288250            return False
    289251        return True
    290 
    291     @classmethod
    292     def requires(cls):
    293         return [("name", "string"), ("end1", "coordinates"),
    294                 ("end2", "coordinates"), ("key_state", "puzzler")]
  • nagslang/puzzle.py

    r235 r201  
    11from nagslang.constants import COLLISION_TYPE_PLAYER
    2 
    3 
    4 def get_editable_puzzlers():
    5     classes = []
    6     for cls_name, cls in globals().iteritems():
    7         if isinstance(cls, type) and hasattr(cls, 'requires'):
    8             classes.append((cls_name, cls))
    9     return classes
    102
    113
     
    3830        raise NotImplementedError()
    3931
    40     @classmethod
    41     def requires(cls):
    42         """Tell the level editor the arguments we require
    43 
    44            Format is a list of name: type hint tuples"""
    45         return [("name", "string")]
    46 
    4732
    4833class YesPuzzler(Puzzler):
     
    7358        return False
    7459
    75     @classmethod
    76     def requires(cls):
    77         return [("name", "string"), ("collision_types", "list of ints")]
    78 
    7960
    8061class StateProxyPuzzler(Puzzler):
     
    8465    def get_state(self):
    8566        return self.glue.get_state_of(self._state_source)
    86 
    87     @classmethod
    88     def requires(cls):
    89         return [("name", "string"), ("sources", "list of names")]
    9067
    9168
     
    9976                return False
    10077        return True
    101 
    102     @classmethod
    103     def requires(cls):
    104         return [("name", "string"), ("sources", "list of names")]
  • nagslang/screens/area.py

    r244 r243  
    127127            if ev.key == pygame.locals.K_c:
    128128                self.protagonist.toggle_form()
    129                 self.world.transformations += 1
    130129        elif DoorEvent.matches(ev):
    131130            self.protagonist.set_position(ev.dest_pos)
     
    133132                # Go to anther screen
    134133                self._disable_render = True
    135                 self.world.rooms += 1
    136134                ScreenChange.post(ev.destination, self.protagonist)
    137135                return
  • nagslang/screens/menu.py

    r238 r226  
    55from nagslang.screens.base import Screen
    66from nagslang.events import QuitEvent, ScreenChange
    7 from nagslang.widgets.text import TextWidget, MultiLineWidget
     7from nagslang.widgets.text import TextWidget
    88
    99
     
    2424            TextWidget((40, 70), 'Restore saved game'),
    2525            TextWidget((40, 90), 'Quit'),
    26             MultiLineWidget((60, 120), self.world.get_formatted_stats()),
    2726            self.cursor,
    2827        ]
  • nagslang/widgets/text.py

    r237 r196  
     1import pygame
     2
    13from nagslang.constants import FONT, FONT_SIZE
    24from nagslang.widgets.base import Widget
    3 import pygame
    4 
    55from nagslang.utils import convert_colour
    66from nagslang.resources import resources
     
    3232
    3333
    34 class MultiLineWidget(TextWidget):
    35 
    36     def prepare(self):
    37         self.font = resources.get_font(self.fontname, self.fontsize)
    38         surfaces = []
    39         height = 0
    40         width = 0
    41         for line in self.text.split('\n'):
    42             surface = self.font.render(line, True, self.colour)
    43             width = max(width, surface.get_rect().width)
    44             height += surface.get_rect().height
    45             surfaces.append(surface)
    46         self.surface = pygame.surface.Surface((width, height))
    47         self.surface.fill(pygame.Color('white'))
    48         y = 0
    49         for surface in surfaces:
    50             self.surface.blit(surface, (0, y))
    51             y += surface.get_rect().height
    52 
    53 
    5434class LabelWidget(TextWidget):
    5535    def __init__(self, *args, **kwargs):
  • tools/area_editor.py

    r236 r225  
    3232from nagslang.constants import SCREEN
    3333from nagslang.level import Level, POLY_COLORS, LINE_COLOR
    34 from nagslang.enemies import Enemy, get_editable_enemies
    35 from nagslang.game_object import get_editable_game_objects
    36 from nagslang.puzzle import get_editable_puzzlers
     34from nagslang.enemies import Enemy
     35
    3736
    3837# layout constants
     
    379378        row.rect = pygame.rect.Rect(0, 450, 700, 50)
    380379        edit_box.add(row)
    381         edit_box.get_selection = lambda: table.get_selection()
    382380        return edit_box
    383381
     
    385383        edit_box = self._make_edit_dialog(self.level._game_objects)
    386384        res = edit_box.present()
    387         choice = edit_box.get_selection()
    388         if choice is None:
    389             return
    390385        if res == 'OK':
    391386            # Edit object stuff goes here
     
    397392        edit_box = self._make_edit_dialog(self.level._enemies)
    398393        res = edit_box.present()
    399         choice = edit_box.get_selection()
    400         if choice is None:
    401             return
    402394        if res == 'OK':
    403395            # Edit object stuff goes here
    404396            pass
    405397        elif res == 'Delete':
    406             pass
    407 
    408     def _make_choice_dialog(self, classes):
    409         # Dialog to hold the editor
    410         data = []
    411         for cls_name, cls in classes:
    412             data.append({"classname": cls_name, "class": cls})
    413         edit_box = Dialog()
    414         edit_box.rect = pygame.rect.Rect(0, 0, 700, 500)
    415         table = ObjectTable(data)
    416         edit_box.add(table)
    417         buttons = []
    418         for text in ['OK', 'Cancel']:
    419             but = Button(text, action=lambda x=text: edit_box.dismiss(x))
    420             buttons.append(but)
    421         row = Row(buttons)
    422         row.rect = pygame.rect.Rect(0, 450, 700, 50)
    423         edit_box.add(row)
    424         edit_box.get_selection = lambda: table.get_selection()
    425         return edit_box
    426 
    427     def add_game_object(self):
    428         classes = get_editable_game_objects()
    429         choose = self._make_choice_dialog(classes)
    430         res = choose.present()
    431         choice = choose.get_selection()
    432         if res == 'OK' and choice is not None:
    433             pass
    434 
    435     def add_enemy(self):
    436         classes = get_editable_enemies()
    437         choose = self._make_choice_dialog(classes)
    438         res = choose.present()
    439         choice = choose.get_selection()
    440         if res == 'OK' and choice is not None:
    441             pass
    442 
    443     def add_puzzler(self):
    444         classes = get_editable_puzzlers()
    445         choose = self._make_choice_dialog(classes)
    446         res = choose.present()
    447         choice = choose.get_selection()
    448         if res == 'OK' and choice is not None:
    449398            pass
    450399
     
    517466        y += MENU_BUTTON_HEIGHT + MENU_PAD
    518467
     468        save_but = Button('Save Level', action=self.save)
     469        save_but.rect = BUTTON_RECT.copy()
     470        save_but.rect.move_ip(MENU_LEFT, y)
     471        widgets.append(save_but)
     472        y += MENU_BUTTON_HEIGHT + MENU_PAD
     473
    519474        close_poly_but = Button('Close Polygon',
    520475                                action=self.level_widget.close_poly)
     
    543498        y += label.rect.height + MENU_PAD
    544499
    545         y += MENU_PAD
    546500        switch_but = Button('Switch to Objects', action=self.switch_to_objects)
    547501        switch_but.rect = BUTTON_RECT.copy()
     
    550504        y += switch_but.rect.height + MENU_PAD
    551505
    552         save_but = Button('Save Level', action=self.save)
    553         save_but.rect = BUTTON_RECT.copy()
    554         save_but.rect.move_ip(MENU_LEFT, y)
    555         widgets.append(save_but)
    556         y += MENU_BUTTON_HEIGHT + MENU_PAD
    557 
    558         y += MENU_PAD
    559506        quit_but = Button('Quit', action=self.quit)
    560507        quit_but.rect = BUTTON_RECT.copy()
     
    584531        y += MENU_BUTTON_HEIGHT + MENU_PAD
    585532
    586         add_obj_but = Button('Add Game Object',
    587                              action=self.level_widget.add_game_object)
    588         add_obj_but.rect = BUTTON_RECT.copy()
    589         add_obj_but.rect.move_ip(MENU_LEFT, y)
    590         widgets.append(add_obj_but)
    591         y += MENU_BUTTON_HEIGHT + MENU_PAD
    592 
    593         add_puzzle_but = Button('Add Puzzler',
    594                                 action=self.level_widget.add_puzzler)
    595         add_puzzle_but.rect = BUTTON_RECT.copy()
    596         add_puzzle_but.rect.move_ip(MENU_LEFT, y)
    597         widgets.append(add_puzzle_but)
    598         y += MENU_BUTTON_HEIGHT + MENU_PAD
    599 
    600         add_enemy_but = Button('Add Enemy',
    601                                action=self.level_widget.add_enemy)
    602         add_enemy_but.rect = BUTTON_RECT.copy()
    603         add_enemy_but.rect.move_ip(MENU_LEFT, y)
    604         widgets.append(add_enemy_but)
    605         y += MENU_BUTTON_HEIGHT + MENU_PAD
    606 
    607         y += MENU_PAD
     533        save_but = Button('Save Level', action=self.save)
     534        save_but.rect = BUTTON_RECT.copy()
     535        save_but.rect.move_ip(MENU_LEFT, y)
     536        widgets.append(save_but)
     537        y += MENU_BUTTON_HEIGHT + MENU_PAD
     538
    608539        switch_but = Button('Switch to Drawing', action=self.switch_to_draw)
    609540        switch_but.rect = BUTTON_RECT.copy()
     
    612543        y += switch_but.rect.height + MENU_PAD
    613544
    614         save_but = Button('Save Level', action=self.save)
    615         save_but.rect = BUTTON_RECT.copy()
    616         save_but.rect.move_ip(MENU_LEFT, y)
    617         widgets.append(save_but)
    618         y += MENU_BUTTON_HEIGHT + MENU_PAD
    619 
    620         y += MENU_PAD
    621545        quit_but = Button('Quit', action=self.quit)
    622546        quit_but.rect = BUTTON_RECT.copy()
Note: See TracChangeset for help on using the changeset viewer.