diff options
author | Griffin Smith <root@gws.fyi> | 2019-07-14T18·29-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-07-14T18·29-0400 |
commit | e7ad87c7301f266dece36e7558c0f212e370aac6 (patch) | |
tree | 7da150d5648cc0b17d973bf4a30673f36b20be82 /src/entities/creature.rs | |
parent | 081146da30bcf1a17d9533c3dc9c735a3a558165 (diff) |
Add (statically-included) entity raws
Add a system for statically-included entity raws (which necessitated making a deserializable existential Color struct) and test it out by initializing the game (for now) with a single on-screen gormlak.
Diffstat (limited to 'src/entities/creature.rs')
-rw-r--r-- | src/entities/creature.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/entities/creature.rs b/src/entities/creature.rs new file mode 100644 index 000000000000..6ddeade21845 --- /dev/null +++ b/src/entities/creature.rs @@ -0,0 +1,43 @@ +use crate::display; +use crate::entities::raws::CreatureType; +use crate::entities::raws::EntityRaw; +use crate::entities::{raw, Entity}; +use crate::types::Position; +use std::io::{self, Write}; + +pub struct Creature { + pub typ: &'static CreatureType<'static>, + pub position: Position, + pub hitpoints: u16, +} + +impl Creature { + pub fn new_from_raw(name: &'static str, position: Position) -> Self { + match raw(name) { + EntityRaw::Creature(typ) => Self::new_with_type(typ, position), + _ => panic!("Invalid raw type for {:?}, expected Creature", name), + } + } + + pub fn new_with_type( + typ: &'static CreatureType<'static>, + position: Position, + ) -> Self { + Creature { + typ, + position, + hitpoints: typ.max_hitpoints, + } + } +} + +positioned!(Creature); +positioned_mut!(Creature); + +impl Entity for Creature {} + +impl display::Draw for Creature { + fn do_draw(&self, out: &mut Write) -> io::Result<()> { + write!(out, "{}", self.typ.chr) + } +} |