all repos — Legends-RPG @ a55164ece8c0aeea2d6fcc25cf11f80345134f11

A fantasy mini-RPG built with Python and Pygame.

Finished house, began adding sprites to town map
Justin Armstrong justinmeister@gmail.com
Fri, 11 Apr 2014 21:41:55 -0700
commit

a55164ece8c0aeea2d6fcc25cf11f80345134f11

parent

6387912ba1c75cd67b42aa13d443f3b07598983d

M data/components/person.pydata/components/person.py

@@ -337,14 +337,14 @@ class FemaleVillager(Person):

"""Female Person for town""" def __init__(self, x, y): - super(FemaleVillager, self).__init__('femalevillager', x, y) - self.index = 1 + super(FemaleVillager, self).__init__('femalevillager', x, y, 'right') + #self.index = 1 class FemaleVillager2(Person): """A second female person for town""" def __init__(self, x, y, direction='down'): - super(FemaleVillager2, self).__init__('femvillager2', x, y, direction) + super(FemaleVillager2, self).__init__('femvillager2', x, y, direction, 'autoresting') self.index = 1
M data/shopgui.pydata/shopgui.py

@@ -13,6 +13,7 @@ class Gui(object):

"""Class that controls the GUI of the shop state""" def __init__(self, level): self.level = level + self.game_data = self.level.game_data self.level.game_data['last direction'] = 'down' self.sellable_items = level.sell_items self.player_inventory = level.game_data['player inventory']

@@ -224,6 +225,7 @@

else: if self.level.name in self.no_selling: self.level.done = True + self.game_data['last state'] = self.level.name else: self.state = 'buysell'

@@ -433,7 +435,9 @@ self.allow_input = False

self.arrow_index = 0 else: + self.level.done = True + self.game_data['last state'] = self.level.name self.arrow_index = 0
M data/states/house/house.pydata/states/house/house.py

@@ -8,13 +8,13 @@

from .. import level_state from ... import constants as c +from ... import setup class House(level_state.LevelState): def __init__(self): super(House, self).__init__() self.name = c.HOUSE - self.map_width = 25 - self.map_height = 19 + self.tmx_map = setup.TMX['house'] def set_sprite_dialogue(self): """Sets unique dialogue for each sprite"""
M data/states/level_state.pydata/states/level_state.py

@@ -40,12 +40,8 @@ self.portals = None

self.player = person.Player(game_data['last direction']) self.player = self.make_player() self.blockers = self.make_blockers() - self.sprites = pg.sprite.Group() - #self.start_positions = tm.set_sprite_positions(self.player, - # self.sprites, - # self.name, - # self.game_data) - #self.set_sprite_dialogue() + self.sprites = self.make_sprites() + self.collision_handler = collision.CollisionHandler(self.player, self.blockers, self.sprites)

@@ -74,14 +70,16 @@

def make_player(self): """Makes the player and sets location""" player = person.Player(self.game_data['last direction']) + last_state = self.game_data['last state'] for object in self.renderer.tmx_data.getObjects(): properties = object.__dict__ - if properties['name'] == 'player start': - posx = properties['x'] * 2 - posy = (properties['y'] * 2) - 32 - player.rect.x = posx - player.rect.y = posy + if properties['name'] == 'start point': + if last_state == properties['state']: + posx = properties['x'] * 2 + posy = (properties['y'] * 2) - 32 + player.rect.x = posx + player.rect.y = posy return player

@@ -99,6 +97,29 @@ blockers.append(blocker)

return blockers + def make_sprites(self): + """Make any sprites for the level as needed""" + sprites = pg.sprite.Group() + + for object in self.renderer.tmx_data.getObjects(): + properties = object.__dict__ + if properties['name'] == 'sprite': + left = properties['x'] * 2 + top = ((properties['y']) * 2) - 32 + + if properties['type'] == 'oldman': + sprites.add(person.OldMan(left, top)) + elif properties['type'] == 'bluedressgirl': + sprites.add(person.FemaleVillager(left, top)) + elif properties['type'] == 'femalewarrior': + sprites.add(person.FemaleVillager2(left, top)) + elif properties['type'] == 'devil': + print 'hi' + sprites.add(person.Devil(left, top)) + + + return sprites + def set_sprite_dialogue(self): """Sets unique dialogue for each sprite"""

@@ -122,7 +143,7 @@ properties = object.__dict__

if properties['name'] == 'portal': posx = properties['x'] * 2 posy = (properties['y'] * 2) - 32 - new_state = properties['new state'] + new_state = properties['type'] portal_group.add(portal.Portal(posx, posy, new_state))

@@ -134,9 +155,9 @@ """Update level normally"""

self.check_for_dialogue() self.check_for_portals() self.player.update(keys, current_time) - #self.sprites.update(current_time) + self.sprites.update(current_time) self.collision_handler.update(keys, current_time) - #self.dialogue_handler.update(keys, current_time) + self.dialogue_handler.update(keys, current_time) self.check_for_menu(keys) self.viewport_update()

@@ -150,7 +171,6 @@

if portal and self.player.state == 'resting': self.player.location = self.player.get_tile_location() self.next = portal.name - print self.next self.update_game_data() self.done = True

@@ -171,7 +191,6 @@ """Update the persistant game data dictionary"""

self.game_data['last location'] = self.player.location self.game_data['last direction'] = self.player.direction self.game_data['last state'] = self.name - self.set_new_start_pos()

@@ -179,7 +198,6 @@ def set_new_start_pos(self):

"""Set new start position based on previous state""" location = copy.deepcopy(self.game_data['last location']) direction = self.game_data['last direction'] - state = self.game_data['last state'] if self.next == 'player menu': pass

@@ -192,12 +210,11 @@ location[0] += 1

elif direction == 'right': location[0] -= 1 - self.game_data[state + ' start pos'] = location def handling_dialogue(self, surface, keys, current_time): """Update only dialogue boxes""" - #self.dialogue_handler.update(keys, current_time) + self.dialogue_handler.update(keys, current_time) self.draw_level(surface)

@@ -209,9 +226,8 @@

def check_for_dialogue(self): """Check if the level needs to freeze""" - #if self.dialogue_handler.textbox: - # self.state = 'dialogue' - pass + if self.dialogue_handler.textbox: + self.state = 'dialogue' def update(self, surface, keys, current_time): """Updates state"""
M data/states/shop.pydata/states/shop.py

@@ -119,7 +119,7 @@ class Inn(Shop):

"""Where our hero gets rest""" def __init__(self): super(Inn, self).__init__() - self.name = 'Inn' + self.name = c.INN self.key = 'innman' def make_dialogue(self):

@@ -150,7 +150,7 @@ class WeaponShop(Shop):

"""A place to buy weapons""" def __init__(self): super(WeaponShop, self).__init__() - self.name = 'Weapon Shop' + self.name = c.WEAPON_SHOP self.key = 'weaponman' self.sell_items = ['Long Sword', 'Rapier']

@@ -183,7 +183,7 @@ class ArmorShop(Shop):

"""A place to buy armor""" def __init__(self): super(ArmorShop, self).__init__() - self.name = 'Armor Shop' + self.name = c.ARMOR_SHOP self.key = 'armorman' self.sell_items = ['Chain Mail', 'Wooden Shield']

@@ -216,7 +216,7 @@ class MagicShop(Shop):

"""A place to buy magic""" def __init__(self): super(MagicShop, self).__init__() - self.name = 'Magic Shop' + self.name = c.MAGIC_SHOP self.key = 'magiclady'

@@ -248,7 +248,7 @@ class PotionShop(Shop):

"""A place to buy potions""" def __init__(self): super(PotionShop, self).__init__() - self.name = 'Potion Shop' + self.name = c.POTION_SHOP self.key = 'potionlady' self.sell_items = 'Healing Potion'
A resources/tmx/house.tmx

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

+<?xml version="1.0" encoding="UTF-8"?> +<map version="1.0" orientation="orthogonal" width="25" height="19" tilewidth="16" tileheight="16" backgroundcolor="#130f30"> + <tileset firstgid="1" name="tileset1" tilewidth="16" tileheight="16"> + <image source="../graphics/tileset1.png" width="160" height="80"/> + </tileset> + <tileset firstgid="51" name="tileset2" tilewidth="16" tileheight="16"> + <image source="../graphics/tileset2.png" width="160" height="180"/> + </tileset> + <tileset firstgid="161" name="tileset3" tilewidth="16" tileheight="16"> + <image source="../graphics/tileset3.png" width="176" height="192"/> + </tileset> + <tileset firstgid="293" name="house" tilewidth="16" tileheight="16"> + <image source="../graphics/house.png" width="512" height="448"/> + </tileset> + <layer name="Tile Layer 1" width="25" height="19"> + <data encoding="base64" compression="zlib"> + eJzt0TEOgCAQBdFFStTa46rHFShRSifxBCSsiWZ/eO1OgYjN9mxp1LtxICIhKzUKTlyoSg1xPAzwTqcRuDtiwqzUeOPPv9xYsWHv2LD9dzcEmhGk + </data> + </layer> + <layer name="Tile Layer 2" width="25" height="19"> + <data encoding="base64" compression="zlib"> + eJzty7cRwlAQRdE/2wYI3wVOmC4ACaMucMJ0AUgCVKhutinzE5K9Myd7z7n/VRPn6gjQQBMttNFBFz3RnU99fgMMMcIYISaYYoa56M6nBb8lVogQY40NttghEd35tOd3wBEnnJHigituuIvufHrwe+KFDDkKvPHBF6XozrIsy/qtCvPJFrM= + </data> + </layer> + <layer name="Tile Layer 3" width="25" height="19"> + <data encoding="base64" compression="zlib"> + eJztzckNgEAMBMHBJhGORDgSgSXxXQiElojBvNxSfWekLPuqJjXceCzmo3PJ4Og95mNgd8SEOehjYXfFhj3o42D3RMEV9JFl2T+9ywQG6w== + </data> + </layer> + <objectgroup name="Object Layer 1" width="25" height="19"> + <object name="sprite" type="oldman" gid="115" x="240" y="128"/> + <object name="start point" gid="123" x="176" y="224"> + <properties> + <property name="state" value="town"/> + </properties> + </object> + <object name="portal" type="town" gid="139" x="192" y="240"/> + <object name="portal" type="town" gid="139" x="176" y="240"/> + <object name="portal" type="town" gid="139" x="160" y="240"/> + </objectgroup> +</map>
M resources/tmx/overworld.tmxresources/tmx/overworld.tmx

@@ -150,16 +150,17 @@ <object name="blocker" gid="120" x="80" y="64"/>

<object name="blocker" gid="120" x="96" y="64"/> <object name="blocker" gid="120" x="96" y="80"/> <object name="blocker" gid="120" x="96" y="96"/> - <object name="portal" gid="139" x="272" y="480"> + <object name="portal" type="town" gid="139" x="272" y="480"/> + <object name="portal" type="town" gid="139" x="256" y="480"/> + <object name="start point" gid="123" x="272" y="496"> <properties> - <property name="new state" value="town"/> + <property name="state" value="town"/> </properties> </object> - <object name="portal" gid="139" x="256" y="480"> + <object name="start point" gid="123" x="256" y="496"> <properties> - <property name="new state" value="town"/> + <property name="state" value="main menu"/> </properties> </object> - <object name="player start" gid="123" x="272" y="496"/> </objectgroup> </map>
M resources/tmx/town.tmxresources/tmx/town.tmx

@@ -6,6 +6,12 @@ </tileset>

<tileset firstgid="51" name="tileset2" tilewidth="16" tileheight="16"> <image source="../graphics/tileset2.png" width="160" height="180"/> </tileset> + <tileset firstgid="161" name="medievalsigns" tilewidth="16" tileheight="16"> + <image source="../graphics/medievalsigns.png" width="64" height="64"/> + </tileset> + <tileset firstgid="177" name="shopsigns" tilewidth="16" tileheight="16"> + <image source="../graphics/shopsigns.png" width="64" height="16"/> + </tileset> <layer name="Tile Layer 1" width="25" height="51"> <data encoding="base64" compression="zlib"> eJztlc8KgCAMh733Rl58gB2jl4q6Rc+bBwOJmVv5Z8iC7yDu54eOGBhjQFEGZ/Vs6iBxeE4BPcNwDL5kXMb/ZA7UvLM6xnHsEdg656DkWziWCGydc1DyLRyAZLGz3nrOyZdkxP+Dev4UqOGJz2/lqf1eUntuGdwOTsYO9Fbq6ONIzU9OjQRHav5xaiQ4gLCfqynp6DHHOff4izrqO1p8Fz0Qegc=

@@ -13,11 +19,15 @@ </data>

</layer> <layer name="Tile Layer 2" width="25" height="51"> <data encoding="base64" compression="zlib"> - eJztVlsKxCAQyzH6vfjtkXZ7/1NsF1qQwceMmilbDAxFahPiqGkAF+Go6MAfHPhZOpKfsV7Lhx4ePqQOC+zzAfT52M6y6ljQo/GDZa1eZ1n5mT0H+D0Hlg8Llg89Uh9v8U6OWyh97+nD69+EAXbWAn2Z/jlqH+Bv6Vz8Gp0af0zm1HRG+YGxPRCTZxBjBtj3lARz717PJ57BmXqaPTyKf+dHgX9235k+ZMbmfFhzvIS7+v2UczHjnIcKPzJjrZa8W1vZGsV8jU5uLTTZas3H3HzvDPwCwBwqqw== + eJztVkkKwzAMnGf0XHz2k9p+sIcuD2wKDhjhRbI9LjUZEEJEmUGWFcWBC7eZn8DvJvCzdCQ/47yOOvSYUYfUYYE9H0BbHadgVh0LWjS+sJzVOZiVn9lzgN9z4KjDghXreItnLyPXU8SP4OM6LiJHxjXk3p/Zj1n/Jgywdy3QttOvm906+Gs6O79Gp8Tvo5ySTi8/0HcHfOSdiBlgf6ckmHd39yvO4Eg9zR3uxb/zI8M/qg/34Jl1yB2bqsO6x3P4Vb9XmYsRc+4K/EjEWi35ba3tVi/yNTqps9DsVut+TOXP3oEfnVUuIg== </data> </layer> <objectgroup name="Object Layer 1" width="25" height="51"> - <object name="player start" gid="123" x="176" y="800"/> + <object name="start point" gid="123" x="176" y="800"> + <properties> + <property name="state" value="overworld"/> + </properties> + </object> <object name="blocker" gid="120" x="112" y="800"/> <object name="blocker" gid="120" x="112" y="784"/> <object name="blocker" gid="120" x="96" y="768"/>

@@ -190,41 +200,46 @@ <object name="blocker" gid="120" x="384" y="288"/>

<object name="blocker" gid="120" x="384" y="256"/> <object name="blocker" gid="120" x="384" y="240"/> <object name="blocker" gid="120" x="384" y="224"/> - <object name="portal" gid="139" x="192" y="816"> + <object name="portal" type="overworld" gid="139" x="192" y="816"/> + <object name="portal" type="overworld" gid="139" x="176" y="816"/> + <object name="portal" type="house" gid="139" x="64" y="688"/> + <object name="portal" type="Inn" gid="139" x="320" y="672"/> + <object name="portal" type="armor shop" gid="139" x="96" y="368"/> + <object name="portal" type="weapon shop" gid="139" x="32" y="368"/> + <object name="portal" type="potion shop" gid="139" x="288" y="368"/> + <object name="portal" type="magic shop" gid="139" x="352" y="368"/> + <object name="start point" gid="123" x="320" y="688"> <properties> - <property name="new state" value="overworld"/> + <property name="state" value="Inn"/> </properties> </object> - <object name="portal" gid="139" x="176" y="816"> + <object name="start point" gid="123" x="64" y="704"> <properties> - <property name="new state" value="overworld"/> + <property name="state" value="house"/> </properties> </object> - <object gid="139" x="64" y="688"/> - <object name="portal" gid="139" x="320" y="672"> + <object name="start point" gid="123" x="352" y="384"> <properties> - <property name="new state" value="Inn"/> + <property name="state" value="magic shop"/> </properties> </object> - <object name="portal" gid="139" x="96" y="368"> - <properties> - <property name="new state" value="armor shop"/> - </properties> - </object> - <object name="portal" gid="139" x="32" y="368"> + <object name="start point" gid="123" x="288" y="384"> <properties> - <property name="new state" value="weapon shop"/> + <property name="state" value="potion shop"/> </properties> </object> - <object name="portal" gid="139" x="288" y="368"> + <object name="start point" gid="123" x="96" y="384"> <properties> - <property name="new state" value="potion shop"/> + <property name="state" value="armor shop"/> </properties> </object> - <object name="portal" gid="139" x="352" y="368"> + <object name="start point" gid="123" x="32" y="384"> <properties> - <property name="new state" value="magic shop"/> + <property name="state" value="weapon shop"/> </properties> </object> + <object name="sprite" type="bluedressgirl" gid="124" x="144" y="768"/> + <object name="sprite" type="femalewarrior" gid="124" x="240" y="640"/> + <object name="sprite" type="devil" gid="124" x="288" y="464"/> </objectgroup> </map>