all repos — Legends-RPG @ cc33fef47c2a05a8fbfc55b7d32f72fb5ff0fd59

A fantasy mini-RPG built with Python and Pygame.

Can now pick up items other than gold, changed brother to blue
Justin Armstrong justinmeister@gmail.com
Mon, 07 Apr 2014 17:51:51 -0700
commit

cc33fef47c2a05a8fbfc55b7d32f72fb5ff0fd59

parent

7725c2234297c6e0c00dfdb295d2961f72393d0f

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

@@ -36,7 +36,6 @@ self.default_direction = direction

self.item = None self.wander_box = self.make_wander_box() - def create_spritesheet_dict(self, sheet_key): """Implemented by inheriting classes""" image_list = []

@@ -58,7 +57,6 @@ image_dict[key] = image

return image_dict - def create_animation_dict(self): """Return a dictionary of image lists for animation""" image_dict = self.spritesheet_dict

@@ -74,7 +72,6 @@ 'up': up_list,

'down': down_list} return direction_dict - def create_state_dict(self): """Return a dictionary of all state methods"""

@@ -86,7 +83,6 @@ 'automoving': self.auto_moving}

return state_dict - def create_vector_dict(self): """Return a dictionary of x and y velocities set to direction keys."""

@@ -96,7 +92,6 @@ 'left': (-1, 0),

'right': (1, 0)} return vector_dict - def update(self, current_time, *args): """Implemented by inheriting classes"""

@@ -290,7 +285,6 @@ assert(self.rect.x % 32 == 0 or self.rect.y % 32 == 0), \

'Not centered on tile' - class Player(Person): """User controlled character"""

@@ -371,8 +365,13 @@

class OldMan(Person): """Old man villager""" - def __init__(self, x, y, direction='down', state='resting'): - super(OldMan, self).__init__('oldman', x, y, direction, state) + def __init__(self, x, y, filename='oldman', direction='down', state='resting'): + super(OldMan, self).__init__(filename, 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/components/textbox.pydata/components/textbox.py

@@ -87,7 +87,7 @@ image.blit(self.bground, (0, 0))

if self.item: type = list(self.item.keys())[0] - total = str(self.item[type]) + total = str(self.item[type]['quantity']) dialogue = 'You received ' + total + ' ' + type + '.' self.dialogue_list = [dialogue] self.item = None

@@ -180,12 +180,23 @@

def check_for_item(self): """Checks if sprite has an item to give to the player""" item = self.talking_sprite.item + type = list(item.keys())[0] + quantity = item[type]['quantity'] + value = item[type]['value'] + if item: - if 'gold' in item: - self.game_data['player inventory']['gold'] += item['gold'] + if type in self.game_data['player inventory']: + self.game_data['player inventory'][type]['quantity'] += item[type]['quantity'] + else: + self.game_data['player inventory'][type] = {'quantity': quantity, + 'value': value} + self.talking_sprite.item = None + if self.talking_sprite.name == 'king': self.game_data['king item'] = None + elif self.talking_sprite.name == 'oldmanbrother': + self.game_data['old man item'] = None return item
M data/menugui.pydata/menugui.py

@@ -57,7 +57,8 @@ pos_list = [(310, 173),

(310, 223), (310, 323), (310, 373), - (310, 478)] + (310, 478), + (310, 528)] return pos_list

@@ -89,7 +90,7 @@ surface = pg.Surface(rect.size)

surface.set_colorkey(c.BLACK) surface.blit(image, (0, 0)) - text = "Gold: " + str(self.inventory['gold']) + text = "Gold: " + str(self.inventory['GOLD']['quantity']) text_render = self.font.render(text, True, c.NEAR_BLACK) text_rect = text_render.get_rect(centerx=130, centery=35)

@@ -122,12 +123,12 @@ self.get_tile = tilemap.get_tile

self.sword = self.get_tile(96, 0, setup.GFX['shopsigns'], 32, 32) self.shield = self.get_tile(64, 0, setup.GFX['shopsigns'], 32, 32) self.potion = self.get_tile(32, 0, setup.GFX['shopsigns'], 32, 32) - self.possible_potions = ['Healing Potion'] + self.possible_potions = ['Healing Potion', 'ELIXIR'] self.possible_armor = ['Wooden Shield', 'Chain Mail'] self.possible_weapons = ['Long Sword', 'Rapier'] self.possible_magic = ['Fire Blast', 'Cure'] - self.quantity_items = ['Healing Potion'] - self.slots = [None for i in range(5)] + self.quantity_items = ['Healing Potion', 'ELIXIR'] + self.slots = [None for i in range(6)] self.state = 'stats' self.state_dict = self.make_state_dict() self.print_slots = True

@@ -192,7 +193,6 @@ surface.blit(self.sword['surface'], self.sword['rect'])

surface.blit(self.shield['surface'], self.shield['rect']) surface.blit(self.potion['surface'], self.potion['rect']) - self.image = surface self.rect = rect

@@ -213,6 +213,9 @@ self.slots[3] = armor[2]

if len(potions) == 2: self.slots[4] = potions[1] + elif len(potions) == 3: + self.slots[4] = potions[1] + self.slots[5] = potions[2]
M data/shopgui.pydata/shopgui.py

@@ -85,7 +85,7 @@

surface = pg.Surface(rect.size) surface.set_colorkey(c.BLACK) surface.blit(image, (0, 0)) - gold = self.player_inventory['gold'] + gold = self.player_inventory['GOLD']['quantity'] text = 'Gold: ' + str(gold) text_render = self.font.render(text, True, c.NEAR_BLACK) text_rect = text_render.get_rect(x=80, y=60)

@@ -268,16 +268,16 @@ def buy_item(self):

"""Attempt to allow player to purchase item""" item = self.item_to_be_purchased - self.player_inventory['gold'] -= item['price'] + self.player_inventory['GOLD']['quantity'] -= item['price'] - if self.player_inventory['gold'] < 0: - self.player_inventory['gold'] += item['price'] + if self.player_inventory['GOLD']['quantity'] < 0: + self.player_inventory['GOLD']['quantity'] += item['price'] self.state = 'reject' else: if (item['type'] in self.player_inventory and self.name == 'Magic Shop'): self.state = 'hasitem' - self.player_inventory['gold'] += item['price'] + self.player_inventory['gold']['quantity'] += item['price'] else: self.state = 'accept' self.add_player_item(item)
M data/states/brother_house/brother_house.pydata/states/brother_house/brother_house.py

@@ -19,9 +19,8 @@

def set_sprite_dialogue(self): """Sets unique dialogue for each sprite""" for sprite in self.sprites: - if sprite.location == [14, 6]: - sprite.dialogue = ["I am very sick. cough... cough...", - "Only an ELIXIR can help me.", - "Please go to my brother and obtain one for me.", - "He lives in a house on the NorthEast shores.", - "I will be forever in your debt."] + 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']
M data/states/brother_house/sprite_start_pos.txtdata/states/brother_house/sprite_start_pos.txt

@@ -4,7 +4,7 @@ 0000000000000000000000000

0000000000000000000000000 0000000000000000000000000 0000000000000000000000000 -000000000H000000000000000 +000000000J000000000000000 0000000000000000000000000 0000000000000000000000000 0000000000000000000000000
M data/tilemap.pydata/tilemap.py

@@ -382,6 +382,9 @@ level_sprites.add(devil_villager)

elif letter == 'H': old_villager = person.OldMan(column*32, row*32) level_sprites.add(old_villager) + elif letter == 'J': + old_brother = person.OldManBrother(column*32, row*32) + level_sprites.add(old_brother) tile_map.close()
M data/tools.pydata/tools.py

@@ -155,7 +155,9 @@

def create_game_data_dict(): """Create a dictionary of persistant values the player carries between states""" - player_items = {'gold': 600} + + player_items = {'GOLD': dict([('quantity',600), + ('value',0)])} player_health = {'current': 100, 'maximum': 100}

@@ -179,7 +181,10 @@ 'castle start pos': [12, 26],

'house start pos': [12, 13], 'brother_house start pos': [12, 13], 'overworld start pos': [17, 30], - 'king item': {'gold': 500}, + 'king item': {'GOLD': dict([('quantity', 500), + ('value',0)])}, + 'old man item': {'ELIXIR': dict([('value',1000), + ('quantity',1)])}, 'player inventory': player_items, 'player stats': player_stats }