Began implementing a level system.
@@ -15,7 +15,7 @@ """
Info box that describes attack damage and other battle related information. """ - def __init__(self, game_data): + def __init__(self, game_data, experience): self.game_data = game_data self.enemy_damage = 0 self.player_damage = 0@@ -23,6 +23,7 @@ self.state = c.SELECT_ACTION
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.state_dict = self.make_state_dict() self.image = self.make_image() self.rect = self.image.get_rect(bottom=608)@@ -46,7 +47,9 @@ c.DISPLAY_ENEMY_ATTACK_DAMAGE: self.player_hit(),
c.DRINK_HEALING_POTION: 'Player healed.', c.DRINK_ETHER_POTION: 'Magic Points Increased.', c.FIRE_SPELL: 'FIRE BLAST!', - c.BATTLE_WON: 'Battle won!'} + c.BATTLE_WON: 'Battle won!', + c.SHOW_EXPERIENCE: self.show_experience(), + c.LEVEL_UP: self.level_up()} return state_dict@@ -159,6 +162,22 @@
def update(self): """Updates info box""" self.image = self.make_image() + + def show_experience(self): + """ + Show how much experience the player earned. + """ + return "You earned {} experience points this battle!".format(self.experience_points) + + def level_up(self): + """ + Return message indicating a level up for player. + """ + return "You leveled up to Level {}!".format(self.game_data['player stats']['Level']) + + def reset_level_up_message(self): + self.state_dict[c.LEVEL_UP] = self.level_up() + class SelectBox(object):
@@ -37,7 +37,6 @@ self.default_direction = direction
self.item = None self.wander_box = self.make_wander_box() self.observers = [] - self.level = 1 self.health = 0 self.death_image = pg.transform.scale2x(self.image) self.battle = None@@ -464,13 +463,21 @@ """
User controlled character. """ - def __init__(self, direction, x=0, y=0, state='resting', index=0): + def __init__(self, direction, game_data, x=0, y=0, state='resting', index=0): super(Player, self).__init__('player', x, y, direction, state, index) self.damaged = False self.healing = False self.damage_alpha = 0 self.healing_alpha = 0 self.fade_in = True + self.game_data = game_data + + @property + def level(self): + """ + Make level property equal to player level in game_data. + """ + return self.game_data['player stats']['Level'] def create_vector_dict(self):@@ -562,39 +569,18 @@ """
Calculate hit strength based on attack stats. """ max_strength = 5 + (self.level * 5) + print max_strength min_strength = max_strength // 2 return random.randint(min_strength, max_strength) - - -class Well(pg.sprite.Sprite): - """Talking well""" - def __init__(self, x, y): - super(Well, self).__init__() - self.image = pg.Surface((32, 32)) - self.image.set_colorkey((0,0,0)) - self.rect = self.image.get_rect(left=x, top=y) - self.location = self.get_location() - self.dialogue = ["I'm a well!"] - self.blockers = [self.rect] - self.x_vel = self.y_vel = 0 - self.state = 'resting' - self.direction = 'down' - self.default_direction = self.direction - self.item = None - self.wander_box = [] - - def get_location(self): - """Get tile location""" - x = self.rect.x / 32 - y = self.rect.y / 32 - - return [x, y] - - def begin_auto_resting(self): - """Placeholder""" - pass +class Enemy(Person): + """ + Enemy sprite. + """ + def __init__(self, sheet_key, x, y, direction='down', state='resting', index=0): + super(Enemy, self).__init__(sheet_key, x, y, direction, state, index) + self.level = 1 class Chest(Person):
@@ -64,6 +64,8 @@ VICTORY_DANCE = 'victory dance'
KNOCK_BACK = 'knock back' FLEE = 'flee' FADE_DEATH = 'fade death' +SHOW_EXPERIENCE = 'show experience' +LEVEL_UP = 'level up' #EVENTS
@@ -47,7 +47,9 @@ c.ENEMY_ATTACK_DAMAGE: self.player_damaged,
c.DRINK_HEALING_POTION: self.drink_healing_potion, c.DRINK_ETHER_POTION: self.drink_ether_potion, c.CURE_SPELL: self.cure_spell, - c.FIRE_SPELL: self.fire_spell} + c.FIRE_SPELL: self.fire_spell, + c.SHOW_EXPERIENCE: self.show_experience, + c.LEVEL_UP: self.level_up} return event_dict@@ -205,6 +207,21 @@ """
Eliminate all traces of enemy. """ self.player.attacked_enemy = None + + def show_experience(self): + """ + Show the experience the player gained that battle. + """ + self.info_box.state = c.SHOW_EXPERIENCE + self.level.set_timer_to_current_time() + + def level_up(self): + """ + Display message that the player leveled up. + """ + self.info_box.reset_level_up_message() + self.info_box.state = c.LEVEL_UP + self.level.set_timer_to_current_time()
@@ -27,6 +27,7 @@ self.attacking_enemy = None
self.enemy_group = None self.enemy_pos_list = [] self.enemy_list = [] + self.experience_points = 0 self.background = None self.info_box = None@@ -53,8 +54,9 @@ self.player = self.make_player()
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.background = self.make_background() - self.info_box = battlegui.InfoBox(game_data) + self.info_box = battlegui.InfoBox(game_data, self.experience_points) self.arrow = battlegui.SelectArrow(self.enemy_pos_list, self.info_box) self.select_box = battlegui.SelectBox()@@ -66,6 +68,33 @@ self.observers = [observer.Battle(self)]
self.player.observers.extend(self.observers) self.damage_points = pg.sprite.Group() + def make_enemy_level_dict(self): + new_dict = {c.OVERWORLD: 1, + c.DUNGEON: 2, + c.DUNGEON2: 2, + c.DUNGEON3: 3, + c.DUNGEON4: 2} + + return new_dict + + def set_enemy_level(self, enemy_list): + dungeon_level_dict = self.make_enemy_level_dict() + + for enemy in enemy_list: + enemy.level = dungeon_level_dict[self.previous] + + def get_experience_points(self): + """ + Calculate experience points based on number of enemies + and their levels. + """ + experience_total = 0 + + for enemy in self.enemy_list: + experience_total += (random.randint(5,10)*enemy.level) + + return experience_total + @staticmethod def make_background(): """Make the blue/black background"""@@ -91,29 +120,28 @@
enemy_group = pg.sprite.Group() if self.game_data['battle type']: - enemy = person.Person('evilwizard', 0, 0, + enemy = person.Enemy('evilwizard', 0, 0, 'down', 'battle resting') enemy_group.add(enemy) else: for enemy in range(random.randint(1, 6)): - enemy_group.add(person.Person('devil', 0, 0, + enemy_group.add(person.Enemy('devil', 0, 0, 'down', 'battle resting')) for i, enemy in enumerate(enemy_group): enemy.rect.topleft = pos_list[i] enemy.image = pg.transform.scale2x(enemy.image) enemy.index = i - enemy.level = 1 + enemy.level = self.make_enemy_level_dict()[self.previous] enemy.health = enemy.level * 7 enemy_list = [enemy for enemy in enemy_group] return enemy_group, pos_list[0:len(enemy_group)], enemy_list - @staticmethod - def make_player(): + def make_player(self): """Make the sprite for the player's character""" - player = person.Player('left', 630, 220, 'battle resting', 1) + player = person.Player('left', self.game_data, 630, 220, 'battle resting', 1) player.image = pg.transform.scale2x(player.image) return player@@ -224,9 +252,28 @@ self.state = c.BATTLE_WON
self.timer = self.current_time self.notify(self.state) - elif self.state == c.FLEE or self.state == c.BATTLE_WON: + elif self.state == c.FLEE: if (self.current_time - self.timer) > 1500: self.end_battle() + + elif self.state == c.BATTLE_WON: + if (self.current_time - self.timer) > 1800: + self.state = c.SHOW_EXPERIENCE + self.notify(self.state) + + elif self.state == c.SHOW_EXPERIENCE: + 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: + player_stats['Level'] += 1 + player_stats['health']['maximum'] += int(player_stats['health']['maximum']*.25) + player_stats['magic points']['maximum'] += int(player_stats['magic points']['maximum']*.20) + new_experience = int((player_stats['Level'] * 100) * .75) + player_stats['experience to next level'] = new_experience + self.notify(c.LEVEL_UP) + else: + self.end_battle() elif self.state == c.DISPLAY_ENEMY_ATTACK_DAMAGE: if (self.current_time - self.timer) > 600:
@@ -83,7 +83,7 @@ last_state = self.game_data['last state']
if last_state == 'battle': - player = person.Player(self.game_data['last direction']) + player = person.Player(self.game_data['last direction'], self.game_data) player.rect.x = self.game_data['last location'][0] * 32 player.rect.y = self.game_data['last location'][1] * 32@@ -94,7 +94,8 @@ if properties['name'] == 'start point':
if last_state == properties['state']: posx = properties['x'] * 2 posy = (properties['y'] * 2) - 32 - player = person.Player(properties['direction']) + player = person.Player(properties['direction'], + self.game_data) player.rect.x = posx player.rect.y = posy
@@ -40,8 +40,8 @@ def flip_state(self):
previous, self.state_name = self.state_name, self.state.next persist = self.state.cleanup() self.state = self.state_dict[self.state_name] - self.state.startup(self.current_time, persist) self.state.previous = previous + self.state.startup(self.current_time, persist) def event_loop(self): self.events = pg.event.get()@@ -188,7 +188,7 @@ 'maximum': 100}
player_stats = {'health': player_health, 'Level': 1, - 'experience to next level': 100, + 'experience to next level': 20, 'magic points': player_magic, 'attack points': 10, 'Defense Points': 10}