Changeset 408:d04981e24fda


Ignore:
Timestamp:
Sep 7, 2013, 10:32:40 AM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Move hard-coded starting point to levels meta file

Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/level.py

    r379 r408  
     1import os
     2
    13import pygame
    24import pygame.locals as pgl
     
    6264    @classmethod
    6365    def list_levels(cls):
    64         with resources.get_file('levels', 'LEVELS') as f:
    65             levels = load(f)
    66             return levels['levels']
     66        dir_ = resources.get_resource_path('levels')
     67        for file_ in os.listdir(dir_):
     68            if file_ == 'meta':
     69                continue
     70            yield file_
     71
     72    @classmethod
     73    def game_starting_point(cls):
     74        with resources.get_file('levels', 'meta') as f:
     75            data = load(f)
     76        return (data['starting_level'], data['starting_position'])
    6777
    6878    def load(self, space):
  • nagslang/world.py

    r403 r408  
    1919
    2020    def reset(self):
    21         first_level = Level.list_levels()[0]
    22         starting_position = (350, 300)
    2321        self.__dict__['_data'] = {
    2422            'attacks': 0,
     
    2725            'kills': 0,
    2826            'rooms': 0,
    29             'level': (first_level, starting_position),
     27            'level': Level.game_starting_point(),
    3028            'level_state': {},
    3129            'inventory': set(),
    3230        }
    3331        self.__dict__['protagonist'] = Protagonist(
    34             pymunk.Space(), self, starting_position)
     32            pymunk.Space(), self, self.level[1])
    3533
    3634    def __getattr__(self, name):
Note: See TracChangeset for help on using the changeset viewer.