added traps and HP-Postions

This commit is contained in:
Lukas Nöllemeyer 2024-08-21 18:14:56 +02:00
parent 96895c5ce5
commit 23d95c4b2f
2 changed files with 30 additions and 7 deletions

View file

@ -12,7 +12,7 @@ from tcod.event import KeySym
from tcod.map import Map
import g
from game.components import Action, Gold, Graphic, Position
from game.components import HP, Action, Gold, Graphic, Position
from game.constants import DIRECTION_KEYS, ACTION_KEYS, FLOOR_CHAR
from game.screens import Push, Screen, ScreenResult
from game.tags import IsWalllike, IsItem, IsPlayer, IsActor
@ -39,12 +39,21 @@ def _handle_movement(player, map, dir):
player.components[Position] = new_pos
_recalc_fov(new_pos)
# Auto pickup gold
for gold in g.world.Q.all_of(components=[Gold], tags=[player.components[Position], IsItem]):
# Auto pickup items
for gold in g.world.Q.all_of(components=[Gold], tags=[new_pos, IsItem]):
player.components[Gold] += gold.components[Gold]
text = f"Picked up {gold.components[Gold]}g, total: {player.components[Gold]}g"
g.world[None].components[("Text", str)] = text
gold.clear()
for hp in g.world.Q.all_of(components=[HP, Position], tags=[new_pos, IsItem]):
h_p = hp.components[HP]
player.components[HP] += hp.components[HP]
text = f"You stepped into a trap and took {-h_p} HP damage"
if h_p > 0:
text = f"You found a Poition and gained {h_p} HP"
text += f", you now have {player.components[HP]} HP"
g.world[None].components[("HP_Text", str)] = text
hp.clear()
def _handle_action(player):
for entity in g.world.Q.all_of(components=[Action, Position]):
@ -126,5 +135,8 @@ class MainScreen(Screen):
# draw the player
for player in g.world.Q.all_of(tags=[IsPlayer]):
_draw_entity(player, camera_pos, w, h)
if text := g.world[None].components.get(("Text", str)):
console.print(x=0, y=console.height - 1, string=text, fg=(255, 255, 255), bg=(0, 0, 0))
if hp_text := g.world[None].components.get(("HP_Text", str)):
console.print(x=0, y=console.height - 2, string=hp_text, fg=(255, 255, 255), bg=(0, 0, 0))