all repos — Legends-RPG @ 322ed0813ca073c324e0476bbf9412b05c1d71e0

A fantasy mini-RPG built with Python and Pygame.

Added brother's house, refactored NPCs
Justin Armstrong justinmeister@gmail.com
Sat, 12 Apr 2014 11:25:06 -0700
commit

322ed0813ca073c324e0476bbf9412b05c1d71e0

parent

68aafd99d9f82e78e31817a43b72cdd0d7ce9900

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

@@ -7,16 +7,13 @@ class Person(pg.sprite.Sprite):

"""Base class for all world characters controlled by the computer""" - def __init__(self, sheet_key, x, y, direction='right', state='resting'): + def __init__(self, sheet_key, x, y, direction='down', state='resting', index=0): super(Person, self).__init__() self.name = sheet_key self.get_image = setup.tools.get_image self.spritesheet_dict = self.create_spritesheet_dict(sheet_key) self.animation_dict = self.create_animation_dict() - if direction == 'left': - self.index = 1 - else: - self.index = 0 + self.index = index self.direction = direction self.image_list = self.animation_dict[self.direction] self.image = self.image_list[self.index]

@@ -130,23 +127,21 @@ blockers.extend([tile_rect1, tile_rect2])

return blockers - - def get_tile_location(self): - """Converts pygame coordinates into tile coordinates""" + """ + Convert pygame coordinates into tile coordinates. + """ if self.rect.x == 0: tile_x = 0 elif self.rect.x % 32 == 0: tile_x = (self.rect.x / 32) else: tile_x = 0 - if self.rect.y == 0: tile_y = 0 elif self.rect.y % 32 == 0: tile_y = (self.rect.y / 32) - else: tile_y = 0

@@ -154,8 +149,10 @@ return [tile_x, tile_y]

def make_wander_box(self): - """Make a list of rects that surround the initial location - of a sprite to limit his/her wandering""" + """ + Make a list of rects that surround the initial location + of a sprite to limit his/her wandering. + """ x = int(self.location[0]) y = int(self.location[1]) box_list = []

@@ -189,21 +186,21 @@ + str(self.rect.y))

assert(self.rect.x % 32 == 0), ('Player not centered on tile' + str(self.rect.x)) - def moving(self): - """Increment index and set self.image for animation.""" + """ + Increment index and set self.image for animation. + """ self.animation() - assert(self.rect.x % 32 == 0 or self.rect.y % 32 == 0), \ 'Not centered on tile' - def animated_resting(self): self.animation(500) - def animation(self, freq=100): - """Adjust sprite image frame based on timer""" + """ + Adjust sprite image frame based on timer. + """ if (self.current_time - self.timer) > freq: if self.index < (len(self.image_list) - 1): self.index += 1

@@ -213,10 +210,10 @@ self.timer = self.current_time

self.image = self.image_list[self.index] - - def begin_moving(self, direction): - """Transition the player into the 'moving' state.""" + """ + Transition the player into the 'moving' state. + """ self.direction = direction self.image_list = self.animation_dict[direction] self.timer = self.current_time

@@ -230,14 +227,17 @@ self.x_vel = self.vector_dict[self.direction][0]

def begin_resting(self): - """Transition the player into the 'resting' state.""" + """ + Transition the player into the 'resting' state. + """ self.state = 'resting' self.index = 1 self.x_vel = self.y_vel = 0 - def begin_auto_moving(self, direction): - """Transition sprite to a automatic moving state""" + """ + Transition sprite to a automatic moving state. + """ self.direction = direction self.image_list = self.animation_dict[direction] self.state = 'automoving'

@@ -245,9 +245,10 @@ self.x_vel = self.vector_dict[direction][0]

self.y_vel = self.vector_dict[direction][1] self.move_timer = self.current_time - def begin_auto_resting(self): - """Transition sprite to an automatic resting state""" + """ + Transition sprite to an automatic resting state. + """ self.state = 'autoresting' self.index = 1 self.x_vel = self.y_vel = 0

@@ -275,10 +276,10 @@ direction = direction_list[0]

self.begin_auto_moving(direction) self.move_timer = self.current_time - - def auto_moving(self): - """Animate sprite and check to stop""" + """ + Animate sprite and check to stop. + """ self.animation() assert(self.rect.x % 32 == 0 or self.rect.y % 32 == 0), \

@@ -286,7 +287,9 @@ 'Not centered on tile'

class Player(Person): - """User controlled character""" + """ + User controlled character. + """ def __init__(self, direction, x=0, y=0): super(Player, self).__init__('player', x, y, direction)

@@ -330,45 +333,6 @@ """Soldier for the castle"""

def __init__(self, x, y, direction='down', state='resting'): super(Soldier, self).__init__('soldier', x, y, direction, state) - - - -class FemaleVillager(Person): - """Female Person for town""" - - def __init__(self, x, y, direction='down', state='resting'): - super(FemaleVillager, self).__init__('femalevillager', x, y, direction, state) - 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, 'autoresting') - self.index = 1 - - -class King(Person): - """King of the town""" - def __init__(self, x, y, direction='down', state='resting'): - super(King, self).__init__('king', x, y, direction, state) - - -class Devil(Person): - """Devil-like villager""" - def __init__(self, x, y, direction='down', state='autoresting'): - super(Devil, self).__init__('devil', x, y, direction, state) - - -class OldMan(Person): - """Old man villager""" - def __init__(self, x, y, direction='down', state='resting'): - super(OldMan, self).__init__('oldman', x, y, direction, state) - -class OldManBrother(OldMan): - """Brother of Old Man""" - def __init__(self, x, y): - super(OldManBrother, self).__init__(x, y, 'oldmanbrother') class Well(pg.sprite.Sprite):
M data/main.pydata/main.py

@@ -16,7 +16,7 @@ MAGIC_SHOP = 'magic shop'

POTION_SHOP = 'potion shop' PLAYER_MENU = 'player menu' OVERWORLD = 'overworld' -BROTHER_HOUSE = 'brother_house' +BROTHER_HOUSE = 'brotherhouse' BATTLE = 'battle'

@@ -27,6 +27,7 @@ state_dict = {MAIN_MENU: main_menu.Menu(),

TOWN: levels.LevelState(TOWN), HOUSE: levels.LevelState(HOUSE), OVERWORLD: levels.LevelState(OVERWORLD), + BROTHER_HOUSE: levels.LevelState(BROTHER_HOUSE), INN: shop.Inn(), ARMOR_SHOP: shop.ArmorShop(), WEAPON_SHOP: shop.WeaponShop(),
D data/states/brother_house/__init__.py

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

-__author__ = 'justin'
D data/states/brother_house/blockers.txt

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

-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -00000000BBBBBBBBB00000000 -000000B1111111B11B0000000 -000000B1111111B11B0000000 -000000B1111111B11B0000000 -000000B1111111B11B0000000 -000000B1111111BBBB0000000 -000000B1111111111B0000000 -000000B1111111111B0000000 -000000B1111111111B0000000 -000000B1111111111B0000000 -0000000BBBB11BBBB00000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000
D data/states/brother_house/brother_house.py

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

-"""This is the house on the lower left hand -corner of the town. 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. Essentially the -only purpose of house.py is to assign dialogue to each sprite. -""" - - -from .. import levels -from ... import constants as c - -class House(levels.LevelState): - def __init__(self): - super(House, self).__init__() - self.name = c.BROTHER_HOUSE - self.map_width = 25 - self.map_height = 19 - - def set_sprite_dialogue(self): - """Sets unique dialogue for each sprite""" - for sprite in self.sprites: - if sprite.location == [9, 6]: - sprite.dialogue = ["My brother is sick?!?", - "I haven't seen him in years. I had no idea he was not well.", - "Quick, take this ELIXIR to him immediately."] - sprite.item = self.game_data['old man item']
D data/states/brother_house/layer1.txt

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

-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000BBBBBBBBBB00000000 -0000000BBBBBBBBBB00000000 -0000000BBBBBBBBBB00000000 -0000000BBBBBBBBBB00000000 -0000000BBBBBBBBBB00000000 -0000000BBBBBBBBBB00000000 -0000000BBBBBBBBBB00000000 -0000000BBBBBBBBBB00000000 -0000000BBBBQEBBBB00000000 -0000000KKKKKKKKKK00000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000
D data/states/brother_house/layer1extra.txt

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

-0000000000000000000000000 -0000000G00000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -00000001111111E1100000000 -00000001J1111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000
D data/states/brother_house/layer2.txt

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

-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -00000000000NN000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000
D data/states/brother_house/layer3.txt

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

-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000111111111100000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000
D data/states/brother_house/portals.txt

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

-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -00000000000JJ000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000
D data/states/brother_house/sprite_start_pos.txt

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

-0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -000000000J000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000 -0000000000000000000000000
M data/states/levels.pydata/states/levels.py

@@ -106,14 +106,15 @@

for object in self.renderer.tmx_data.getObjects(): properties = object.__dict__ if properties['name'] == 'sprite': - left = properties['x'] * 2 - top = ((properties['y']) * 2) - 32 + x = properties['x'] * 2 + y = ((properties['y']) * 2) - 32 - sprite_dict = {'oldman': person.OldMan(left, top), - 'bluedressgirl': person.FemaleVillager(left, top, 'right'), - 'femalewarrior': person.FemaleVillager2(left, top), - 'devil': person.Devil(left, top)} - + sprite_dict = {'oldman': person.Person('oldman', x, y, 'down'), + 'bluedressgirl': person.Person('femalevillager', x, y, 'right', 'resting', 1), + 'femalewarrior': person.Person('femvillager2', x, y, 'down', 'autoresting'), + 'devil': person.Person('devil', x, y, 'down', 'autoresting'), + 'oldmanbrother': person.Person('oldmanbrother', x, y, 'down')} + sprite = sprite_dict[properties['type']] self.assign_dialogue(sprite, properties) sprites.add(sprite)
A resources/tmx/brotherhouse.tmx

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

+<?xml version="1.0" encoding="UTF-8"?> +<map version="1.0" orientation="orthogonal" width="25" height="19" tilewidth="16" tileheight="16" backgroundcolor="#131930"> + <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"> + eJzt0TEOgCAQBdEFS8Wa46rHBSwVSyfxBBrWguwPr90pELHZnsWXvjYSMgp2pcaBExWXUkMcDx6D02mM3J0QMCs1/vjzXhsLVmyNGrZ+dwOWbhGk + </data> + </layer> + <layer name="Tile Layer 2" width="25" height="19"> + <data encoding="base64" compression="zlib"> + eJztzcURwzAUhGFFThdBQxdBQxdBQxdh6CIMjQUKyX/TXTMaH+Kd+W773gqRXypSiCpqqKOBJmw4cOFJ1dNJi7s2Ouiihz58BAgRSdXTyYC7IUYYY4IpYiRIkUnV08mMuzkWWGKFNTbYYoe9VD2dHLg74oQzLrjihjseeErVM5EXf9/44Gtoo2QJIWGhbJnZsPnrwIVnaMPnb4AQkaGNmL8JUmSGNooU+Yf8ACabHZ0= + </data> + </layer> + <objectgroup name="Object Layer 1" width="25" height="19"> + <object name="blocker" gid="120" x="224" y="240"/> + <object name="blocker" gid="120" x="256" y="240"/> + <object name="blocker" gid="120" x="240" y="240"/> + <object name="blocker" gid="120" x="272" y="240"/> + <object name="blocker" gid="120" x="288" y="224"/> + <object name="blocker" gid="120" x="288" y="192"/> + <object name="blocker" gid="120" x="288" y="208"/> + <object name="blocker" gid="120" x="288" y="160"/> + <object name="blocker" gid="120" x="288" y="176"/> + <object name="blocker" gid="120" x="288" y="144"/> + <object name="blocker" gid="120" x="288" y="128"/> + <object name="blocker" gid="120" x="288" y="112"/> + <object name="blocker" gid="120" x="288" y="96"/> + <object name="blocker" gid="120" x="288" y="80"/> + <object name="blocker" gid="120" x="272" y="80"/> + <object name="blocker" gid="120" x="256" y="80"/> + <object name="blocker" gid="120" x="240" y="80"/> + <object name="blocker" gid="120" x="224" y="80"/> + <object name="blocker" gid="120" x="208" y="80"/> + <object name="blocker" gid="120" x="208" y="80"/> + <object name="blocker" gid="120" x="192" y="80"/> + <object name="blocker" gid="120" x="176" y="80"/> + <object name="blocker" gid="120" x="160" y="80"/> + <object name="blocker" gid="120" x="144" y="80"/> + <object name="blocker" gid="120" x="128" y="80"/> + <object name="blocker" gid="120" x="128" y="80"/> + <object name="blocker" gid="120" x="112" y="80"/> + <object name="blocker" gid="120" x="96" y="80"/> + <object name="blocker" gid="120" x="96" y="80"/> + <object name="blocker" gid="120" x="80" y="96"/> + <object name="blocker" gid="120" x="80" y="112"/> + <object name="blocker" gid="120" x="80" y="128"/> + <object name="blocker" gid="120" x="80" y="144"/> + <object name="blocker" gid="120" x="80" y="160"/> + <object name="blocker" gid="120" x="80" y="176"/> + <object name="blocker" gid="120" x="80" y="192"/> + <object name="blocker" gid="120" x="80" y="208"/> + <object name="blocker" gid="120" x="80" y="224"/> + <object name="blocker" gid="120" x="96" y="240"/> + <object name="blocker" gid="120" x="112" y="240"/> + <object name="blocker" gid="120" x="128" y="240"/> + <object name="blocker" gid="120" x="144" y="240"/> + <object name="blocker" gid="120" x="160" y="240"/> + <object name="blocker" gid="120" x="240" y="160"/> + <object name="blocker" gid="120" x="240" y="176"/> + <object name="blocker" gid="120" x="256" y="176"/> + <object name="blocker" gid="120" x="256" y="160"/> + <object name="blocker" gid="120" x="256" y="128"/> + <object name="blocker" gid="120" x="256" y="144"/> + <object name="blocker" gid="120" x="240" y="144"/> + <object name="blocker" gid="120" x="240" y="128"/> + <object name="blocker" gid="120" x="240" y="112"/> + <object name="blocker" gid="120" x="256" y="112"/> + <object name="sprite" type="oldmanbrother" gid="115" x="128" y="128"> + <properties> + <property name="dialogue length" value="3"/> + <property name="dialogue0" value="My brother is sick?!?"/> + <property name="dialogue1" value="I haven't seen him in years. I had no idea he was not well."/> + <property name="dialogue2" value="Quick, take this ELIXIR to him immediately."/> + </properties> + </object> + <object name="start point" gid="123" x="192" y="224"> + <properties> + <property name="state" value="overworld"/> + </properties> + </object> + <object name="portal" type="overworld" gid="139" x="208" y="240"/> + <object name="portal" type="overworld" gid="139" x="192" y="240"/> + <object name="portal" type="overworld" gid="139" x="176" y="240"/> + </objectgroup> +</map>
M resources/tmx/overworld.tmxresources/tmx/overworld.tmx

@@ -162,5 +162,11 @@ <properties>

<property name="state" value="main menu"/> </properties> </object> + <object name="portal" type="brotherhouse" gid="139" x="400" y="144"/> + <object name="start point" gid="123" x="400" y="160"> + <properties> + <property name="state" value="brotherhouse"/> + </properties> + </object> </objectgroup> </map>