-
Notifications
You must be signed in to change notification settings - Fork 0
/
HeroFsm.cpp
60 lines (53 loc) · 1.24 KB
/
HeroFsm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "HeroFsm.h"
#include <Debug.h>
#include <Gamebuino-Meta.h>
namespace actors
{
namespace hero
{
const char no_state_msg[] PROGMEM = "No current state to update().";
void HeroFsm::change_state(const hero_state state)
{
if (state == current_state_)
return;
if (current_state_ptr_ != nullptr)
current_state_ptr_->on_exit(*hero_ptr_);
current_state_ = state;
switch (state)
{
case hero_state::on_floor:
current_state_ptr_ = &on_floor_state_;
break;
case hero_state::in_air:
current_state_ptr_ = &in_air_state_;
break;
case hero_state::on_ladder:
current_state_ptr_ = &on_ladder_state_;
break;
case hero_state::teleporting_out:
current_state_ptr_ = &teleport_state_;
break;
case hero_state::teleporting_in:
current_state_ptr_ = &spawn_state_;
break;
case hero_state::shooting:
current_state_ptr_ = &shooting_state;
break;
}
current_state_ptr_->on_enter(*hero_ptr_);
}
void HeroFsm::update() const
{
if (current_state_ptr_ == nullptr)
{
Debug::throw_fatal(no_state_msg);
return;
}
current_state_ptr_->update(*hero_ptr_);
}
HeroFsm::hero_state HeroFsm::get_state() const
{
return current_state_;
}
}
}