commit 00161bf6cec802552de80acb033e09a17539c2cf
parent 7fd2cbbd3505ec839b2cc8d428273c506ff2c0c9
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Sun, 3 Oct 2021 13:30:30 -0500
checkpoint for battles
Diffstat:
4 files changed, 59 insertions(+), 22 deletions(-)
diff --git a/data/dungeons/testdun1/encounters.json b/data/dungeons/testdun1/encounters.json
@@ -11,6 +11,8 @@
"sheet" : "enemies_battle1",
"sprite" : [0, 0],
"color" : 9,
+ "row" : 0,
+ "position" : 0,
"level" : 1,
"xp" : 0,
"hp" : 100,
@@ -35,6 +37,8 @@
"sheet" : "enemies_battle1",
"sprite" : [0, 0],
"color" : 9,
+ "row" : 0,
+ "position" : 0,
"level" : 1,
"xp" : 0,
"hp" : 100,
diff --git a/src/battle.py b/src/battle.py
@@ -0,0 +1,46 @@
+import pygame, random
+from . import entity
+from .gamelib import *
+
+#############
+# battle.py #
+#############
+
+# This file contains:
+# 1. The Battle class, which is an abstract representation of an in-game battle.
+
+#############################
+# Section 1 - Battle object #
+#############################
+
+class Battle(object):
+ """
+ The Battle object represents an encounter
+ in either a dungeon or in the overworld
+ with a group of enemies. It handles turn
+ order, enemies and players taking turns,
+ and battle conclusions including doling
+ out exp gains. It also draws the sprites
+ for players and enemies, taking over the
+ former responsiblity from the Game object
+ while in a dungeon.
+ """
+
+ def __init__(self, game, player_party, enemy_party):
+
+ # Saved vals
+ self.player_party_definition = player_party
+ self.enemy_party_definition = enemy_party
+
+ # Groups and sprites
+ self.draw_group = pygame.sprite.Group()
+ self.player_party_group = pygame.sprite.Group()
+ self.enemy_party_group = pygame.sprite.Group()
+
+ # Initialize the group members
+ for p in self.player_party_definition:
+ pg = entity.CustomSprite(self.game.sheets[self.player_party_definition[p]["party_sheet"]].sprites[tuple(self.player_party_definition[p]["party_sprite"])], (self.game.viewport_rect.left + (256 * self.player_party_definition[p]["position"]), self.game.viewport_rect.center[1] + (48 * self.player_party_definition[p]["row"])), self.player_party_definition[p]["color"])
+ self.player_party_group.add(pg)
+ for e in self.enemy_party_definition:
+ eg = entity.CustomSprite(self.game.sheets[self.enemy_party_definition[p]["sheet"]].sprites[tuple(self.enemy_party_definition[p]["sprite"])], (self.game.viewport_rect.left + (256 * self.enemy_party_definition[p]["position"]), self.enemy.viewport_rect.center[1] + (48 * self.enemy_party_definition[p]["row"])), self.enemy_party_definition[p]["color"])
+
diff --git a/src/entity.py b/src/entity.py
@@ -8,10 +8,9 @@ from .gamelib import *
# This file contains:
# 1. The 'CustomSprite' object, which is a simple extension of the pygame Sprite object.
# 2. The 'Entity' object that is the extension of pygame.Sprite used throughout the game on the board.
-# 3. The 'StaticEntity' and 'DynamicEntity' classes, which inherit directly from Entity and are characterized by how the board handles them.
+# 3. The 'StaticEntity' class, which inherits directly from Entity and is characterized by how the board handles it.
# 4. Various other entity classes that inherit directly from Entity.
# 5. Various StaticEntity subclasses.
-# 6. Various DynamicEntity subclasses.
######################################
# Section 1 - The CustonSprite class #
@@ -81,9 +80,9 @@ class Entity(CustomSprite):
if surface != None and viewport != None and self.rect.colliderect(viewport):
surface.blit(self.image, self.rect)
-##############################################
-# Section 3 - StaticEntity and DynamicEntity #
-##############################################
+############################
+# Section 3 - StaticEntity #
+############################
class StaticEntity(Entity):
"""
@@ -106,18 +105,6 @@ class StaticEntity(Entity):
"""
self.rect.topleft = ((self.relative_tilepos[0] * scale) + posoff[0] - (tileoff[0] * scale), (self.relative_tilepos[1] * scale) + posoff[1] - (tileoff[1] * scale))
-class DynamicEntity(Entity):
- """
- DynamicEntity is a class for objects that must
- be managed in specific ways by the board, or that
- are not managed by the board at all.
- """
-
- def __init__(self, image, cellpos, tilepos, pixcolor = None, rel_tilepos = None):
-
- # Parent initialization
- super().__init__(image, cellpos, tilepos, pixcolor)
-
#########################################
# Section 4 - Various Entity Subclasses #
#########################################
@@ -176,10 +163,6 @@ class OverlayEntity(StaticEntity):
# Other vals
self.event = event
-################################################
-# Section 6 - Various DynamicEntity Subclasses #
-################################################
-
class NPCEntity(StaticEntity):
"""
Class that represents the non-player character
diff --git a/src/game.py b/src/game.py
@@ -1,5 +1,5 @@
import pygame, os, json
-from . import interface, images, board, entity, ui, message, dungeon
+from . import interface, images, board, entity, ui, message, dungeon, battle
from .gamelib import *
###########
@@ -338,6 +338,10 @@ class Game(object):
self.message_board.post(text, self.gamedata)
def trigger_battle(self, partydef):
+ """
+ Trigger a battle with the given party
+ definition.
+ """
pass
def update_dynamic_ui(self, surface = None):