Add lighting scroll
This commit is contained in:
parent
d8654e5db5
commit
5b5f49bf6b
3
color.py
3
color.py
@ -1,8 +1,11 @@
|
||||
white = (0xFF, 0xFF, 0xFF)
|
||||
black = (0x0, 0x0, 0x0)
|
||||
red = (0xFF, 0x0, 0x0)
|
||||
|
||||
player_atk = (0xE0, 0xE0, 0xE0)
|
||||
enemy_atk = (0xFF, 0xC0, 0xC0)
|
||||
needs_target = (0x3F, 0xFF, 0xFF)
|
||||
status_effect_applied = (0x3F, 0xFF, 0x3F)
|
||||
|
||||
player_die = (0xFF, 0x30, 0x30)
|
||||
enemy_die = (0xFF, 0xA0, 0x30)
|
||||
|
@ -50,3 +50,31 @@ class HealingConsumable(Consumable):
|
||||
self.consume()
|
||||
else:
|
||||
raise Impossible(f"Your health is already full.")
|
||||
|
||||
|
||||
class LightningDamageConsumable(Consumable):
|
||||
def __init__(self, damage: int, maximum_range: int):
|
||||
self.damage = damage
|
||||
self.maximum_range = maximum_range
|
||||
|
||||
def activate(self, action: actions.ItemAction) -> None:
|
||||
consumer = action.entity
|
||||
target = None
|
||||
closest_distance = self.maximum_range + 1.0
|
||||
|
||||
for actor in self.engine.game_map.actors:
|
||||
if actor is not consumer and self.parent.gamemap.visible[actor.x, actor.y]:
|
||||
distance = consumer.distance(actor.x, actor.y)
|
||||
|
||||
if distance < closest_distance:
|
||||
target = actor
|
||||
closest_distance = distance
|
||||
|
||||
if target:
|
||||
self.engine.message_log.add_message(
|
||||
f"A lightning bolt stikes the {target.name} with a loud thunder, for {self.damage} damage!"
|
||||
)
|
||||
target.fighter.take_damage(self.damage)
|
||||
self.consume()
|
||||
else:
|
||||
raise Impossible("No enemy is close enough to strike.")
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import math
|
||||
from typing import Optional, Tuple, Type, TypeVar, TYPE_CHECKING, Union
|
||||
|
||||
from render_order import RenderOrder
|
||||
@ -70,6 +71,12 @@ class Entity:
|
||||
self.parent = gamemap
|
||||
gamemap.entities.add(self)
|
||||
|
||||
def distance(self, x: int, y: int) -> float:
|
||||
"""
|
||||
Return the distance between the current entity and the given (x,y) coordinate.
|
||||
"""
|
||||
return math.sqrt((x - self.x) ** 2 + (y - self.y) ** 2)
|
||||
|
||||
def move(self, dx: int, dy: int):
|
||||
# Move the entity by a given amount
|
||||
self.x += dx
|
||||
|
@ -1,5 +1,5 @@
|
||||
from components.ai import HostileEnemy
|
||||
from components.consumable import HealingConsumable
|
||||
from components import consumable
|
||||
from components.fighter import Fighter
|
||||
from components.inventory import Inventory
|
||||
from entity import Actor, Item
|
||||
@ -19,7 +19,7 @@ orc = Actor(
|
||||
name="Orc",
|
||||
ai_cls=HostileEnemy,
|
||||
fighter=Fighter(hp=10, defense=0, power=3),
|
||||
inventory=Inventory(capacity=0)
|
||||
inventory=Inventory(capacity=0),
|
||||
)
|
||||
troll = Actor(
|
||||
char="T",
|
||||
@ -27,12 +27,19 @@ troll = Actor(
|
||||
name="Troll",
|
||||
ai_cls=HostileEnemy,
|
||||
fighter=Fighter(hp=16, defense=1, power=4),
|
||||
inventory=Inventory(capacity=0)
|
||||
inventory=Inventory(capacity=0),
|
||||
)
|
||||
|
||||
health_potion = Item(
|
||||
char="!",
|
||||
color=(127, 0, 255),
|
||||
name="Health Potion",
|
||||
consumable=HealingConsumable(amount=4)
|
||||
consumable=consumable.HealingConsumable(amount=4),
|
||||
)
|
||||
|
||||
lightning_scroll = Item(
|
||||
char="~",
|
||||
color=(255, 255, 0),
|
||||
name="Lightning Scroll",
|
||||
consumable=consumable.LightningDamageConsumable(damage=20, maximum_range=5),
|
||||
)
|
||||
|
@ -66,7 +66,12 @@ def place_entities(
|
||||
y = random.randint(room.y1 + 1, room.y2 - 1)
|
||||
|
||||
if not any(entity.x == x and entity.y == y for entity in dungeon.entities):
|
||||
item_chance = random.random()
|
||||
|
||||
if item_chance < 0.7:
|
||||
entity_factories.health_potion.spawn(dungeon, x, y)
|
||||
else:
|
||||
entity_factories.lightning_scroll.spawn(dungeon, x, y)
|
||||
|
||||
|
||||
def tunnel_between(start: Tuple[int, int], end: Tuple[int, int]) -> Iterator[Tuple[int, int]]:
|
||||
|
Loading…
Reference in New Issue
Block a user