The next little game in the series where I make a fancy rogue game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
roguish/entity.cpp

38 lines
657 B

#include "entity.hpp"
void Entity::move(Point loc) {
location = loc;
}
void Entity::event(EntityEvent ev) {
switch($state) {
FSM_STATE(EntityState, START, ev);
FSM_STATE(EntityState, HUNTING, ev);
FSM_STATE(EntityState, DEAD, ev);
}
}
void Entity::START(EntityEvent ev) {
state(EntityState::HUNTING);
}
void Entity::HUNTING(EntityEvent ev) {
switch(ev) {
case EntityEvent::HIT:
hp -= damage;
break;
default:
state(EntityState::HUNTING);
}
if(hp <= 0) {
state(EntityState::DEAD);
} else {
state(EntityState::HUNTING);
}
}
void Entity::DEAD(EntityEvent ev) {
state(EntityState::DEAD);
}