Refactor the entity out.
This commit is contained in:
parent
cac7017563
commit
a7f6357e12
6 changed files with 126 additions and 111 deletions
37
entity.cpp
Normal file
37
entity.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue