Changeset 264:afd9256ad682


Ignore:
Timestamp:
04/08/11 12:54:31 (12 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Move between doorways. (Still with hacky collision limiting.)

Files:
12 edited

Legend:

Unmodified
Added
Removed
  • data/game.json

    r244 r264  
    3232        "level4" : "level4",
    3333        "level5" : "level5"
    34     }
     34    },
     35    "player": {"level": "temple", "doorway": "starting"}
    3536}
  • data/levels/level2.json

    r249 r264  
    3131    "enemies": [],
    3232    "sprites": [],
    33     "doorways": [],
    34     "player": {"pos": [6, 2], "direction": "right"}
     33    "doorways": {
     34        "starting": {"type": "StartingDoorway", "pos": [5, 5], "facing": "right"},
     35        "to_temple": {"type": "Doorway", "pos": [29, 2], "facing": "right", "leadsto": "temple.to_level2"}
     36    }
    3537}
  • data/levels/level3.json

    r249 r264  
    2121    "enemies": [],
    2222    "sprites": [],
    23     "doorways": [],
    24     "player": {"pos": [2, 1], "direction": "right"}
     23    "doorways": {
     24        "starting": {"type": "StartingDoorway", "pos": [2, 1], "facing": "right"}
     25    }
    2526}
  • data/levels/level4.json

    r249 r264  
    2222    "enemies": [],
    2323    "sprites": [],
    24     "doorways": [],
    25     "player": {}
     24    "doorways": {
     25        "starting": {"type": "StartingDoorway", "pos": [5, 2], "facing": "right"}
     26    }
    2627}
  • data/levels/level5.json

    r249 r264  
    3030    "enemies": [],
    3131    "sprites": [],
    32     "doorways": [],
    33     "player": {}
     32    "doorways": {
     33        "starting": {"type": "StartingDoorway", "pos": [5, 2], "facing": "right"}
     34    }
    3435}
  • data/levels/temple.json

    r249 r264  
    2929        {"type": "RedOni", "pos": [15, 11], "direction": "right" }
    3030    ],
    31     "doorways": [
    32         {"type": "Doorway", "pos": [17, 16], "leadsto": "level2"}
    33     ],
    34     "player": {"pos": [4, 17], "direction": "right"}
     31    "doorways": {
     32        "starting": {"type": "StartingDoorway", "pos": [4, 17], "facing": "right"},
     33        "to_level2": {"type": "Doorway", "pos": [17, 16], "facing": "left", "leadsto": "level2.to_temple"}
     34    }
    3535}
  • data/levels/temple_grounds.json

    r249 r264  
    2626        {"type": "RedOni", "pos": [26, 11], "direction": "right" }
    2727    ],
    28     "doorways": [],
    29     "player": {"pos": [3, 2], "direction": "right"}
     28    "doorways": {
     29        "starting": {"type": "StartingDoorway", "pos": [3, 2], "facing": "right"}
     30    }
    3031}
  • skaapsteker/engine.py

    r262 r264  
    3939                    next_scene = ev.next_scene
    4040                    if not isinstance(next_scene, Scene):
    41                         next_scene = next_scene[0](self.game_state, *(next_scene[1:]))
     41                        next_scene = next_scene[0](self.game_state, self.soundsystem, *(next_scene[1:]))
    4242                    self.change_scene(next_scene)
    4343                    break
  • skaapsteker/level.py

    r262 r264  
    5454
    5555class Level(object):
    56     def __init__(self, leveldef, player, soundsystem):
     56    def __init__(self, leveldef, soundsystem):
    5757        self.name = leveldef
    5858        self.level_data = json.loads(data.load('levels/' + leveldef + '.json').read())
     
    6363        self.setup_enemies()
    6464        self.setup_doorways()
    65         self.setup_player(player)
    6665        self._background_music = None
    6766        if 'music' in self.level_data:
     
    104103
    105104    def setup_doorways(self):
    106         self.doorways = LayeredUpdates()
    107         for door_def in self.level_data['doorways']:
     105        self.doorways = {}
     106        for door_name, door_def in self.level_data['doorways'].items():
    108107            doorway = find_sprite(door_def, 'base')
     108            self.doorways[door_name] = doorway
    109109            self.sprites.add(doorway)
    110 
    111 
    112     def setup_player(self, player):
    113         player_data = self.level_data['player']
    114         player.set_facing(player_data.pop('direction', 'left'))
    115         player.set_image()
    116         player.set_pos(player_data.pop('pos', (5, 5)))
    117         self.sprites.add(player)
    118110
    119111
  • skaapsteker/levelscene.py

    r263 r264  
    1717class LevelScene(engine.Scene):
    1818
    19     def __init__(self, game_state, soundsystem, leveldef):
     19    def __init__(self, game_state, soundsystem, doorway_def=None):
    2020        super(LevelScene, self).__init__(game_state, soundsystem)
    2121
    22         self._player = player.Player(game_state.world, soundsystem)
    23         self._level = level.Level(leveldef, self._player, soundsystem)
    24         self._leveldef = leveldef
     22        if doorway_def is not None:
     23            player_def = self.game_state.world.player
     24            player_def.level, player_def.doorway = doorway_def.split('.')
     25        self._level = level.Level(self.game_state.world.player.level, soundsystem)
    2526        self._player_dead = False
    2627        self._dialogue = None
     28
     29        self.setup_player()
    2730
    2831        self._level_surface = self._level.get_surface()
     
    3841
    3942        self._build_action_map()
     43
     44
     45    def setup_player(self):
     46        doorway = self._level.doorways[self.game_state.world.player.doorway]
     47        self._player = player.Player(self.game_state.world, self._soundsystem)
     48        self._player.set_facing(doorway.facing)
     49        self._player.set_image()
     50        self._player.set_pos(doorway._starting_tile_pos)
     51
    4052
    4153    def _build_action_map(self):
     
    7991        if self._player_dead:
    8092            self._player.restore()
    81         engine.ChangeScene.post(LevelScene(self.game_state, self._soundsystem, self._leveldef))
     93        engine.ChangeScene.post(LevelScene(self.game_state, self._soundsystem))
    8294
    8395    def _toggle_pause(self):
  • skaapsteker/menuscene.py

    r262 r264  
    1414        self.cur_game = cur_game
    1515        menu_options = [
    16             ('Temple', 'temple'),
    17             ('Level 2', 'level2'),
    18             ('Level 3', 'level3'),
    19             ('Level 4', 'level4'),
    20             ('Level 5', 'level5'),
     16            ('Temple', 'temple.starting'),
     17            ('Level 2', 'level2.starting'),
     18            ('Level 3', 'level3.starting'),
     19            ('Level 4', 'level4.starting'),
     20            ('Level 5', 'level5.starting'),
    2121            ('Starting Cutscene', 'cutscene'),
    2222            ('Quit', 'quit'),
  • skaapsteker/sprites/base.py

    r261 r264  
    2828    def __init__(self, pos, **opts):
    2929        Sprite.__init__(self)
     30        self._starting_tile_pos = pos
     31        self.setup_image_data(pos)
     32        self.setup(**opts)
     33
     34
     35    def setup_image_data(self, pos):
    3036        self.image = data.load_image(self.image_dir + self.image_file)
    3137        self.rect = self.image.get_rect(midbottom=(pos[0]*TILE_SIZE[0]+TILE_SIZE[0]/2, (pos[1]+1)*TILE_SIZE[1]))
    3238        self.collide_rect = self.rect.move(0, 0)
    33         self.setup(**opts)
    3439
    3540
     
    278283    gravitates = False
    279284    collides_with = set([PC_LAYER])
     285    wants_updates = True
    280286
    281287    image_file = 'torii.png'
     
    285291    def __init__(self, pos, **opts):
    286292        GameSprite.__init__(self, pos, **opts)
    287         self._layer = Layers.PLAYER
     293        self._ticks_before_interact = 120
     294
     295
     296    def setup_image_data(self, pos):
     297        super(Doorway, self).setup_image_data(pos)
    288298        self.image = pygame.transform.scale(self.image, self.image.get_rect().center)
    289299        self.rect = self.image.get_rect(midbottom=self.rect.midbottom)
     
    291301
    292302
    293     def setup(self, leadsto):
     303    def setup(self, facing, leadsto):
     304        self.facing = facing
    294305        self.leadsto = leadsto
    295306        print leadsto
     307
     308
     309    def update(self):
     310        super(Doorway, self).update()
     311        if self._ticks_before_interact > 0:
     312            self._ticks_before_interact -= 1
     313
     314
     315    def collided_player(self, player):
     316        if self._ticks_before_interact != 0:
     317            return
     318        self._ticks_before_interact = 120
     319        print "Player touched %s" % self
     320        from .. import engine, levelscene
     321        engine.ChangeScene.post((levelscene.LevelScene, self.leadsto))
     322
     323
     324
     325class StartingDoorway(Doorway):
     326    collides_with = set()
     327
     328    def setup_image_data(self, pos):
     329        self.image = pygame.Surface((0, 0))
     330        self.rect = self.image.get_rect(midbottom=(pos[0]*TILE_SIZE[0]+TILE_SIZE[0]/2, (pos[1]+1)*TILE_SIZE[1]))
     331        self.collide_rect = self.rect.move(0, 0)
     332
     333
     334    def setup(self, facing):
     335        Doorway.setup(self, facing, None)
    296336
    297337
Note: See TracChangeset for help on using the changeset viewer.