all repos — Legends-RPG @ 3f30da44bb69bd438432750872fdd354c4f07ee3

A fantasy mini-RPG built with Python and Pygame.

Weapons are auto-equipped, other minor tweaks
Justin Armstrong justinmeister@gmail.com
Tue, 03 Jun 2014 10:49:04 -0700
commit

3f30da44bb69bd438432750872fdd354c4f07ee3

parent

771a9169fe092728fcd9519c5a9f76f2fd9cb035

M data/collision.pydata/collision.py

@@ -5,11 +5,12 @@

class CollisionHandler(object): """Handles collisions between the user, blockers and computer characters""" - def __init__(self, player, blockers, sprites, level): + def __init__(self, player, blockers, sprites, portals, level): self.player = player self.static_blockers = blockers self.blockers = self.make_blocker_list(blockers, sprites) self.sprites = sprites + self.portals = portals self.level = level def make_blocker_list(self, blockers, sprites):

@@ -41,6 +42,7 @@ self.check_for_blockers()

if self.player.rect.x % 32 == 0 and self.player.rect.y % 32 == 0: if not self.player.state == 'resting': + self.check_for_portal() self.check_for_battle() self.player.begin_resting()

@@ -49,8 +51,20 @@ if sprite.state == 'automoving':

if sprite.rect.x % 32 == 0 and sprite.rect.y % 32 == 0: sprite.begin_auto_resting() + def check_for_portal(self): + """ + Check for a portal to change level scene. + """ + portal = pg.sprite.spritecollideany(self.player, self.portals) + + if portal: + self.level.next = portal.name + self.level.use_portal = True + def check_for_blockers(self): - """Checks for collisions with blocker rects""" + """ + Checks for collisions with blocker rects. + """ player_collided = False sprite_collided_list = []
M data/menugui.pydata/menugui.py

@@ -460,8 +460,12 @@ self.notify(c.CLICK2)

if self.arrow.state == 'selectmenu': if self.arrow_index == 0: self.info_box.state = 'items' + self.arrow.state = 'itemsubmenu' + self.arrow_index = 0 elif self.arrow_index == 1: self.info_box.state = 'magic' + self.arrow.state = 'magicsubmenu' + self.arrow_index = 0 elif self.arrow_index == 2: self.info_box.state = 'stats' elif self.arrow.state == 'itemsubmenu':

@@ -556,12 +560,14 @@ def drink_potion(self, potion, stat, value):

""" Drink potion and change player stats. """ - self.inventory[potion]['quantity'] -= 1 - stat['current'] += value - if stat['current'] > stat['maximum']: - stat['current'] = stat['maximum'] - if not self.inventory[potion]['quantity']: - del self.inventory[potion] + if stat['current'] != stat['maximum']: + self.notify(c.POWERUP) + self.inventory[potion]['quantity'] -= 1 + stat['current'] += value + if stat['current'] > stat['maximum']: + stat['current'] = stat['maximum'] + if not self.inventory[potion]['quantity']: + del self.inventory[potion] def update(self, keys): self.info_box.update()
M data/shopgui.pydata/shopgui.py

@@ -303,13 +303,16 @@ self.add_player_item(item)

def add_player_item(self, item): - """Add item to player's inventory""" + """ + Add item to player's inventory. + """ item_type = item['type'] quantity = item['quantity'] value = item['price'] power = item['power'] magic_list = ['Cure', 'Fire Blast'] player_armor = ['Chain Mail', 'Wooden Shield'] + player_weapons = ['Rapier', 'Long Sword'] player_items = self.level.game_data['player inventory'] player_health = self.level.game_data['player stats']['health'] player_magic = self.level.game_data['player stats']['magic']

@@ -325,6 +328,8 @@ 'power': item['power']}

player_items[item_type] = item_to_add if item_type in player_armor: equipped_armor.append(item_type) + if item_type in player_weapons: + player_items['equipped weapon'] = item_type if item_type in player_items: player_items[item_type]['quantity'] += quantity elif quantity > 0:

@@ -333,9 +338,10 @@ elif item_type == 'room':

player_health['current'] = player_health['maximum'] player_magic['current'] = player_magic['maximum'] - def confirm_sell(self, keys, current_time): - """Confirm player wants to sell item""" + """ + Confirm player wants to sell item. + """ dialogue = ['Are you sure?'] choices = ['Yes', 'No'] self.dialogue_box = self.make_dialogue_box(dialogue, 0)
M data/states/battle.pydata/states/battle.py

@@ -326,11 +326,12 @@ if (self.current_time - self.timer) > 2200:

player_stats = self.game_data['player stats'] player_stats['experience to next level'] -= self.experience_points if player_stats['experience to next level'] <= 0: + extra_experience = player_stats['experience to next level'] * -1 player_stats['Level'] += 1 player_stats['health']['maximum'] += int(player_stats['health']['maximum']*.25) player_stats['magic']['maximum'] += int(player_stats['magic']['maximum']*.20) new_experience = int((player_stats['Level'] * 50) * .75) - player_stats['experience to next level'] = new_experience + player_stats['experience to next level'] = new_experience - extra_experience self.enter_level_up_state() self.just_leveled_up = True else:
M data/states/levels.pydata/states/levels.py

@@ -59,6 +59,7 @@ self.current_time = current_time

self.state = 'transition_in' self.reset_dialogue = () self.switch_to_battle = False + self.use_portal = False self.allow_input = False self.cut_off_bottom_map = ['castle', 'town', 'dungeon'] self.renderer = tilerender.Renderer(self.tmx_map)

@@ -67,7 +68,7 @@

self.viewport = self.make_viewport(self.map_image) self.level_surface = self.make_level_surface(self.map_image) self.level_rect = self.level_surface.get_rect() - self.portals = None + self.portals = self.make_level_portals() self.player = self.make_player() self.blockers = self.make_blockers() self.sprites = self.make_sprites()

@@ -75,10 +76,10 @@

self.collision_handler = collision.CollisionHandler(self.player, self.blockers, self.sprites, + self.portals, self) self.dialogue_handler = textbox.TextHandler(self) self.state_dict = self.make_state_dict() - self.portals = self.make_level_portals() self.menu_screen = player_menu.Player_Menu(game_data, self) self.transition_rect = setup.SCREEN.get_rect() self.transition_alpha = 255

@@ -345,11 +346,8 @@ 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': + if self.use_portal and not self.done: self.player.location = self.player.get_tile_location() - self.next = portal.name self.update_game_data() self.state = 'transition_out'
M data/states/shop.pydata/states/shop.py

@@ -294,7 +294,7 @@

def make_purchasable_items(self): """Make list of items to be chosen""" fire_dialogue = 'Fire Blast (150 gold)' - cure_dialogue = 'Cure (150 gold)' + cure_dialogue = 'Cure (50 gold)' item1 = {'type': 'Cure', 'price': 50,
M data/tools.pydata/tools.py

@@ -188,7 +188,7 @@ def create_game_data_dict():

"""Create a dictionary of persistant values the player carries between states""" - player_items = {'GOLD': dict([('quantity',100), + player_items = {'GOLD': dict([('quantity',200), ('value',0)]), 'Healing Potion': dict([('quantity',2), ('value',15)]),
M resources/tmx/castle.tmxresources/tmx/castle.tmx

@@ -163,12 +163,13 @@ </properties>

</object> <object name="sprite" type="king" gid="74" x="192" y="112"> <properties> - <property name="dialogue length" value="5"/> + <property name="dialogue length" value="6"/> <property name="dialogue0" value="Please! You must help me!"/> <property name="dialogue1" value="An evil sorceror has stolen my magic crown."/> <property name="dialogue2" value="WIthout it, our town will be overrun by monsters!"/> - <property name="dialogue3" value="Take this money for supplies."/> - <property name="dialogue4" value="Our town's fate is in your hands."/> + <property name="dialogue3" value="Go to the NorthWest Castle and retrieve it for me."/> + <property name="dialogue4" value="Here is some GOLD for supplies."/> + <property name="dialogue5" value="You are my only hope."/> </properties> </object> <object name="sprite" type="soldier" gid="74" x="128" y="336">