commit 30e78ca45b2ed27a2d7099495f3b26d563505f0d
parent eae4a0e3713ae0508e05e1d4cdd5eef3766517d2
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Tue, 31 Aug 2021 21:55:41 -0500
some npc work
Diffstat:
3 files changed, 58 insertions(+), 36 deletions(-)
diff --git a/data/boards/testloc1/entities.json b/data/boards/testloc1/entities.json
@@ -1,10 +1,8 @@
{
- "dynamic" : [
- ],
"static" : [
{
"type" : "overlay",
- "cell" : [1, 0],
+ "cell" : [0, 0],
"tile" : [0, 3],
"data" : {
"sprite" : [2, 0],
@@ -15,6 +13,20 @@
"tile" : [0, 1]
}
}
+ },
+ {
+ "type" : "npc",
+ "cell" : [1, 1],
+ "tile" : [0, 0],
+ "data" : {
+ "sprite" : [4, 4],
+ "npc_def" : {
+ "npc_id" : 100,
+ "ai_package" : "wait"
+ }
+ }
}
+ ],
+ "dynamic" : [
]
}
diff --git a/src/board.py b/src/board.py
@@ -55,6 +55,7 @@ class Board(object):
# Entity values
self.statics = pygame.sprite.Group()
+ self.holdovers = pygame.sprite.Group()
self.dynamics = pygame.sprite.Group()
self.overlays = pygame.sprite.Group()
@@ -130,17 +131,18 @@ class Board(object):
"""
# First, setup vals and empty static-only groups
overlay_sheet = self.game.sheets[OVERLAY_SHEET + str(self.scale_factor)].sprites
+ npc_sheet = self.game.sheets["chars" + str(self.scale_factor)].sprites
to_gen = []
self.statics.empty()
self.overlays.empty()
# Next, decide which entities we should actually generate
for e in self.entity_definition["static"]:
- erc = (self.current_cell_coord[0] + e["cell"][0], self.current_cell_coord[1] + e["cell"][1])
+ erc = (e["cell"][0] - self.current_cell_coord[0], e["cell"][1] - self.current_cell_coord[1])
if tuple(e["cell"]) == self.current_cell_coord or (erc in self.adjacent_cells.keys() and self.adjacent_cells[erc] != None):
to_gen.append([e, erc])
- # Lastly, create these entities
+ # Next, create these entities
for i in to_gen:
# First, we must make a proper relative tilepos
if tuple(i[0]["cell"]) == self.current_cell_coord:
@@ -153,6 +155,26 @@ class Board(object):
oe = entity.OverlayEntity(overlay_sheet[tuple(i[0]["data"]["sprite"])], tuple(i[0]["cell"]), tuple(i[0]["tile"]), None, xy, i[0]["data"]["event"])
self.statics.add(oe)
self.overlays.add(oe)
+ elif i[0]["type"] == "npc":
+ make = True
+ for h in self.holdovers:
+ if h.npc_id == i[0]["data"]["npc_def"]["npc_id"]:
+ make = False
+ if make:
+ npce = entity.NPCEntity(npc_sheet[tuple(i[0]["data"]["sprite"])], tuple(i[0]["cell"]), tuple(i[0]["tile"]), None, xy, i[0]["data"]["npc_def"])
+ self.statics.add(npce)
+ self.holdovers.add(npce)
+
+ # Next, re-add holdovers
+ for h in self.holdovers:
+ herc = (h.cellpos[0] - self.current_cell_coord[0], h.cellpos[1] - self.current_cell_coord[1])
+ if (h.cellpos == self.current_cell_coord or (herc in self.adjacent_cells.keys() and self.adjacent_cells[herc] != None)) and h not in self.statics:
+ if h.cellpos == self.current_cell_coord:
+ hxy = h.tilepos
+ else:
+ hxy = (h.tilepos[0] + (herc[0] * self.cell_dimensions[0]), h.tilepos[1] + (herc[1] * self.cell_dimensions[1]))
+ h.relative_tilepos = hxy
+ self.statics.add(h)
def create_dynamic_entities(self):
"""
diff --git a/src/entity.py b/src/entity.py
@@ -79,7 +79,7 @@ class DynamicEntity(Entity):
are not managed by the board at all.
"""
- def __init__(self, image, cellpos, tilepos, pixcolor = None):
+ def __init__(self, image, cellpos, tilepos, pixcolor = None, rel_tilepos = None):
# Parent initialization
super().__init__(image, cellpos, tilepos, pixcolor)
@@ -114,6 +114,16 @@ class Tile(Entity):
"""
self.rect.topleft = ((self.tilepos[0] * self.board.scale_factor) + self.board.position_offset[0] - (self.board.tile_offset[0] * self.board.scale_factor), (self.tilepos[1] * self.board.scale_factor) + self.board.position_offset[1] - (self.board.tile_offset[1] * self.board.scale_factor))
+class PlayerEntity(Entity):
+ """
+ Class that represents the player object.
+ """
+
+ def __init__(self, image, cellpos, tilepos, pixcolor = None):
+
+ # Parent intialization
+ super().__init__(image, cellpos, tilepos, pixcolor)
+
###############################################
# Section 4 - Various StaticEntity Subclasses #
###############################################
@@ -136,46 +146,24 @@ class OverlayEntity(StaticEntity):
# Section 5 - Various DynamicEntity Subclasses #
################################################
-class PlayerEntity(DynamicEntity):
- """
- Class that represents the player object.
- """
-
- def __init__(self, image, cellpos, tilepos, pixcolor = None):
-
- # Parent intialization
- super().__init__(image, cellpos, tilepos, pixcolor)
-
-class NPCEntity(DynamicEntity):
+class NPCEntity(StaticEntity):
"""
Class that represents the non-player character
in locations.
"""
- def __init__(self, image, cellpos, tilepos, pixcolor = None, npc_def = {}):
+ def __init__(self, image, cellpos, tilepos, pixcolor = None, rel_tilepos = None, npc_def = {}):
# Parent intialization
- super().__init__(image, cellpos, tilepos, pixcolor)
+ super().__init__(image, cellpos, tilepos, pixcolor, rel_tilepos)
# Definition vals
self.definition = npc_def
+ self.npc_id = npc_def["npc_id"]
+ self.ai_package = npc_def["ai_package"]
- def get_conversation_string(self, convo_option = None, flags = None):
- """
- Return the conversation string associated
- with this NPC, checking progress flags for
- any modifications.
- """
- # TODO: The way convo trees should work should be recursive. Each NPC flag
- # could be associated with a unique string that could be keyed to a line
- # in the npc_def's convos dict. This dict could have at least one key
- # called 'default' and one or more others with a unique name, each being
- # associated with a flag that is defined as part of the scenario. Each
- # of these keys will have a 'default' key and associated convo string,
- # along with one or more other keys ALSO associated with named flags.
- # The convo tree should then be read recursively, and this would allow
- # there to be a true heirarchy of conversations.
- # NOTE: Maybe this is a bad/half-baked idea... Convo options should be taken
- # into account...
+ def move_by_tile_offset(self):
pass
+ def process_ai_package(self):
+ pass