data/states/battle.py (view raw)
1"""This is the state that handles battles against
2monsters"""
3
4import pygame as pg
5from .. import tools
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.menu = None
21 self.name = 'battle'
22 self.next = game_data['last state']
23
24 def make_background(self):
25 """Make the blue/black background"""
26 background = pg.sprite.Sprite()
27 surface = pg.Surface(c.SCREEN_SIZE).convert()
28 surface.fill(c.BLACK_BLUE)
29 background.image = surface
30 background.rect = background.image.get_rect()
31 background_group = pg.sprite.Group(background)
32
33 return background_group
34
35 def make_enemies(self):
36 """Make the enemies for the battle. Return sprite group"""
37 enemy = person.Person('devil', 100, 100, 'down', 'battle resting')
38 group = pg.sprite.Group(enemy)
39
40 return group
41
42 def make_player(self):
43 """Make the sprite for the player's character"""
44 player = person.Player('left', 300, 300, 'battle resting')
45 player_group = pg.sprite.Group(player)
46
47 return player_group
48
49 def update(self, surface, keys, current_time):
50 """Update the battle state"""
51 self.check_input(keys)
52 self.enemy_group.update(current_time)
53 self.player_group.update(keys, current_time)
54 #self.menu.update()
55 self.draw_battle(surface)
56
57 def check_input(self, keys):
58 """
59 Check user input to navigate GUI.
60 """
61 if keys[pg.K_SPACE]:
62 self.game_data['last state'] = self.name
63 self.done = True
64
65 def draw_battle(self, surface):
66 """Draw all elements of battle state"""
67 self.background.draw(surface)
68 self.enemy_group.draw(surface)
69 self.player_group.draw(surface)
70 #self.menu.draw(surface)
71