made wounds that flash the background red when an entity is attacked

This commit is contained in:
troido 2018-01-12 15:49:37 +01:00
parent 20570c3cdb
commit 5c9364a64b
7 changed files with 48 additions and 13 deletions

View File

@ -89,7 +89,6 @@ If you don't know how to help, [I made a list of suggestions on how to help](doc
## TODO first
- write howto for entity creation
- red background flash when attacked
- reconsider getters and setters
- show adjacent objects
- have a difference between ground-like items and interesting items
@ -120,6 +119,7 @@ If you don't know how to help, [I made a list of suggestions on how to help](doc
## DONE
- red background flash when attacked
- document map format
- world chat
- chat scrolling

View File

@ -32,6 +32,7 @@
"entry": ["%", 7],
"fence": ["#", 3],
"armour": ["[", 7],
"wound": [" ", 7, 1],
" ": [" ", 7]
},
"default": ["?", 7],

View File

@ -32,6 +32,7 @@
"entry": ["", 7],
"fence": ["", 3],
"armour": ["", 7],
"wound": [" ", 7, 1],
" ": [" ", 7]
},
"default": ["", 7],

View File

@ -2,6 +2,7 @@ from .. import timeout
from asciifarm.common import utils
import random
from .component import Component
from .. import gameobjects
class Fighter(Component):
@ -19,6 +20,7 @@ class Fighter(Component):
obj.addListener("roomjoin", self.roomJoin)
def roomJoin(self, o, roomData):
self.roomData = roomData
self.fightEvent = roomData.getEvent("fight")
self.updateEvent = roomData.getEvent("update")
self.timeout = timeout.Timeout(roomData.getEvent("update"), self.slowness)
@ -29,6 +31,11 @@ class Fighter(Component):
self.owner.trigger("damage" if damage >= 0 else "heal", attacker, abs(damage))
# should this be it's own component? ('bleeding' for example)
if damage > 0:
obj = gameobjects.makeEntity("wound", self.roomData, 4, self.owner.getHeight() - 0.01)
obj.place(self.owner.getGround())
if self.isDead():
self.die(attacker)

View File

@ -0,0 +1,31 @@
from .. import timeout
from .component import Component
class Volatile(Component):
def __init__(self, duration):
self.duration = duration
def attach(self, obj):
self.owner = obj
obj.addListener("roomjoin", self.roomJoin)
def roomJoin(self, o, roomData):
self.roomData = roomData
self.timeout = timeout.Timeout(roomData.getEvent("update"), self.duration, self.end)
def end(self, to):
self.owner.remove()
def remove(self):
self.timeout.remove()
def toJSON(self):
# better not to save volatile entities in the first place...
return {
"duration": self.duration
}

View File

@ -18,6 +18,7 @@ from .components.build import Build
from .components.harvest import Harvest
from .components.food import Food
from .components.equippable import Equippable
from .components.volatile import Volatile
""" This module contains factory functions for many placable entities, and a make function to call a factory by a string name """
@ -94,32 +95,21 @@ entities["plant"] = lambda: Entity(sprite="plant", height=1.2, components={
entities["food"] = lambda: Entity(sprite="food", height=0.2, components={"item": Food(20)})
#def makeSeed():
#return Entity(sprite="seed", height=0.3, components={"item": Build("sownseed", flagsNeeded={"soil"})})
entities["seed"] = lambda: Entity(sprite="seed", height=0.3, components={"item": Build("sownseed", flagsNeeded={"soil"})})
#def makeBuiltWall():
#return Entity(sprite="wall", height=2, components={"fighter": Fighter(maxHealth=100, strength=0), "alignment": Alignment(faction.NONE), "loot": Loot([("stone", 1)])}, flags={"solid"})
entities["builtwall"] = lambda: Entity(
sprite="wall", height=2, flags={"solid"}, components={
"fighter": Fighter(maxHealth=100, strength=0),
"alignment": Alignment(faction.NONE),
"loot": Loot([("stone", 1)])})
#def makeSword():
#return Entity(sprite="sword", height=0.5, components={"item": Equippable("hand", {"strength": 5})})
entities["sword"] = lambda: Entity(sprite="sword", height=0.5, components={"item": Equippable("hand", {"strength": 5})})
#def makeClub():
#return Entity(sprite="club", height=0.5, components={"item": Equippable("hand", {"strength": 3})})
entities["club"] = lambda: Entity(sprite="club", height=0.5, components={"item": Equippable("hand", {"strength": 3})})
#def makeArmour():
#return Entity(sprite="armour", height=0.5, components={"item": Equippable("body", {"defense": 100})})
entities["armour"] = lambda: Entity(sprite="armour", height=0.5, components={"item": Equippable("body", {"defense": 100})})
entities["wound"] = lambda duration=4, height=0.2: Entity(sprite="wound", height=height, components={"volatile": Volatile(duration)})
def makeEntity(entType, roomData, *args, preserve=False, **kwargs):
entity = entities[entType](*args, **kwargs)

View File

@ -1,4 +1,9 @@
# this package is not used, but it is important that it is imported before any component modules
# importing components before gameobjects is loaded will result in a cyclic dependency problem
from . import gameobjects
from .components.inventory import Inventory
from .components.inputcontroller import InputController
from .components.move import Move