Player now collects gold from enemies after battle.
Justin Armstrong justinmeister@gmail.com
Sat, 24 May 2014 23:36:03 -0700
3 files changed,
39 insertions(+),
3 deletions(-)
M
data/battlegui.py
→
data/battlegui.py
@@ -15,7 +15,7 @@ """
Info box that describes attack damage and other battle related information. """ - def __init__(self, game_data, experience): + def __init__(self, game_data, experience, gold): self.game_data = game_data self.enemy_damage = 0 self.player_damage = 0@@ -24,6 +24,7 @@ self.title_font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 22)
self.title_font.set_underline(True) self.font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 18) self.experience_points = experience + self.gold_earned = gold self.state_dict = self.make_state_dict() self.image = self.make_image() self.rect = self.image.get_rect(bottom=608)@@ -50,7 +51,8 @@ c.FIRE_SPELL: 'FIRE BLAST!',
c.BATTLE_WON: 'Battle won!', c.SHOW_EXPERIENCE: self.show_experience(), c.LEVEL_UP: self.level_up(), - c.TWO_ACTIONS: 'Two actions per turn mode is now available.'} + c.TWO_ACTIONS: 'Two actions per turn mode is now available.', + c.SHOW_GOLD: self.show_gold()} return state_dict@@ -169,6 +171,12 @@ """
Show how much experience the player earned. """ return "You earned {} experience points this battle!".format(self.experience_points) + + def show_gold(self): + """ + Show how much gold the player earned. + """ + return "You found {} gold.".format(self.gold_earned) def level_up(self): """
M
data/constants.py
→
data/constants.py
@@ -64,6 +64,7 @@ FADE_DEATH = 'fade death'
SHOW_EXPERIENCE = 'show experience' LEVEL_UP = 'level up' TWO_ACTIONS = 'two actions' +SHOW_GOLD = 'show gold' #EVENTS
M
data/states/battle.py
→
data/states/battle.py
@@ -28,8 +28,11 @@ self.attack_animations = pg.sprite.Group()
self.sword = attackitems.Sword(self.player) self.enemy_group, self.enemy_pos_list, self.enemy_list = self.make_enemies() self.experience_points = self.get_experience_points() + self.new_gold = self.get_new_gold() self.background = self.make_background() - self.info_box = battlegui.InfoBox(game_data, self.experience_points) + self.info_box = battlegui.InfoBox(game_data, + self.experience_points, + self.new_gold) self.arrow = battlegui.SelectArrow(self.enemy_pos_list, self.info_box) self.select_box = battlegui.SelectBox()@@ -86,6 +89,18 @@ for enemy in self.enemy_list:
experience_total += (random.randint(5,10)*enemy.level) return experience_total + + def get_new_gold(self): + """ + Calculate the gold collected at the end of the battle. + """ + gold = 0 + + for enemy in self.enemy_list: + max_gold = enemy.level * 10 + gold += (random.randint(1, max_gold)) + + return gold def make_background(self): """Make the blue/black background"""@@ -261,6 +276,10 @@ if (self.current_time - self.timer) > 1500:
self.end_battle() elif self.state == c.BATTLE_WON: + if (self.current_time - self.timer) > 1800: + self.enter_show_gold_state() + + elif self.state == c.SHOW_GOLD: if (self.current_time - self.timer) > 1800: self.enter_show_experience_state()@@ -636,6 +655,14 @@ Transition battle into the battle won state.
""" self.state = self.info_box.state = c.BATTLE_WON self.player.state = c.VICTORY_DANCE + self.set_timer_to_current_time() + + def enter_show_gold_state(self): + """ + Transition battle into the show gold state. + """ + self.inventory['GOLD']['quantity'] += self.new_gold + self.state = self.info_box.state = c.SHOW_GOLD self.set_timer_to_current_time() def enter_show_experience_state(self):