added traps and HP-Postions
This commit is contained in:
parent
96895c5ce5
commit
23d95c4b2f
2 changed files with 30 additions and 7 deletions
|
|
@ -12,7 +12,7 @@ from tcod.event import KeySym
|
||||||
from tcod.map import Map
|
from tcod.map import Map
|
||||||
|
|
||||||
import g
|
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.constants import DIRECTION_KEYS, ACTION_KEYS, FLOOR_CHAR
|
||||||
from game.screens import Push, Screen, ScreenResult
|
from game.screens import Push, Screen, ScreenResult
|
||||||
from game.tags import IsWalllike, IsItem, IsPlayer, IsActor
|
from game.tags import IsWalllike, IsItem, IsPlayer, IsActor
|
||||||
|
|
@ -39,12 +39,21 @@ def _handle_movement(player, map, dir):
|
||||||
player.components[Position] = new_pos
|
player.components[Position] = new_pos
|
||||||
_recalc_fov(new_pos)
|
_recalc_fov(new_pos)
|
||||||
|
|
||||||
# Auto pickup gold
|
# Auto pickup items
|
||||||
for gold in g.world.Q.all_of(components=[Gold], tags=[player.components[Position], IsItem]):
|
for gold in g.world.Q.all_of(components=[Gold], tags=[new_pos, IsItem]):
|
||||||
player.components[Gold] += gold.components[Gold]
|
player.components[Gold] += gold.components[Gold]
|
||||||
text = f"Picked up {gold.components[Gold]}g, total: {player.components[Gold]}g"
|
text = f"Picked up {gold.components[Gold]}g, total: {player.components[Gold]}g"
|
||||||
g.world[None].components[("Text", str)] = text
|
g.world[None].components[("Text", str)] = text
|
||||||
gold.clear()
|
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):
|
def _handle_action(player):
|
||||||
for entity in g.world.Q.all_of(components=[Action, Position]):
|
for entity in g.world.Q.all_of(components=[Action, Position]):
|
||||||
|
|
@ -126,5 +135,8 @@ class MainScreen(Screen):
|
||||||
# draw the player
|
# draw the player
|
||||||
for player in g.world.Q.all_of(tags=[IsPlayer]):
|
for player in g.world.Q.all_of(tags=[IsPlayer]):
|
||||||
_draw_entity(player, camera_pos, w, h)
|
_draw_entity(player, camera_pos, w, h)
|
||||||
|
|
||||||
if text := g.world[None].components.get(("Text", str)):
|
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))
|
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))
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from tcod.map import Map
|
||||||
|
|
||||||
import g
|
import g
|
||||||
|
|
||||||
from game.components import Action, Gold, Graphic, Position
|
from game.components import HP, Action, Gold, Graphic, Position
|
||||||
from game.tags import IsActor, IsItem, IsPlayer, IsWalllike
|
from game.tags import IsActor, IsItem, IsPlayer, IsWalllike
|
||||||
|
|
||||||
world_center: Final = Position(50, 50)
|
world_center: Final = Position(50, 50)
|
||||||
|
|
@ -51,7 +51,8 @@ def new_world() -> Registry:
|
||||||
components={
|
components={
|
||||||
Position: player_pos,
|
Position: player_pos,
|
||||||
Graphic: Graphic(ch=ord('@'), fg=(255, 0, 0, 255), bg=(255, 255, 255, 0)),
|
Graphic: Graphic(ch=ord('@'), fg=(255, 0, 0, 255), bg=(255, 255, 255, 0)),
|
||||||
Gold: 0
|
Gold: 0,
|
||||||
|
HP: 100,
|
||||||
},
|
},
|
||||||
tags=[IsActor, IsPlayer]
|
tags=[IsActor, IsPlayer]
|
||||||
)
|
)
|
||||||
|
|
@ -59,7 +60,8 @@ def new_world() -> Registry:
|
||||||
world.new_entity(
|
world.new_entity(
|
||||||
components={
|
components={
|
||||||
Position: Position(0, 5),
|
Position: Position(0, 5),
|
||||||
Graphic: Graphic(ch=ord('G'), fg=(100,100,0, 255))
|
Graphic: Graphic(ch=ord('G'), fg=(100,100,0, 255)),
|
||||||
|
HP: 20,
|
||||||
},
|
},
|
||||||
tags=[IsActor]
|
tags=[IsActor]
|
||||||
)
|
)
|
||||||
|
|
@ -69,10 +71,19 @@ def new_world() -> Registry:
|
||||||
components={
|
components={
|
||||||
Position: Position(rng.randint(0, 20), rng.randint(0, 20)),
|
Position: Position(rng.randint(0, 20), rng.randint(0, 20)),
|
||||||
Graphic: Graphic(ord("$"), fg=(255, 255, 0, 255)),
|
Graphic: Graphic(ord("$"), fg=(255, 255, 0, 255)),
|
||||||
Gold: rng.randint(1, 10)
|
Gold: rng.randint(1, 10),
|
||||||
},
|
},
|
||||||
tags=[IsItem]
|
tags=[IsItem]
|
||||||
)
|
)
|
||||||
|
if rng.choice([True, False]):
|
||||||
|
world.new_entity(
|
||||||
|
components={
|
||||||
|
Position: Position(rng.randint(0, 10), rng.randint(0, 20)),
|
||||||
|
Graphic: Graphic(ord("t"), (255, 0, 0, 255)),
|
||||||
|
HP: rng.randint(-5, 5),
|
||||||
|
},
|
||||||
|
tags=[IsItem]
|
||||||
|
)
|
||||||
|
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
if i == 5 or i == 9:
|
if i == 5 or i == 9:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue