Began creating battle system; basic skeleton complete.
Justin Armstrong justinmeister@gmail.com
Tue, 08 Apr 2014 23:18:25 -0700
4 files changed,
62 insertions(+),
3 deletions(-)
M
data/components/person.py
→
data/components/person.py
@@ -291,7 +291,6 @@
def __init__(self, direction, x=0, y=0): super(Player, self).__init__('player', x, y, direction) - def create_vector_dict(self): """Return a dictionary of x and y velocities set to direction keys."""@@ -301,7 +300,6 @@ 'left': (-2, 0),
'right': (2, 0)} return vector_dict - def update(self, keys, current_time): """Updates player behavior"""@@ -312,7 +310,6 @@ self.check_for_input()
state_function = self.state_dict[self.state] state_function() self.location = self.get_tile_location() - def check_for_input(self): """Checks for player input"""
M
data/constants.py
→
data/constants.py
@@ -15,6 +15,7 @@ MAGIC_SHOP = 'magic shop'
HOUSE = 'house' OVERWORLD = 'overworld' BROTHER_HOUSE = 'brother_house' +BATTLE = 'battle' ##Colors
M
data/main.py
→
data/main.py
@@ -21,6 +21,7 @@ POTION_SHOP = 'potion shop'
PLAYER_MENU = 'player menu' OVERWORLD = 'overworld' BROTHER_HOUSE = 'brother_house' +BATTLE = 'battle' def main():
A
data/states/battle.py
@@ -0,0 +1,60 @@
+"""This is the state that handles battles against +monsters""" + +import pygame as pg +from .. import tools +from .. components import person +from .. import constants as c + +class Battle(tools._State): + def __init__(self): + super(Battle, self).__init__() + + def startup(self, current_time, game_data): + """Initialize state attributes""" + self.current_time = current_time + 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 + + def make_background(self): + """Make the blue/black background""" + background = pg.sprite.Sprite() + surface = pg.Surface(c.SCREEN_SIZE).convert() + surface.fill(c.BLACK_BLUE) + background.image = surface + background.rect = background.image.get_rect() + background_group = pg.sprite.Group(background) + + return background_group + + def make_enemies(self): + """Make the enemies for the battle. Return sprite group""" + enemy = person.Devil(100, 100, 'down', 'resting') + 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) + player_group = pg.sprite.Group(player) + + return player_group + + def update(self, surface, keys, current_time): + """Update the battle state""" + self.enemy_group.update() + self.player_group.update() + self.menu.update() + self.draw_battle(surface) + + def draw_battle(self, surface): + """Draw all elements of battle state""" + self.background.draw(surface) + self.enemy_group.draw(surface) + self.player_group.draw(surface) + self.menu.draw(surface) +