Changeset 437:d087dfb10896


Ignore:
Timestamp:
Sep 7, 2013, 12:26:28 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Replace menu and death screen with the starting level

Files:
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • data/levels/start

    r410 r437  
    1010  - [300, 300]
    1111  - 180
    12   classname: Door
     12  classname: ContinueGameDoor
    1313- args:
    1414  - [300, 125]
    15   - '"Assessment authorisation for Pandora Station, pursuant to the ongoing claims investigation" -- just another day at the office.'
     15  - "Assessment authorisation for Pandora Station, pursuant to the ongoing claims investigation" -- just another day at the office.
    1616  classname: Note
    1717- args:
     
    1919  - 'Note to self: Practice using tools and weapons during "that time of the month". We don''t want a repeat of last time. Or the time before.'
    2020  classname: Note
     21- args:
     22  - [550, 475]
     23  - Go through this door to restart the game
     24  classname: Note
     25  name: note_restart
     26- args:
     27  - [550, 550]
     28  - level1
     29  - [300, 300]
     30  - 90
     31  classname: RestartGameDoor
     32- args:
     33  - [650, 300]
     34  - Go through this door to continue the game
     35  classname: Note
     36  name: note_continue
    2137lines: []
    2238polygons:
  • nagslang/engine.py

    r399 r437  
    55
    66from nagslang import constants
    7 from nagslang.screens.menu import MenuScreen
    87from nagslang.screens.area import AreaScreen
    9 from nagslang.screens.playerdied import PlayerDiedScreen
    108from nagslang.events import ScreenChange
    119from nagslang.world import World
     10from nagslang.level import Level
    1211
    1312
     
    2019        self._world = World()
    2120        self._current_screen = None
    22         self._screens = {
    23             'menu': MenuScreen,
    24             'dead': PlayerDiedScreen,
    25         }
     21
     22        self._screens = {}
    2623        for area_name in AreaScreen.list_areas():
    2724            self._screens[area_name] = AreaScreen
     25        starting_area = Level.game_starting_point()[0]
     26
    2827        self._world.load()
    29         self.change_screen('menu')
     28        self.change_screen(starting_area)
    3029        # Dummy resize event, to force us to realise our real size
    3130        # http://stackoverflow.com/q/16442573/8629
  • nagslang/game_object.py

    r429 r437  
    371371
    372372
     373class RestartGameDoor(Door):
     374    def _post_door_event(self, protagonist):
     375        protagonist.world.reset()
     376        super(RestartGameDoor, self)._post_door_event(protagonist)
     377
     378
     379class ContinueGameDoor(Door):
     380    def _post_door_event(self, protagonist):
     381        world = protagonist.world
     382        DoorEvent.post(world.level[0], world.level[1])
     383
     384
    373385class PuzzleDoor(BaseDoor):
    374386    def __init__(self, space, position, destination, dest_pos, angle,
  • nagslang/level.py

    r433 r437  
    2828
    2929class Level(object):
     30    _game_starting_point = None
    3031
    3132    def __init__(self, name, world):
     
    7576    @classmethod
    7677    def game_starting_point(cls):
    77         with resources.get_file('levels', 'meta') as f:
    78             data = load(f)
    79         return (data['starting_level'], data['starting_position'])
     78        if not cls._game_starting_point:
     79            with resources.get_file('levels', 'meta') as f:
     80                data = load(f)
     81            cls._game_starting_point = (data['starting_level'],
     82                                        tuple(data['starting_position']))
     83        return cls._game_starting_point
     84
     85    def is_starting_level(self):
     86        return self.name == self.game_starting_point()[0]
    8087
    8188    def load(self, space):
  • nagslang/protagonist.py

    r416 r437  
    1212from nagslang.game_object import (
    1313    GameObject, Physicser, Result, Bullet, ClawAttack, make_body)
     14from nagslang.level import Level
    1415from nagslang.mutators import FLIP_H
    1516from nagslang.resources import resources
     
    341342        self.world.load()
    342343        self.world.deaths += 1
    343         ScreenChange.post('dead')
     344        level, pos = Level.game_starting_point()
     345        self.set_position(pos)
     346        ScreenChange.post(level)
    344347
    345348    def lose_health(self, amount):
  • nagslang/screens/area.py

    r406 r437  
    99    COLLISION_TYPE_FURNITURE, COLLISION_TYPE_WEREWOLF_ATTACK,
    1010    CMD_TOGGLE_FORM, CMD_ACTION)
    11 from nagslang.events import ScreenChange, DoorEvent
     11from nagslang.events import ScreenChange, DoorEvent, QuitEvent
    1212from nagslang.level import Level
    1313from nagslang.screens.base import Screen
     
    8585        self._level = Level(self.name, self.world)
    8686        self._level.load(self.space)
     87        self.game_starting_point = Level.game_starting_point()
    8788        self._drawables = Drawables()
    8889        self.add_walls()
     
    162163        if ev.type == pygame.locals.KEYDOWN:
    163164            if ev.key == pygame.locals.K_ESCAPE:
    164                 ScreenChange.post('menu')
     165                if self._level.is_starting_level():
     166                    QuitEvent.post()
     167                    return
     168                room, pos = self.game_starting_point
     169                self.world.load()
     170                self.world.deaths += 1
     171                ScreenChange.post(room)
     172                self.protagonist.set_position(pos)
     173                self._disable_render = True
     174                return
    165175            cmd_key = self.keys.get_command_key(ev.key)
    166176            if cmd_key is not None:
  • nagslang/world.py

    r408 r437  
    6969            data = load(f)
    7070        data['inventory'] = set(data['inventory'])
     71        data['level'] = (data['level'][0], tuple(data['level'][1]))
    7172        self.__dict__['_data'].update(data)
    7273        return True
Note: See TracChangeset for help on using the changeset viewer.