Changeset 127:e1dd3b785269


Ignore:
Timestamp:
Apr 4, 2011, 10:03:33 PM (9 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Message:

Initial game state stuff.

Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • data/levels/level1.json

    r107 r127  
    2424        {"type": "Dummy", "pos": [5, 5], "direction": "right" }
    2525    ],
    26     "sprites": [
    27         {"type": "enemies.Dummy", "pos": [2, 2], "direction": "left" }
    28     ],
    29     "player": {"pos": [3, 3], "direction": "left"}
     26    "player": {"pos": [3, 3], "direction": "right"}
    3027}
  • skaapsteker/__main__.py

    r106 r127  
    5858    engine = Engine()
    5959    if level is not None:
    60         engine.change_scene(LevelScene(level))
     60        engine.change_scene(LevelScene(engine.game_state, level))
    6161    else:
    62         engine.change_scene(MenuScene())
     62        engine.change_scene(MenuScene(engine.game_state))
    6363    try:
    6464        engine.run()
  • skaapsteker/engine.py

    r126 r127  
    55import pygame.event
    66from pygame.locals import QUIT, USEREVENT
     7
     8from skaapsteker.gamestate import GameState
    79
    810class Engine(object):
     
    1315        self._fpss = [self._framerate] * 100
    1416        self._cur_frame = 0
     17        self.game_state = GameState()
    1518
    1619    def change_scene(self, next_scene):
     
    4548class Scene(object):
    4649
    47     def __init__(self):
     50    def __init__(self, game_state):
    4851        self.widgets = []
     52        self._game_state = game_state
    4953
    5054    def post(self, ev):
  • skaapsteker/level.py

    r119 r127  
    5757class Level(object):
    5858    def __init__(self, leveldef, player):
     59        self.name = leveldef
    5960        self.level_data = json.loads(data.load('levels/' + leveldef + '.json').read())
    6061        self.sprites = LayeredUpdates()
     
    8889        self.enemies = LayeredUpdates()
    8990        for enemy_def in self.level_data['enemies']:
    90             enemy = enemies.get_enemy(enemy_def)
     91            enemy = find_sprite(enemy_def, 'enemies')
    9192            self.enemies.add(enemy)
    9293            self.sprites.add(enemy)
     94
    9395
    9496    def setup_player(self, player):
     
    98100        player.set_pos(player_data.pop('pos', (5, 5)))
    99101        self.sprites.add(player)
    100 
    101     # def setup_sprites(self):
    102     #     self.sprites = []
    103     #     for sprite_desc in self.level_data['sprites']:
    104     #         self.sprites.append(find_sprite(sprite_desc))
    105     #     print self.sprites
    106102
    107103
  • skaapsteker/levelscene.py

    r124 r127  
    1414class LevelScene(engine.Scene):
    1515
    16     def __init__(self, leveldef, player=None):
     16    def __init__(self, game_state, leveldef, player=None):
     17        super(LevelScene, self).__init__(game_state)
    1718        if not player:
    1819            self._player = sprites.player.Player()
     
    2930            self._world.add(sprite)
    3031        for sprite in self._level.tiles:
     32            self._world.add(sprite)
     33        for sprite in self._game_state.levels[self._level.name]:
    3134            self._world.add(sprite)
    3235
  • skaapsteker/menuscene.py

    r125 r127  
    77
    88class MenuScene(Scene):
    9     def __init__(self, cur_game=None):
    10         super(MenuScene, self).__init__()
     9    def __init__(self, game_state, cur_game=None):
     10        super(MenuScene, self).__init__(game_state)
    1111        self.widgets.append(Text("MENU:", (50, 50), color='white', size=48))
    1212        self.cur_game = cur_game
     
    2828        "Callback from menu TextChoice"
    2929        if data.startswith('level'):
    30             ChangeScene.post(LevelScene(data))
     30            ChangeScene.post(LevelScene(self._game_state, data))
    3131        elif data == 'quit':
    3232            pygame.event.post(pygame.event.Event(QUIT))
  • skaapsteker/sprites/base.py

    r122 r127  
    4949    gravitates = False
    5050
     51    image_file = None
     52    collision_layer = MONSTER_LAYER
     53    collides_with = set([PC_LAYER])
     54
     55    debug_color = (240, 0, 240)
     56
     57    def __init__(self, pos, **opts):
     58        Sprite.__init__(self)
     59        self.image = data.load_image('sprites/' + self.image_file)
     60        self.starting_tile_pos = pos
     61        self.rect = self.image.get_rect(topleft=(pos[0]*TILE_SIZE[0], pos[1]*TILE_SIZE[1]))
     62        self._layer = Layers.PLAYER
     63        self.setup(**opts)
     64
     65
     66    def setup(self):
     67        pass
     68
    5169
    5270class Geography(Sprite):
     
    7189
    7290
    73 def find_sprite(descr):
     91def find_sprite(descr, mod_name=None):
    7492    """Create a sprite object from a dictionary describing it."""
    7593    descr = descr.copy()
    76     stype = descr.pop("type")
    77     mod_name, cls_name = stype.rsplit(".", 1)
     94    cls_name = descr.pop("type")
     95    if mod_name is None:
     96        mod_name, cls_name = cls_name.rsplit(".", 1)
    7897    mod_name = ".".join(["skaapsteker.sprites", mod_name])
    7998    mod =  __import__(mod_name, fromlist=[cls_name])
  • skaapsteker/sprites/enemies.py

    r59 r127  
    11from base import Monster
    2 
    3 def get_enemy(enemydef):
    4     enemydef = enemydef.copy()
    5     monster_class = enemydef.pop('type')
    6     pos = enemydef.pop('pos')
    7     return globals()[monster_class](pos, **enemydef)
    82
    93
     
    126
    137    def setup(self, direction):
    14         print "Dummy monster at %r, facing %s on layer %s" % (self.starting_tile_pos, direction, self._layer)
     8        self.facing = direction
    159
    1610
    17 
Note: See TracChangeset for help on using the changeset viewer.