all repos — Legends-RPG @ 1468db2538cd810757a76ae20fce0a306f457744

A fantasy mini-RPG built with Python and Pygame.

Began making overworld
Justin Armstrong justinmeister@gmail.com
Sat, 05 Apr 2014 21:31:14 -0700
commit

1468db2538cd810757a76ae20fce0a306f457744

parent

cb2c441948d0a97c4525338090a60b636f5b8c09

M data/components/textbox.pydata/components/textbox.py

@@ -47,21 +47,17 @@ image.blit(dialogue_image, dialogue_rect)

return image - - def update(self, keys, current_time): """Updates scrolling text""" self.current_time = current_time self.draw_box(current_time) self.terminate_check(keys) - def draw_box(self, current_time, x=400): """Reveal dialogue on textbox""" self.image = self.make_dialogue_box_image() self.check_to_draw_arrow() - def terminate_check(self, keys): """Remove textbox from sprite group after 2 seconds""" if keys[pg.K_SPACE] and self.allow_input:

@@ -69,7 +65,6 @@ self.done = True

if not keys[pg.K_SPACE]: self.allow_input = True - def check_to_draw_arrow(self): """Blink arrow if more text needs to be read"""

@@ -83,7 +78,6 @@ class ItemBox(DialogueBox):

"""Text box for information like obtaining new items""" def __init__(self, dialogue, item=None): super(ItemBox, self).__init__(None, 0, 'infobox', item) - def make_dialogue_box_image(self): """Make the image of the dialogue box"""
M data/constants.pydata/constants.py

@@ -13,6 +13,7 @@ ARMOR_SHOP = 'armor shop'

WEAPON_SHOP = 'weapon shop' MAGIC_SHOP = 'magic shop' HOUSE = 'house' +OVERWORLD = 'overworld' ##Colors
M data/main.pydata/main.py

@@ -3,7 +3,7 @@ from data.states.town import town

from data.states.castle import castle from data.states import shop from data.states.house import house -from data.states import player_menu +from data.states.overworld import overworld from . import setup, tools from . import constants as c

@@ -18,6 +18,7 @@ WEAPON_SHOP = 'weapon shop'

MAGIC_SHOP = 'magic shop' POTION_SHOP = 'potion shop' PLAYER_MENU = 'player menu' +OVERWORLD = 'overworld' def main():

@@ -31,7 +32,8 @@ INN: shop.Inn(),

ARMOR_SHOP: shop.ArmorShop(), WEAPON_SHOP: shop.WeaponShop(), MAGIC_SHOP: shop.MagicShop(), - POTION_SHOP: shop.PotionShop() + POTION_SHOP: shop.PotionShop(), + OVERWORLD: overworld.Overworld() } run_it.setup_states(state_dict, c.MAIN_MENU)
M data/states/level_state.pydata/states/level_state.py

@@ -21,8 +21,6 @@ self.name = None

self.map_width = None self.map_height = None - - def startup(self, current_time, game_data): """Called when the State object is created""" self.game_data = game_data

@@ -57,7 +55,7 @@

def set_sprite_dialogue(self): """Sets unique dialogue for each sprite""" - raise NotImplementedError + pass def make_state_dict(self):

@@ -152,18 +150,15 @@ """Check if the level needs to freeze"""

if self.dialogue_handler.textbox: self.state = 'dialogue' - def update(self, surface, keys, current_time): """Updates state""" state_function = self.state_dict[self.state] state_function(surface, keys, current_time) - def viewport_update(self): """Viewport stays centered on character, unless at edge of map""" self.viewport.center = self.player.rect.center self.viewport.clamp_ip(self.level_rect) - def draw_level(self, surface): """Blits all images to screen"""
A data/states/overworld/__init__.py

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

+__author__ = 'justin'
A data/states/overworld/blockers.txt

@@ -0,0 +1,29 @@

+0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +000000000000000000B000000 +00000B00000BBB0000B000000 +00000B0000BBBB0000B000000 +00000B0000BBBB0000B000000 +00000B0000B00B0000B000000 +00000B000000000000B000000 +00000B000000000000B000000 +000000BBBBBBBBBBBB0000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000
A data/states/overworld/layer1.txt

@@ -0,0 +1,29 @@

+MMMMMMMMMMMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMMMMMMMMMM +MMMMMM9ab9ab9ab9abMMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM700000000004MMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM700000000004MMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM700000000004MMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM700000000004MMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM700000000004MMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM700000000004MMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM700000000004MMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM700000000004MMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM700000000004MMMMMMM +MMMMMM60000000000ZMMMMMMM +MMMMMM7NYLNYLNYLN4MMMMMMM +MMMMMMMMMMMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMMMMMMMMMM
A data/states/overworld/layer1extra.txt

@@ -0,0 +1,29 @@

+0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000P00000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000
A data/states/overworld/layer2.txt

@@ -0,0 +1,29 @@

+0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000
A data/states/overworld/layer3.txt

@@ -0,0 +1,50 @@

+0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000
A data/states/overworld/overworld.py

@@ -0,0 +1,17 @@

+"""This is overworld state. Most of its functionality is inherited from +the level_state.py module. Most of the level data is contained in +the tilemap.txt files in this state's directory. +""" + +from .. import level_state +from ... import constants as c + +class Overworld(level_state.LevelState): + def __init__(self): + super(Overworld, self).__init__() + self.name = c.OVERWORLD + self.map_width = 25 + self.map_height = 29 + + +
A data/states/overworld/portals.txt

@@ -0,0 +1,29 @@

+0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +00000000000BB000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000
A data/states/overworld/sprite_start_pos.txt

@@ -0,0 +1,50 @@

+0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000000000000000000 +0000000000010000000000000
M data/states/town/blockers.txtdata/states/town/blockers.txt

@@ -48,4 +48,4 @@ B0B0B00000011000000BB0T0T

B0BBB0B000011000B0B0BT0T0 0T0B0BBB00011000BBBB00T00 00000B0B000110000B0B00000 -00000000BBBBBBBBBBB000000+0000000000000000000000000
M data/states/town/portals.txtdata/states/town/portals.txt

@@ -48,4 +48,4 @@ 0000000W00011000000000000

0000000000011000000000000 0000000000011000000000000 00000000000P1000000000000 -000000AAAAAAAAAAAAA000000+000000JJJJJJJJJJJJJ000000
M data/tilemap.pydata/tilemap.py

@@ -17,6 +17,7 @@ shopsigns = setup.GFX['shopsigns']

castle_door = setup.GFX['castledoor'] medieval_signs = setup.GFX['medievalsigns'] house = setup.GFX['house'] + houseoverworld = setup.GFX['houseoverworld'] tile_dict['pavement'] = get_tile(32, 48, tileset2) tile_dict['house wall'] = get_tile(64, 48, tileset2)

@@ -65,6 +66,60 @@ tile_dict['chair'] = get_tile(323, 256, house, 32, 32)

tile_dict['table'] = get_tile(82, 161, tileset3, 46, 32) tile_dict['fancy carpet'] = get_tile(112, 96, tileset3, 64, 64) tile_dict['column'] = get_tile(64, 96, tileset3, 16, 48) + tile_dict['bottomwater1'] = get_tile(16, 32, tileset2) + tile_dict['bottomwater2'] = get_tile(32, 32, tileset2) + tile_dict['bottomwater3'] = get_tile(48, 32, tileset2) + tile_dict['topwater1'] = get_tile(16, 0, tileset2) + tile_dict['topwater2'] = get_tile(32, 0, tileset2) + tile_dict['topwater3'] = get_tile(48, 0, tileset2) + tile_dict['leftwater1'] = get_tile(80, 0, tileset2) + tile_dict['leftwater2'] = get_tile(80, 16, tileset2) + tile_dict['leftwater3'] = get_tile(0, 16, tileset2) + tile_dict['rightwater1'] = get_tile(144, 0, tileset2) + tile_dict['rightwater2'] = get_tile(144, 16, tileset2) + tile_dict['rightwater3'] = get_tile(64, 16, tileset2) + tile_dict['houseoverworld'] = get_tile(0, 0, houseoverworld, 128, 128) + + return tile_dict + +def create_layer1_tile_code_dict(): + """Creates a dictionary of codes to tiles for layer 1""" + tile_dict = {'1': 'pavement', + '2': 'house wall', + '3': 'house roof', + 'T': 'tree', + 'W': 'well', + 'M': 'moat', + 'G': 'grass', + 'B': 'castle bridge', + 'V': 'left vert castle wall', + 'C': 'horiz castle wall', + 'X': 'right vert castle wall', + 'S': 'castle side', + 'Q': 'carpet topleft', + 'E': 'carpet topright', + 'J': 'carpet top', + 'R': 'carpet bottomleft', + 'U': 'carpet bottomright', + 'D': 'carpet bottom', + 'P': 'carpet left', + 'A': 'carpet right', + 'F': 'carpet center', + 'H': 'marble floor', + 'K': 'black tile', + 'L': 'topwater1', + 'N': 'topwater2', + 'Y': 'topwater3', + 'Z': 'leftwater1', + '4': 'leftwater2', + '5': 'leftwater3', + '6': 'rightwater1', + '7': 'rightwater2', + '8': 'rightwater3', + '9': 'bottomwater1', + 'a': 'bottomwater2', + 'b': 'bottomwater3' + } return tile_dict

@@ -97,7 +152,7 @@ """Creates the background surface that the rest of

the town map will be blitted on""" size = (width*16, height*16) surface = pg.Surface(size) - if state_name == c.TOWN: + if state_name == c.TOWN or state_name == c.OVERWORLD: tile = get_image(0, 0, 16, 16, setup.GFX['tileset2']) else: tile = pg.Surface((16, 16))

@@ -123,98 +178,12 @@ tile_map = open(os.path.join('data', 'states', state, 'layer1.txt'), 'r')

for row, line in enumerate(tile_map): for column, letter in enumerate(line): - if letter == '1': - tile = tile_dict['pavement'] - blit_tile_to_map(tile, row, column, map) - - elif letter == '2': - tile = tile_dict['house wall'] - blit_tile_to_map(tile, row, column, map) - - elif letter == '3': - tile = tile_dict['house roof'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'T': - tile = tile_dict['tree'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'W': - tile = tile_dict['well'] + if letter not in layer1_tile_code_dict: + pass + else: + tile = tile_dict[layer1_tile_code_dict[letter]] blit_tile_to_map(tile, row, column, map) - elif letter == 'M': - tile = tile_dict['moat'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'G': - tile = tile_dict['grass'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'B': - tile = tile_dict['castle bridge'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'C': - tile = tile_dict['horiz castle wall'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'V': - tile = tile_dict['left vert castle wall'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'X': - tile = tile_dict['right vert castle wall'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'S': - tile = tile_dict['castle side'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'Q': - tile = tile_dict['carpet topleft'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'E': - tile = tile_dict['carpet topright'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'J': - tile = tile_dict['carpet top'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'R': - tile = tile_dict['carpet bottomleft'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'U': - tile = tile_dict['carpet bottomright'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'D': - tile = tile_dict['carpet bottom'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'P': - tile = tile_dict['carpet left'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'A': - tile = tile_dict['carpet right'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'F': - tile = tile_dict['carpet center'] - blit_tile_to_map(tile, row, column, map) - - elif letter == 'H': - tile = tile_dict['marble floor'] - blit_tile_to_map(tile, row, column, map) - elif letter == 'K': - tile = tile_dict['black tile'] - blit_tile_to_map(tile, row, column, map) - - tile_map.close() layer1_extra = create_map_layer2(state, width, height, 'layer1extra.txt')

@@ -299,6 +268,9 @@ tile = tile_dict['column']

blit_tile_to_map(tile, row, column, map) elif letter == 'N': tile = tile_dict['black tile'] + blit_tile_to_map(tile, row, column, map) + elif letter == 'P': + tile = tile_dict['houseoverworld'] blit_tile_to_map(tile, row, column, map) tile_map.close()

@@ -453,6 +425,8 @@ elif letter == 'G':

portal_group.add(portal.Portal(column, row, c.ARMOR_SHOP)) elif letter == 'H': portal_group.add(portal.Portal(column, row, c.HOUSE)) + elif letter == 'J': + portal_group.add(portal.Portal(column, row, c.OVERWORLD)) return portal_group

@@ -460,4 +434,5 @@

get_image = tools.get_image tile_dict = create_town_sprite_sheet_dict() +layer1_tile_code_dict = create_layer1_tile_code_dict()
M data/tools.pydata/tools.py

@@ -174,6 +174,7 @@ 'last direction': 'up',

'town start pos': [12, 49], 'castle start pos': [12, 26], 'house start pos': [12, 13], + 'overworld start pos': [12, 21], 'king item': {'gold': 500}, 'player inventory': player_items, 'player stats': player_stats