all repos — Legends-RPG @ 29d6707d48fd9a25b37b8dd03c3031896d11dc36

A fantasy mini-RPG built with Python and Pygame.

Added a run away animation.
Justin Armstrong justinmeister@gmail.com
Fri, 02 May 2014 12:08:32 -0700
commit

29d6707d48fd9a25b37b8dd03c3031896d11dc36

parent

cd7f046fd56e95bda0da95b6a8b9a192e10aa6c0

M data/battlegui.pydata/battlegui.py

@@ -39,11 +39,12 @@ c.SELECT_ITEM: 'Select an item.',

c.SELECT_ENEMY: 'Select an enemy.', c.ENEMY_ATTACK: 'Enemy attacks player!', c.PLAYER_ATTACK: 'Player attacks enemy.', - c.RUN_AWAY: 'Run away', + c.RUN_AWAY: 'RUN AWAY!!!', c.ENEMY_HIT: self.enemy_hit(), c.ENEMY_DEAD: 'Enemy killed.', c.DISPLAY_ENEMY_ATTACK_DAMAGE: self.player_hit(), - c.DRINK_HEALING_POTION: 'Player healed.'} + c.DRINK_HEALING_POTION: 'Player healed.', + c.FIRE_SPELL: 'FIRE BLAST!'} return state_dict
M data/components/person.pydata/components/person.py

@@ -85,7 +85,8 @@ 'autoresting': self.auto_resting,

'automoving': self.auto_moving, 'battle resting': self.battle_resting, 'attack': self.attack, - 'enemy attack': self.enemy_attack} + 'enemy attack': self.enemy_attack, + c.RUN_AWAY: self.run_away} return state_dict

@@ -380,6 +381,19 @@ """

max_strength = self.level * 5 min_strength = 0 return random.randint(min_strength, max_strength) + + def run_away(self): + """ + Run away from battle state. + """ + X_VEL = 5 + self.rect.x += X_VEL + self.direction = 'right' + self.small_image_list = self.animation_dict[self.direction] + self.image_list = [] + for image in self.small_image_list: + self.image_list.append(pg.transform.scale2x(image)) + self.animation() class Player(Person):
M data/observer.pydata/observer.py

@@ -145,7 +145,11 @@ self.level.set_timer_to_current_time()

self.level.state = c.ENEMY_HIT def run_away(self): - self.level.end_battle() + self.info_box.state = c.RUN_AWAY + self.level.set_timer_to_current_time() + self.arrow.become_invisible_surface() + self.player.state = c.RUN_AWAY + def battle_won(self): self.level.end_battle()

@@ -170,23 +174,17 @@ def cure_spell(self):

""" Cast cure spell on player. """ - self.player.healing = True - self.level.set_timer_to_current_time() - self.level.state = c.CURE_SPELL - self.arrow.become_invisible_surface() - self.level.enemy_index = 0 - self.level.damage_points.add( - attackitems.HealthPoints(50, self.player.rect.topright, False)) - self.level.player_healed(50) - self.info_box.state = c.DRINK_HEALING_POTION + self.level.cast_cure() + def fire_spell(self): """ Cast fire spell on all enemies. """ self.level.cast_fire_blast() - self.level.state = c.FIRE_SPELL - self.level.set_timer_to_current_time() + + +
M data/shopgui.pydata/shopgui.py

@@ -276,10 +276,10 @@ 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']['quantity'] += item['price'] + if (item['type'] in self.player_inventory and + self.name == c.MAGIC_SHOP): + self.state = 'hasitem' + self.player_inventory['GOLD']['quantity'] += item['price'] else: self.state = 'accept' self.add_player_item(item)

@@ -290,6 +290,7 @@ """Add item to player's inventory"""

item_type = item['type'] quantity = item['quantity'] value = item['price'] + magic_list = ['Cure', 'Fire Blast'] 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 points']

@@ -297,7 +298,11 @@

item_to_add = {'quantity': quantity, 'value': value} - if item_type in player_items: + if item_type in magic_list: + item_to_add = {'magic points': item['magic points'], + 'power': item['power']} + player_items[item_type] = item_to_add + elif item_type in player_items: player_items[item_type]['quantity'] += quantity elif quantity > 0: player_items[item_type] = item_to_add
M data/states/battle.pydata/states/battle.py

@@ -43,6 +43,7 @@ """Initialize state attributes"""

self.current_time = current_time self.timer = current_time self.game_data = game_data + self.inventory = game_data['player inventory'] self.state = c.SELECT_ACTION self.next = game_data['last state']

@@ -185,29 +186,37 @@ """

timed_states = [c.DISPLAY_ENEMY_ATTACK_DAMAGE, c.ENEMY_HIT, c.ENEMY_DEAD, - c.DRINK_HEALING_POTION, - c.CURE_SPELL, - c.FIRE_SPELL] + c.DRINK_HEALING_POTION] long_delay = timed_states[1:] if self.state in long_delay: if (self.current_time - self.timer) > 800: if self.state == c.ENEMY_HIT: - self.state = c.ENEMY_DEAD - elif self.state == c.ENEMY_DEAD: if len(self.enemy_list): self.state = c.ENEMY_ATTACK else: self.state = c.BATTLE_WON elif (self.state == c.DRINK_HEALING_POTION or - self.state == c.CURE_SPELL or - self.state == c.FIRE_SPELL): + self.state == c.CURE_SPELL): if len(self.enemy_list): self.state = c.ENEMY_ATTACK else: self.state = c.BATTLE_WON self.timer = self.current_time self.notify(self.state) + + elif self.state == c.FIRE_SPELL or self.state == c.CURE_SPELL: + if (self.current_time - self.timer) > 1500: + if len(self.enemy_list): + self.state = c.ENEMY_ATTACK + else: + self.state = c.BATTLE_WON + self.timer = self.current_time + self.notify(self.state) + + elif self.state == c.RUN_AWAY: + if (self.current_time - self.timer) > 1500: + self.end_battle() elif self.state == c.DISPLAY_ENEMY_ATTACK_DAMAGE: if (self.current_time - self.timer) > 600:

@@ -278,7 +287,7 @@

def player_damaged(self, damage): self.game_data['player stats']['health']['current'] -= damage - def player_healed(self, heal): + def player_healed(self, heal, magic_points): health = self.game_data['player stats']['health'] health['current'] += heal

@@ -290,7 +299,7 @@ self.game_data['player inventory']['Healing Potion']['quantity'] -= 1

if self.game_data['player inventory']['Healing Potion']['quantity'] == 0: del self.game_data['player inventory']['Healing Potion'] elif self.state == c.CURE_SPELL: - self.game_data['player stats']['magic points']['current'] -= 25 + self.game_data['player stats']['magic points']['current'] -= magic_points def set_timer_to_current_time(self): """Set the timer to the current time."""

@@ -300,10 +309,11 @@ def cast_fire_blast(self):

""" Cast fire blast on all enemies. """ - DAMAGE = 5 - MAGIC_POINTS = 75 + POWER = self.inventory['Fire Blast']['power'] + MAGIC_POINTS = self.inventory['Fire Blast']['magic points'] self.game_data['player stats']['magic points']['current'] -= MAGIC_POINTS for enemy in self.enemy_list: + DAMAGE = random.randint(POWER//2, POWER) self.damage_points.add( attackitems.HealthPoints(DAMAGE, enemy.rect.topright)) enemy.health -= DAMAGE

@@ -319,6 +329,25 @@ self.enemy_index = 0

self.arrow.index = 0 self.arrow.become_invisible_surface() self.arrow.state = c.SELECT_ACTION + self.state = c.FIRE_SPELL + self.set_timer_to_current_time() + self.info_box.state = c.FIRE_SPELL + + def cast_cure(self): + """ + Cast cure spell on player. + """ + HEAL_AMOUNT = self.inventory['Cure']['power'] + MAGIC_POINTS = self.inventory['Cure']['magic points'] + self.player.healing = True + self.set_timer_to_current_time() + self.state = c.CURE_SPELL + self.arrow.become_invisible_surface() + self.enemy_index = 0 + self.damage_points.add( + attackitems.HealthPoints(HEAL_AMOUNT, self.player.rect.topright, False)) + self.player_healed(HEAL_AMOUNT, MAGIC_POINTS) + self.info_box.state = c.DRINK_HEALING_POTION
M data/states/shop.pydata/states/shop.py

@@ -234,11 +234,15 @@

item1 = {'type': 'Cure', 'price': 150, 'quantity': 1, + 'magic points': 25, + 'power': 50, 'dialogue': cure_dialogue} item2 = {'type': 'Fire Blast', 'price': 150, 'quantity': 1, + 'magic points': 75, + 'power': 10, 'dialogue': fire_dialogue} return [item1, item2]
M data/tools.pydata/tools.py

@@ -175,10 +175,10 @@ player_items = {'GOLD': dict([('quantity',600),

('value',0)]), 'Healing Potion': dict([('quantity',5), ('value',15)]), - 'Fire Blast': dict([('value', 150), - ('quantity', 1)]), - 'Cure': dict([('value', 150), - ('quantity', 1)])} + 'Fire Blast': dict([('magic points', 75), + ('power', 10)]), + 'Cure': dict([('magic points', 25), + ('power', 50)])} player_health = {'current': 100, 'maximum': 100}