all repos — Legends-RPG @ 2ded5c74f1c07582e76cc562f5d3027c49637745

A fantasy mini-RPG built with Python and Pygame.

data/states/battle.py (view raw)

  1"""This is the state that handles battles against
  2monsters"""
  3import random, sys
  4from itertools import izip
  5import pygame as pg
  6from .. import tools, battlegui, observer, setup
  7from .. components import person, attack, attackitems
  8from .. import constants as c
  9
 10
 11#Python 2/3 compatibility.
 12if sys.version_info[0] == 2:
 13    range = xrange
 14
 15
 16class Battle(tools._State):
 17    def __init__(self):
 18        super(Battle, self).__init__()
 19        self.name = 'battle'
 20        self.music = setup.MUSIC['high_action']
 21        self.volume = 0.4
 22
 23    def startup(self, current_time, game_data):
 24        """Initialize state attributes"""
 25        self.current_time = current_time
 26        self.timer = current_time
 27        self.allow_input = False
 28        self.game_data = game_data
 29        self.inventory = game_data['player inventory']
 30        self.state = 'transition in'
 31        self.next = game_data['last state']
 32        self.run_away = False
 33
 34        self.player = self.make_player()
 35        self.attack_animations = pg.sprite.Group()
 36        self.sword = attackitems.Sword(self.player)
 37        self.enemy_group, self.enemy_pos_list, self.enemy_list = self.make_enemies()
 38        self.experience_points = self.get_experience_points()
 39        self.new_gold = self.get_new_gold()
 40        self.background = self.make_background()
 41        self.info_box = battlegui.InfoBox(game_data, 
 42                                          self.experience_points, 
 43                                          self.new_gold)
 44        self.arrow = battlegui.SelectArrow(self.enemy_pos_list,
 45                                           self.info_box)
 46        self.select_box = battlegui.SelectBox()
 47        self.player_health_box = battlegui.PlayerHealth(self.select_box.rect,
 48                                                        self.game_data)
 49
 50        self.select_action_state_dict = self.make_selection_state_dict()
 51        self.observers = [observer.Battle(self),
 52                          observer.MusicChange()]
 53        self.player.observers.extend(self.observers)
 54        self.observers.append(observer.SoundEffects())
 55        self.damage_points = pg.sprite.Group()
 56        self.player_actions = []
 57        self.player_action_dict = self.make_player_action_dict()
 58        self.player_level = self.game_data['player stats']['Level']
 59        self.enemies_to_attack = []
 60        self.action_selected = False
 61        self.just_leveled_up = False
 62        self.transition_rect = setup.SCREEN.get_rect()
 63        self.transition_alpha = 255
 64
 65    def make_player_action_dict(self):
 66        """
 67        Make the dict to execute player actions.
 68        """
 69        action_dict = {c.PLAYER_ATTACK: self.enter_player_attack_state,
 70                       c.CURE_SPELL: self.cast_cure,
 71                       c.FIRE_SPELL: self.cast_fire_blast,
 72                       c.DRINK_HEALING_POTION: self.enter_drink_healing_potion_state,
 73                       c.DRINK_ETHER_POTION: self.enter_drink_ether_potion_state}
 74
 75        return action_dict
 76
 77    def make_enemy_level_dict(self):
 78        new_dict = {c.OVERWORLD: 1,
 79                    c.DUNGEON: 2,
 80                    c.DUNGEON2: 2,
 81                    c.DUNGEON3: 3,
 82                    c.DUNGEON4: 2,
 83                    c.DUNGEON5: 5}
 84
 85        return new_dict
 86
 87    def set_enemy_level(self, enemy_list):
 88        dungeon_level_dict = self.make_enemy_level_dict()
 89
 90        for enemy in enemy_list:
 91            enemy.level = dungeon_level_dict[self.previous]
 92
 93    def get_experience_points(self):
 94        """
 95        Calculate experience points based on number of enemies
 96        and their levels.
 97        """
 98        experience_total = 0
 99
100        for enemy in self.enemy_list:
101            experience_total += (random.randint(5,10)*enemy.level)
102
103        return experience_total
104
105    def get_new_gold(self):
106        """
107        Calculate the gold collected at the end of the battle.
108        """
109        gold = 0
110
111        for enemy in self.enemy_list:
112            max_gold = enemy.level * 20
113            gold += (random.randint(1, max_gold))
114
115        return gold
116
117    def make_background(self):
118        """Make the blue/black background"""
119        background = pg.sprite.Sprite()
120        surface = pg.Surface(c.SCREEN_SIZE).convert()
121        surface.fill(c.BLACK_BLUE)
122        background.image = surface
123        background.rect = background.image.get_rect()
124        background_group = pg.sprite.Group(background)
125
126        return background_group
127
128    def make_enemies(self):
129        """Make the enemies for the battle. Return sprite group"""
130        pos_list = []
131
132        for column in range(3):
133            for row in range(3):
134                x = (column * 100) + 100
135                y = (row * 100) + 100
136                pos_list.append([x, y])
137
138        enemy_group = pg.sprite.Group()
139
140        if self.game_data['battle type']:
141            enemy = person.Enemy('evilwizard', 0, 0,
142                                  'down', 'battle resting')
143            enemy_group.add(enemy)
144        else:
145            for enemy in range(random.randint(1, 6)):
146                enemy_group.add(person.Enemy('devil', 0, 0,
147                                              'down', 'battle resting'))
148
149        for i, enemy in enumerate(enemy_group):
150            enemy.rect.topleft = pos_list[i]
151            enemy.image = pg.transform.scale2x(enemy.image)
152            enemy.index = i
153            enemy.level = self.make_enemy_level_dict()[self.previous]
154            enemy.health = enemy.level * 7
155
156        enemy_list = [enemy for enemy in enemy_group]
157
158        return enemy_group, pos_list[0:len(enemy_group)], enemy_list
159
160    def make_player(self):
161        """Make the sprite for the player's character"""
162        player = person.Player('left', self.game_data, 630, 220, 'battle resting', 1)
163        player.image = pg.transform.scale2x(player.image)
164        return player
165
166    def make_selection_state_dict(self):
167        """
168        Make a dictionary of states with arrow coordinates as keys.
169        """
170        pos_list = self.arrow.make_select_action_pos_list()
171        state_list = [self.enter_select_enemy_state, self.enter_select_item_state,
172                      self.enter_select_magic_state, self.try_to_run_away]
173        return dict(izip(pos_list, state_list))
174
175    def update(self, surface, keys, current_time):
176        """Update the battle state"""
177        self.current_time = current_time
178        self.check_input(keys)
179        self.check_timed_events()
180        self.check_if_battle_won()
181        self.enemy_group.update(current_time)
182        self.player.update(keys, current_time)
183        self.attack_animations.update()
184        self.info_box.update()
185        self.arrow.update(keys)
186        self.sword.update(current_time)
187        self.damage_points.update()
188        self.execute_player_actions()
189
190        self.draw_battle(surface)
191
192    def check_input(self, keys):
193        """
194        Check user input to navigate GUI.
195        """
196        if self.allow_input:
197            if keys[pg.K_RETURN]:
198                self.end_battle()
199
200            elif keys[pg.K_SPACE]:
201                if self.state == c.SELECT_ACTION:
202                    enter_state_function = self.select_action_state_dict[
203                        self.arrow.rect.topleft]
204                    enter_state_function()
205
206                elif self.state == c.SELECT_ENEMY:
207                    self.player_actions.append(c.PLAYER_ATTACK)
208                    self.enemies_to_attack.append(self.get_enemy_to_attack())
209                    self.action_selected = True
210
211                elif self.state == c.SELECT_ITEM:
212                    if self.arrow.index == (len(self.arrow.pos_list) - 1):
213                        self.enter_select_action_state()
214                    elif self.info_box.item_text_list[self.arrow.index][:14] == 'Healing Potion':
215                        self.player_actions.append(c.DRINK_HEALING_POTION)
216                        self.action_selected = True
217                    elif self.info_box.item_text_list[self.arrow.index][:5] == 'Ether':
218                        self.player_actions.append(c.DRINK_ETHER_POTION)
219                        self.action_selected = True
220                elif self.state == c.SELECT_MAGIC:
221                    if self.arrow.index == (len(self.arrow.pos_list) - 1):
222                        self.enter_select_action_state()
223                    elif self.info_box.magic_text_list[self.arrow.index] == 'Cure':
224                        magic_points = self.game_data['player inventory']['Cure']['magic points']
225                        if self.game_data['player stats']['magic']['current'] >= magic_points:
226                            self.player_actions.append(c.CURE_SPELL)
227                            self.action_selected = True
228                    elif self.info_box.magic_text_list[self.arrow.index] == 'Fire Blast':
229                        magic_points = self.game_data['player inventory']['Fire Blast']['magic points']
230                        if self.game_data['player stats']['magic']['current'] >= magic_points:
231                            self.player_actions.append(c.FIRE_SPELL)
232                            self.action_selected = True
233
234            self.allow_input = False
235
236        if keys[pg.K_RETURN] == False and keys[pg.K_SPACE] == False:
237            self.allow_input = True
238
239    def check_timed_events(self):
240        """
241        Check if amount of time has passed for timed events.
242        """
243        timed_states = [c.PLAYER_DAMAGED,
244                        c.ENEMY_DAMAGED,
245                        c.ENEMY_DEAD,
246                        c.DRINK_HEALING_POTION,
247                        c.DRINK_ETHER_POTION]
248        long_delay = timed_states[1:]
249
250        if self.state in long_delay:
251            if (self.current_time - self.timer) > 1000:
252                if self.state == c.ENEMY_DAMAGED:
253                    if self.player_actions:
254                        self.player_action_dict[self.player_actions[0]]()
255                        self.player_actions.pop(0)
256                    else:
257                        if len(self.enemy_list):
258                            self.enter_enemy_attack_state()
259                        else:
260                            self.enter_battle_won_state()
261                elif (self.state == c.DRINK_HEALING_POTION or
262                      self.state == c.CURE_SPELL or
263                      self.state == c.DRINK_ETHER_POTION):
264                    if self.player_actions:
265                        self.player_action_dict[self.player_actions[0]]()
266                        self.player_actions.pop(0)
267                    else:
268                        if len(self.enemy_list):
269                            self.enter_enemy_attack_state()
270                        else:
271                            self.enter_battle_won_state()
272                self.timer = self.current_time
273
274        elif self.state == c.FIRE_SPELL or self.state == c.CURE_SPELL:
275            if (self.current_time - self.timer) > 1500:
276                if self.player_actions:
277                    self.player_action_dict[self.player_actions[0]]()
278                    self.player_actions.pop(0)
279                else:
280                    if len(self.enemy_list):
281                        self.enter_enemy_attack_state()
282                    else:
283                        self.enter_battle_won_state()
284                self.timer = self.current_time
285
286        elif self.state == c.RUN_AWAY:
287            if (self.current_time - self.timer) > 1500:
288                self.end_battle()
289
290        elif self.state == c.BATTLE_WON:
291            if (self.current_time - self.timer) > 1800:
292                self.enter_show_gold_state()
293
294        elif self.state == c.SHOW_GOLD:
295            if (self.current_time - self.timer) > 1800:
296                self.enter_show_experience_state()
297
298        elif self.state == c.LEVEL_UP:
299            if (self.current_time - self.timer) > 2200:
300                if self.game_data['player stats']['Level'] == 3:
301                    self.enter_two_actions_per_turn_state()
302                else:
303                    self.end_battle()
304
305        elif self.state == c.TWO_ACTIONS:
306            if (self.current_time - self.timer) > 3000:
307                self.end_battle()
308
309        elif self.state == c.SHOW_EXPERIENCE:
310            if (self.current_time - self.timer) > 2200:
311                player_stats = self.game_data['player stats']
312                player_stats['experience to next level'] -= self.experience_points
313                if player_stats['experience to next level'] <= 0:
314                    player_stats['Level'] += 1
315                    player_stats['health']['maximum'] += int(player_stats['health']['maximum']*.25)
316                    player_stats['magic']['maximum'] += int(player_stats['magic']['maximum']*.20)
317                    new_experience = int((player_stats['Level'] * 50) * .75)
318                    player_stats['experience to next level'] = new_experience
319                    self.enter_level_up_state()
320                    self.just_leveled_up = True
321                else:
322                    self.end_battle()
323
324        elif self.state == c.PLAYER_DAMAGED:
325            if (self.current_time - self.timer) > 600:
326                if self.enemy_index == (len(self.enemy_list) - 1):
327                    if self.run_away:
328                        self.enter_run_away_state()
329                    else:
330                        self.enter_select_action_state()
331                else:
332                    self.switch_enemy()
333                self.timer = self.current_time
334
335    def check_if_battle_won(self):
336        """
337        Check if state is SELECT_ACTION and there are no enemies left.
338        """
339        if self.state == c.SELECT_ACTION:
340            if len(self.enemy_group) == 0:
341                self.enter_battle_won_state()
342
343    def notify(self, event):
344        """
345        Notify observer of event.
346        """
347        for new_observer in self.observers:
348            new_observer.on_notify(event)
349
350    def end_battle(self):
351        """
352        End battle and flip back to previous state.
353        """
354        if self.game_data['battle type'] == 'evilwizard':
355            self.game_data['crown quest'] = True
356        self.game_data['last state'] = self.name
357        self.game_data['battle counter'] = random.randint(50, 255)
358        self.game_data['battle type'] = None
359        self.state = 'transition out'
360
361    def attack_enemy(self, enemy_damage):
362        enemy = self.player.attacked_enemy
363        enemy.health -= enemy_damage
364        self.set_enemy_indices()
365
366        if enemy:
367            enemy.enter_knock_back_state()
368            if enemy.health <= 0:
369                self.enemy_list.pop(enemy.index)
370                enemy.state = c.FADE_DEATH
371                self.arrow.remove_pos(self.player.attacked_enemy)
372            self.enemy_index = 0
373
374    def set_enemy_indices(self):
375        for i, enemy in enumerate(self.enemy_list):
376            enemy.index = i
377
378    def draw_battle(self, surface):
379        """Draw all elements of battle state"""
380        self.background.draw(surface)
381        self.enemy_group.draw(surface)
382        self.attack_animations.draw(surface)
383        self.sword.draw(surface)
384        surface.blit(self.player.image, self.player.rect)
385        surface.blit(self.info_box.image, self.info_box.rect)
386        surface.blit(self.select_box.image, self.select_box.rect)
387        surface.blit(self.arrow.image, self.arrow.rect)
388        self.player_health_box.draw(surface)
389        self.damage_points.draw(surface)
390        self.draw_transition(surface)
391
392    def draw_transition(self, surface):
393        """
394        Fade in and out of state.
395        """
396        if self.state == 'transition in':
397
398            transition_image = pg.Surface(self.transition_rect.size)
399            transition_image.fill(c.TRANSITION_COLOR)
400            transition_image.set_alpha(self.transition_alpha)
401            surface.blit(transition_image, self.transition_rect)
402            self.transition_alpha -= c.TRANSITION_SPEED 
403            if self.transition_alpha <= 0:
404                self.state = c.SELECT_ACTION
405                self.transition_alpha = 0
406
407        elif self.state == 'transition out':
408            transition_image = pg.Surface(self.transition_rect.size)
409            transition_image.fill(c.TRANSITION_COLOR)
410            transition_image.set_alpha(self.transition_alpha)
411            surface.blit(transition_image, self.transition_rect)
412            self.transition_alpha += c.TRANSITION_SPEED 
413            if self.transition_alpha >= 255:
414                self.done = True
415
416    def player_damaged(self, damage):
417        self.game_data['player stats']['health']['current'] -= damage
418
419    def player_healed(self, heal, magic_points=0):
420        """
421        Add health from potion to game data.
422        """
423        health = self.game_data['player stats']['health']
424
425        health['current'] += heal
426        if health['current'] > health['maximum']:
427            health['current'] = health['maximum']
428
429        if self.state == c.DRINK_HEALING_POTION:
430            self.game_data['player inventory']['Healing Potion']['quantity'] -= 1
431            if self.game_data['player inventory']['Healing Potion']['quantity'] == 0:
432                del self.game_data['player inventory']['Healing Potion']
433        elif self.state == c.CURE_SPELL:
434            self.game_data['player stats']['magic']['current'] -= magic_points
435
436    def magic_boost(self, magic_points):
437        """
438        Add magic from ether to game data.
439        """
440        magic = self.game_data['player stats']['magic']
441        magic['current'] += magic_points
442        if magic['current'] > magic['maximum']:
443            magic['current'] = magic['maximum']
444
445        self.game_data['player inventory']['Ether Potion']['quantity'] -= 1
446        if not self.game_data['player inventory']['Ether Potion']['quantity']:
447            del self.game_data['player inventory']['Ether Potion']
448
449    def set_timer_to_current_time(self):
450        """Set the timer to the current time."""
451        self.timer = self.current_time
452
453    def cast_fire_blast(self):
454        """
455        Cast fire blast on all enemies.
456        """
457        self.notify(c.FIRE)
458        self.state = self.info_box.state = c.FIRE_SPELL
459        POWER = self.inventory['Fire Blast']['power']
460        POWER += self.game_data['player stats']['Level'] * 5
461        MAGIC_POINTS = self.inventory['Fire Blast']['magic points']
462        self.game_data['player stats']['magic']['current'] -= MAGIC_POINTS
463        for enemy in self.enemy_list:
464            DAMAGE = random.randint(POWER//2, POWER)
465            self.damage_points.add(
466                attackitems.HealthPoints(DAMAGE, enemy.rect.topright))
467            enemy.health -= DAMAGE
468            posx = enemy.rect.x - 32
469            posy = enemy.rect.y - 64
470            fire_sprite = attack.Fire(posx, posy)
471            self.attack_animations.add(fire_sprite)
472            if enemy.health <= 0:
473                enemy.kill()
474                self.arrow.remove_pos(enemy)
475            else:
476                enemy.enter_knock_back_state()
477        self.enemy_list = [enemy for enemy in self.enemy_list if enemy.health > 0]
478        self.enemy_index = 0
479        self.arrow.index = 0
480        self.arrow.state = 'invisible'
481        self.set_timer_to_current_time()
482
483    def cast_cure(self):
484        """
485        Cast cure spell on player.
486        """
487        self.state = c.CURE_SPELL
488        HEAL_AMOUNT = self.inventory['Cure']['power']
489        MAGIC_POINTS = self.inventory['Cure']['magic points']
490        self.player.healing = True
491        self.set_timer_to_current_time()
492        self.arrow.state = 'invisible'
493        self.enemy_index = 0
494        self.damage_points.add(
495            attackitems.HealthPoints(HEAL_AMOUNT, self.player.rect.topright, False))
496        self.player_healed(HEAL_AMOUNT, MAGIC_POINTS)
497        self.info_box.state = c.DRINK_HEALING_POTION
498        self.notify(c.POWERUP)
499
500    def enter_select_enemy_state(self):
501        """
502        Transition battle into the select enemy state.
503        """
504        self.state = self.arrow.state = c.SELECT_ENEMY
505        self.arrow.index = 0
506
507    def enter_select_item_state(self):
508        """
509        Transition battle into the select item state.
510        """
511        self.state = self.info_box.state = c.SELECT_ITEM
512        self.arrow.become_select_item_state()
513
514    def enter_select_magic_state(self):
515        """
516        Transition battle into the select magic state.
517        """
518        self.state = self.info_box.state = c.SELECT_MAGIC
519        self.arrow.become_select_magic_state()
520
521    def try_to_run_away(self):
522        """
523        Transition battle into the run away state.
524        """
525        self.run_away = True
526        self.arrow.state = 'invisible'
527        self.enemy_index = 0
528        self.enter_enemy_attack_state()
529
530    def enter_enemy_attack_state(self):
531        """
532        Transition battle into the Enemy attack state.
533        """
534        self.state = self.info_box.state = c.ENEMY_ATTACK
535        enemy = self.enemy_list[self.enemy_index]
536        enemy.enter_enemy_attack_state()
537
538    def enter_player_attack_state(self):
539        """
540        Transition battle into the Player attack state.
541        """
542        self.state = self.info_box.state = c.PLAYER_ATTACK
543        enemy_to_attack = self.enemies_to_attack.pop(0)
544        if enemy_to_attack in self.enemy_list:
545            self.player.enter_attack_state(enemy_to_attack)
546        else:
547            if self.enemy_list:
548                self.player.enter_attack_state(self.enemy_list[0])
549            else:
550                self.enter_battle_won_state()
551        self.arrow.state = 'invisible'
552
553    def get_enemy_to_attack(self):
554        """
555        Get enemy for player to attack by arrow position.
556        """
557        enemy_posx = self.arrow.rect.x + 60
558        enemy_posy = self.arrow.rect.y - 20
559        enemy_pos = (enemy_posx, enemy_posy)
560        enemy_to_attack = None
561
562        for enemy in self.enemy_list:
563            if enemy.rect.topleft == enemy_pos:
564                enemy_to_attack = enemy
565
566        return enemy_to_attack
567
568
569    def enter_drink_healing_potion_state(self):
570        """
571        Transition battle into the Drink Healing Potion state.
572        """
573        self.state = self.info_box.state = c.DRINK_HEALING_POTION
574        self.player.healing = True
575        self.set_timer_to_current_time()
576        self.arrow.state = 'invisible'
577        self.enemy_index = 0
578        self.damage_points.add(
579            attackitems.HealthPoints(30,
580                                     self.player.rect.topright,
581                                     False))
582        self.player_healed(30)
583        self.notify(c.POWERUP)
584
585    def enter_drink_ether_potion_state(self):
586        """
587        Transition battle into the Drink Ether Potion state.
588        """
589        self.state = self.info_box.state = c.DRINK_ETHER_POTION
590        self.player.healing = True
591        self.arrow.state = 'invisible'
592        self.enemy_index = 0
593        self.damage_points.add(
594            attackitems.HealthPoints(30,
595                                     self.player.rect.topright,
596                                     False,
597                                     True))
598        self.magic_boost(30)
599        self.set_timer_to_current_time()
600        self.notify(c.POWERUP)
601
602    def enter_select_action_state(self):
603        """
604        Transition battle into the select action state
605        """
606        self.state = self.info_box.state = c.SELECT_ACTION
607        self.arrow.index = 0
608        self.arrow.state = self.state
609
610    def enter_player_damaged_state(self):
611        """
612        Transition battle into the player damaged state.
613        """
614        self.state = self.info_box.state = c.PLAYER_DAMAGED
615        if self.enemy_index > len(self.enemy_list) - 1:
616            self.enemy_index = 0
617        enemy = self.enemy_list[self.enemy_index]
618        player_damage = enemy.calculate_hit(self.inventory['equipped armor'],
619                                            self.inventory)
620        self.damage_points.add(
621            attackitems.HealthPoints(player_damage,
622                                     self.player.rect.topright))
623        self.info_box.set_player_damage(player_damage)
624        self.set_timer_to_current_time()
625        self.player_damaged(player_damage)
626        if player_damage:
627            sfx_num = random.randint(1,3)
628            self.notify('punch{}'.format(sfx_num))
629            self.player.damaged = True
630            self.player.enter_knock_back_state()
631
632    def enter_enemy_damaged_state(self):
633        """
634        Transition battle into the enemy damaged state.
635        """
636        self.state = self.info_box.state = c.ENEMY_DAMAGED
637        enemy_damage = self.player.calculate_hit()
638        self.damage_points.add(
639            attackitems.HealthPoints(enemy_damage,
640                                     self.player.attacked_enemy.rect.topright))
641
642        self.info_box.set_enemy_damage(enemy_damage)
643
644        self.arrow.index = 0
645        self.attack_enemy(enemy_damage)
646        self.set_timer_to_current_time()
647
648    def switch_enemy(self):
649        """
650        Switch which enemy the player is attacking.
651        """
652        if self.enemy_index < len(self.enemy_list) - 1:
653            self.enemy_index += 1
654            self.enter_enemy_attack_state()
655
656    def enter_run_away_state(self):
657        """
658        Transition battle into the run away state.
659        """
660        self.state = self.info_box.state = c.RUN_AWAY
661        self.arrow.state = 'invisible'
662        self.player.state = c.RUN_AWAY
663        self.set_timer_to_current_time()
664
665    def enter_battle_won_state(self):
666        """
667        Transition battle into the battle won state.
668        """
669        self.notify(c.BATTLE_WON)
670        self.state = self.info_box.state = c.BATTLE_WON
671        self.player.state = c.VICTORY_DANCE
672        self.set_timer_to_current_time()
673
674    def enter_show_gold_state(self):
675        """
676        Transition battle into the show gold state.
677        """
678        self.inventory['GOLD']['quantity'] += self.new_gold
679        self.state = self.info_box.state = c.SHOW_GOLD
680        self.set_timer_to_current_time()
681
682    def enter_show_experience_state(self):
683        """
684        Transition battle into the show experience state.
685        """
686        self.state = self.info_box.state = c.SHOW_EXPERIENCE
687        self.set_timer_to_current_time()
688
689    def enter_level_up_state(self):
690        """
691        Transition battle into the LEVEL UP state.
692        """
693        self.state = self.info_box.state = c.LEVEL_UP
694        self.info_box.reset_level_up_message()
695        self.set_timer_to_current_time()
696
697    def enter_two_actions_per_turn_state(self):
698        self.state = self.info_box.state = c.TWO_ACTIONS
699        self.set_timer_to_current_time()
700
701    def execute_player_actions(self):
702        """
703        Execute the player actions.
704        """
705        if self.player_level < 3:
706            if self.player_actions:
707                enter_state = self.player_action_dict[self.player_actions[0]]
708                enter_state()
709                self.player_actions.pop(0)
710        else:
711            if len(self.player_actions) == 2:
712                enter_state = self.player_action_dict[self.player_actions[0]]
713                enter_state()
714                self.player_actions.pop(0)
715                self.action_selected = False
716            else:
717                if self.action_selected:
718                    self.enter_select_action_state()
719                    self.action_selected = False
720
721
722
723
724
725
726
727
728