Added text boxes to battle scene and started figuring out what states I'll need. Exciting stuff.
Justin Armstrong justinmeister@gmail.com
Tue, 15 Apr 2014 23:15:51 -0700
4 files changed,
74 insertions(+),
10 deletions(-)
M
data/collision.py
→
data/collision.py
@@ -97,7 +97,7 @@ def check_for_battle(self):
""" Switch scene to battle 1/5 times if battles are allowed. """ - random_number = random.randint(0, 5) + random_number = random.randint(0, 3) if random_number == 0: self.level.switch_to_battle = True
M
data/components/person.py
→
data/components/person.py
@@ -298,8 +298,8 @@ """
User controlled character. """ - def __init__(self, direction, x=0, y=0, state='resting'): - super(Player, self).__init__('player', x, y, direction, state) + def __init__(self, direction, x=0, y=0, state='resting', index=0): + super(Player, self).__init__('player', x, y, direction, state, index) def create_vector_dict(self): """Return a dictionary of x and y velocities set to
M
data/states/battle.py
→
data/states/battle.py
@@ -2,7 +2,7 @@ """This is the state that handles battles against
monsters""" import pygame as pg -from .. import tools +from .. import tools, setup from .. components import person from .. import constants as c@@ -17,7 +17,8 @@ self.game_data = game_data
self.background = self.make_background() self.enemy_group = self.make_enemies() self.player_group = self.make_player() - self.menu = None + self.battle_info = BattleInfo() + self.select_box = SelectBox() self.name = 'battle' self.next = game_data['last state']@@ -34,18 +35,60 @@ return background_group
def make_enemies(self): """Make the enemies for the battle. Return sprite group""" - enemy = person.Person('devil', 100, 100, 'down', 'battle resting') + enemy = person.Person('devil', 100, 220, 'down', 'battle resting') + enemy.image = pg.transform.scale2x(enemy.image) group = pg.sprite.Group(enemy) return group def make_player(self): """Make the sprite for the player's character""" - player = person.Player('left', 300, 300, 'battle resting') + player = person.Player('left', 630, 220, 'battle resting', 1) + player.image = pg.transform.scale2x(player.image) player_group = pg.sprite.Group(player) return player_group + def make_state_dict(self): + """ + Make the dictionary of states the battle can be in. + """ + state_dict = {'select action': self.select_action, + 'select enemy': self.select_enemy, + 'enemy attack': self.enemy_attack, + 'player attack': self.player_attack, + 'run away': self.run_away} + + def select_action(self): + """ + Select player action, of either attack, item, magic, run away. + """ + pass + + def select_enemy(self): + """ + Select enemy you wish to attack. + """ + pass + + def enemy_attack(self): + """ + Enemies, each in turn, attack the player. + """ + pass + + def player_attack(self): + """ + Player attacks enemy + """ + pass + + def run_away(self): + """ + Player attempts to run away. + """ + pass + def update(self, surface, keys, current_time): """Update the battle state""" self.check_input(keys)@@ -67,5 +110,26 @@ """Draw all elements of battle state"""
self.background.draw(surface) self.enemy_group.draw(surface) self.player_group.draw(surface) - #self.menu.draw(surface) + surface.blit(self.battle_info.image, self.battle_info.rect) + surface.blit(self.select_box.image, self.select_box.rect) + + +class BattleInfo(object): + """ + Info box that describes attack damage and other battle + related information. + """ + def __init__(self): + self.image = setup.GFX['shopbox'] + self.rect = self.image.get_rect(bottom=608) + + +class SelectBox(object): + """ + Box to select whether to attack, use item, use magic or run away. + """ + def __init__(self): + self.image = setup.GFX['goldbox'] + self.rect = self.image.get_rect(bottom=608, right=800) +
M
data/states/levels.py
→
data/states/levels.py
@@ -200,10 +200,10 @@ """
Update level normally. """ self.check_for_dialogue() - self.check_for_portals() self.player.update(keys, current_time) self.sprites.update(current_time) self.collision_handler.update(keys, current_time) + self.check_for_portals() self.check_for_battle() self.dialogue_handler.update(keys, current_time) self.check_for_menu(keys)@@ -227,7 +227,7 @@ """
Check if the flag has been made true, indicating to switch state to a battle. """ - if self.switch_to_battle and self.allow_battles: + if self.switch_to_battle and self.allow_battles and not self.done: self.player.location = self.player.get_tile_location() self.update_game_data() self.next = 'battle'