all repos — Legends-RPG @ 322ed0813ca073c324e0476bbf9412b05c1d71e0

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"""
 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
22    def make_background(self):
23        """Make the blue/black background"""
24        background = pg.sprite.Sprite()
25        surface = pg.Surface(c.SCREEN_SIZE).convert()
26        surface.fill(c.BLACK_BLUE)
27        background.image = surface
28        background.rect = background.image.get_rect()
29        background_group = pg.sprite.Group(background)
30
31        return background_group
32
33    def make_enemies(self):
34        """Make the enemies for the battle. Return sprite group"""
35        enemy = person.Devil(100, 100, 'down', 'resting')
36        group = pg.sprite.Group(enemy)
37
38        return group
39
40    def make_player(self):
41        """Make the sprite for the player's character"""
42        player = person.Player('left', 300, 300)
43        player_group = pg.sprite.Group(player)
44
45        return player_group
46
47    def update(self, surface, keys, current_time):
48        """Update the battle state"""
49        self.enemy_group.update()
50        self.player_group.update()
51        self.menu.update()
52        self.draw_battle(surface)
53
54    def draw_battle(self, surface):
55        """Draw all elements of battle state"""
56        self.background.draw(surface)
57        self.enemy_group.draw(surface)
58        self.player_group.draw(surface)
59        self.menu.draw(surface)
60