all repos — Legends-RPG @ 9c199248033bcdb14712e2705aa0b8b200e044c0

A fantasy mini-RPG built with Python and Pygame.

Added portals at every door to reset the level state. In the future will allow the character to to leave the town, enter the castle, shops, etc.
Justin Armstrong justinmeister@gmail.com
Mon, 17 Mar 2014 10:25:31 -0700
commit

9c199248033bcdb14712e2705aa0b8b200e044c0

parent

cec3b2e4079061cbf05e7418b69b276ba06fe6f4

4 files changed, 93 insertions(+), 1 deletions(-)

jump to
A data/components/portal.py

@@ -0,0 +1,13 @@

+__author__ = 'justinarmstrong' +import pygame as pg +from .. import constants as c + + +class Portal(pg.sprite.Sprite): + """Used to change level state""" + def __init__(self, x, y, name): + super(Portal, self).__init__() + self.image = pg.Surface((32, 32)) + self.image.fill(c.BLACK) + self.rect = pg.Rect(x*32, y*32, 32, 32) + self.name = name
A data/states/level_change_map.txt

@@ -0,0 +1,51 @@

+0000000000000000000000000 +0000000000000000000000000 +00V000000000000000000V000 +00V000011111111110000V000 +00V000011111111110000V000 +00V000011111111110000V000 +00V00001111AA11110000V000 +00V000000000000000000V000 +00V000000000000000000V000 +0000000000000000000000000 +0000000000000000000000000 +00000000000BB000000000000 +MMMMMMMMMMMBBMMMMMMMMMMMM +0000000000000000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0333033300011000033303330 +0333033300011000033303330 +0222022200011000022202220 +02A202A20001100002A202A20 +0010001000011000001000100 +0011111111111111111111100 +0000000000011000000000000 +0000000000011000000000000 +00000000001GG100000000000 +0000000001GGGG10000000000 +00000000001GG100000000000 +0000000000011000000000000 +0000000000011000000000000 +MMMMMMMMMMM11MMMMMMMMMMMM +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000000000 +0000000000011000000333000 +0003330000011000000333000 +0003330000011000000222000 +00022200000110000002A2000 +0002A20000011000000010000 +0000100000011000000010000 +0000111111111111111110000 +0000000000011000000000000 +0000000W00011000000000000 +0000000000011000000000000 +0000000000011000000000000 +00000000000P1000000000000 +000000AAAAAAAAAAAAA000000
M data/states/town.pydata/states/town.py

@@ -4,6 +4,7 @@ import pygame as pg

from .. import tools, collision from .. import tilemap as tm from .. components import person, textbox +from .. import constants as c

@@ -34,6 +35,7 @@ self.dialogue_handler = textbox.DialogueHandler(self.player,

self.town_sprites, self) self.state_dict = self.make_state_dict() + self.portals = tm.make_level_portals() def set_sprite_dialogue(self):

@@ -70,6 +72,7 @@

def running_normally(self, surface, keys, current_time): """Update level normally""" self.check_for_dialogue() + self.check_for_portals() self.player.update(keys, current_time) self.town_sprites.update(current_time) self.collision_handler.update(keys, current_time)

@@ -77,6 +80,16 @@ self.dialogue_handler.update(keys, current_time)

self.viewport_update() self.draw_level(surface) + + + def check_for_portals(self): + """Check if the player walks into a door, requiring a level change""" + portal = pg.sprite.spritecollideany(self.player, self.portals) + + if portal and self.player.state == 'resting': + #self.next = portal.name + self.next = c.TOWN + self.done = True def handling_dialogue(self, surface, keys, current_time):
M data/tilemap.pydata/tilemap.py

@@ -3,7 +3,8 @@

import os import pygame as pg import tools, setup -from components import person +from components import person, portal +import constants as c def create_town_sprite_sheet_dict():

@@ -318,6 +319,20 @@ soldier = person.Soldier(column*32, row*32)

level_sprites.add(soldier) tile_map.close() + + +def make_level_portals(): + """Create portals to different levels on doors""" + tile_map = open(os.path.join('data', 'states', 'level_change_map.txt'), 'r') + portal_group = pg.sprite.Group() + + for row, line in enumerate(tile_map): + for column, letter in enumerate(line): + if letter == 'A': + portal_group.add(portal.Portal(column, row, c.MAIN_MENU)) + + return portal_group + get_image = tools.get_image