data/states/battle.py (view raw)
1"""This is the state that handles battles against
2monsters"""
3
4import pygame as pg
5from .. import tools, setup
6from .. components import person
7from .. import constants as c
8
9class Battle(tools._State):
10 def __init__(self):
11 super(Battle, self).__init__()
12
13 def startup(self, current_time, game_data):
14 """Initialize state attributes"""
15 self.current_time = current_time
16 self.game_data = game_data
17 self.background = self.make_background()
18 self.enemy_group = self.make_enemies()
19 self.player_group = self.make_player()
20 self.battle_info = BattleInfo()
21 self.select_box = SelectBox()
22 self.name = 'battle'
23 self.next = game_data['last state']
24
25 def make_background(self):
26 """Make the blue/black background"""
27 background = pg.sprite.Sprite()
28 surface = pg.Surface(c.SCREEN_SIZE).convert()
29 surface.fill(c.BLACK_BLUE)
30 background.image = surface
31 background.rect = background.image.get_rect()
32 background_group = pg.sprite.Group(background)
33
34 return background_group
35
36 def make_enemies(self):
37 """Make the enemies for the battle. Return sprite group"""
38 enemy = person.Person('devil', 100, 220, 'down', 'battle resting')
39 enemy.image = pg.transform.scale2x(enemy.image)
40 group = pg.sprite.Group(enemy)
41
42 return group
43
44 def make_player(self):
45 """Make the sprite for the player's character"""
46 player = person.Player('left', 630, 220, 'battle resting', 1)
47 player.image = pg.transform.scale2x(player.image)
48 player_group = pg.sprite.Group(player)
49
50 return player_group
51
52 def make_state_dict(self):
53 """
54 Make the dictionary of states the battle can be in.
55 """
56 state_dict = {'select action': self.select_action,
57 'select enemy': self.select_enemy,
58 'enemy attack': self.enemy_attack,
59 'player attack': self.player_attack,
60 'run away': self.run_away}
61
62 def select_action(self):
63 """
64 Select player action, of either attack, item, magic, run away.
65 """
66 pass
67
68 def select_enemy(self):
69 """
70 Select enemy you wish to attack.
71 """
72 pass
73
74 def enemy_attack(self):
75 """
76 Enemies, each in turn, attack the player.
77 """
78 pass
79
80 def player_attack(self):
81 """
82 Player attacks enemy
83 """
84 pass
85
86 def run_away(self):
87 """
88 Player attempts to run away.
89 """
90 pass
91
92 def update(self, surface, keys, current_time):
93 """Update the battle state"""
94 self.check_input(keys)
95 self.enemy_group.update(current_time)
96 self.player_group.update(keys, current_time)
97 #self.menu.update()
98 self.draw_battle(surface)
99
100 def check_input(self, keys):
101 """
102 Check user input to navigate GUI.
103 """
104 if keys[pg.K_SPACE]:
105 self.game_data['last state'] = self.name
106 self.done = True
107
108 def draw_battle(self, surface):
109 """Draw all elements of battle state"""
110 self.background.draw(surface)
111 self.enemy_group.draw(surface)
112 self.player_group.draw(surface)
113 surface.blit(self.battle_info.image, self.battle_info.rect)
114 surface.blit(self.select_box.image, self.select_box.rect)
115
116
117class BattleInfo(object):
118 """
119 Info box that describes attack damage and other battle
120 related information.
121 """
122 def __init__(self):
123 self.image = setup.GFX['shopbox']
124 self.rect = self.image.get_rect(bottom=608)
125
126
127class SelectBox(object):
128 """
129 Box to select whether to attack, use item, use magic or run away.
130 """
131 def __init__(self):
132 self.image = setup.GFX['goldbox']
133 self.rect = self.image.get_rect(bottom=608, right=800)
134
135