1
1
// SuperTux - Ispy
2
2
// Copyright (C) 2007 Christoph Sommer <[email protected] >
3
+ // 2022 Jiri Palecek <[email protected] >
3
4
//
4
5
// This program is free software: you can redistribute it and/or modify
5
6
// it under the terms of the GNU General Public License as published by
@@ -41,14 +42,7 @@ Ispy::Ispy(const ReaderMapping& reader) :
41
42
if (m_dir == Direction::AUTO)
42
43
log_warning << " Setting an Ispy's direction to AUTO is no good idea." << std::endl;
43
44
44
- switch (m_dir)
45
- {
46
- case Direction::DOWN: m_sprite->set_action (" idle-down" ); break ;
47
- case Direction::UP: m_sprite->set_action (" idle-up" ); break ;
48
- case Direction::LEFT: m_sprite->set_action (" idle-left" ); break ;
49
- case Direction::RIGHT: m_sprite->set_action (" idle-right" ); break ;
50
- default : break ;
51
- }
45
+ set_sprite_action (" idle" );
52
46
}
53
47
54
48
ObjectSettings
68
62
Ispy::after_editor_set ()
69
63
{
70
64
MovingSprite::after_editor_set ();
71
- switch (m_dir)
72
- {
73
- case Direction::DOWN: m_sprite->set_action (" idle-down" ); break ;
74
- case Direction::UP: m_sprite->set_action (" idle-up" ); break ;
75
- case Direction::LEFT: m_sprite->set_action (" idle-left" ); break ;
76
- case Direction::RIGHT: m_sprite->set_action (" idle-right" ); break ;
77
- default : break ;
78
- }
65
+ set_sprite_action (" idle" );
79
66
}
80
67
81
68
HitResponse
@@ -104,29 +91,15 @@ Ispy::update(float dt_sec)
104
91
105
92
if (Sector::get ().can_see_player (eye))
106
93
{
107
- switch (m_dir)
108
- {
109
- case Direction::DOWN: m_sprite->set_action (" alert-down" , 1 ); break ;
110
- case Direction::UP: m_sprite->set_action (" alert-up" , 1 ); break ;
111
- case Direction::LEFT: m_sprite->set_action (" alert-left" , 1 ); break ;
112
- case Direction::RIGHT: m_sprite->set_action (" alert-right" , 1 ); break ;
113
- default : break ;
114
- }
94
+ set_sprite_action (" alert" , 1 );
115
95
m_state = ISPYSTATE_ALERT;
116
96
}
117
97
}
118
98
if (m_state == ISPYSTATE_ALERT)
119
99
{
120
100
if (m_sprite->animation_done ())
121
101
{
122
- switch (m_dir)
123
- {
124
- case Direction::DOWN: m_sprite->set_action (" hiding-down" , 1 ); break ;
125
- case Direction::UP: m_sprite->set_action (" hiding-up" , 1 ); break ;
126
- case Direction::LEFT: m_sprite->set_action (" hiding-left" , 1 ); break ;
127
- case Direction::RIGHT: m_sprite->set_action (" hiding-right" , 1 ); break ;
128
- default : break ;
129
- }
102
+ set_sprite_action (" hiding" , 1 );
130
103
m_state = ISPYSTATE_HIDING;
131
104
132
105
Sector::get ().run_script (m_script, " Ispy" );
@@ -136,34 +109,33 @@ Ispy::update(float dt_sec)
136
109
{
137
110
if (m_sprite->animation_done ())
138
111
{
139
- switch (m_dir)
140
- {
141
- case Direction::DOWN: m_sprite->set_action (" showing-down" , 1 ); break ;
142
- case Direction::UP: m_sprite->set_action (" showing-up" , 1 ); break ;
143
- case Direction::LEFT: m_sprite->set_action (" showing-left" , 1 ); break ;
144
- case Direction::RIGHT: m_sprite->set_action (" showing-right" , 1 ); break ;
145
- default : break ;
146
- }
112
+ set_sprite_action (" showing" , 1 );
147
113
m_state = ISPYSTATE_SHOWING;
148
114
}
149
115
}
150
116
if (m_state == ISPYSTATE_SHOWING)
151
117
{
152
118
if (m_sprite->animation_done ())
153
119
{
154
- switch (m_dir)
155
- {
156
- case Direction::DOWN: m_sprite->set_action (" idle-down" ); break ;
157
- case Direction::UP: m_sprite->set_action (" idle-up" ); break ;
158
- case Direction::LEFT: m_sprite->set_action (" idle-left" ); break ;
159
- case Direction::RIGHT: m_sprite->set_action (" idle-right" ); break ;
160
- default : break ;
161
- }
120
+ set_sprite_action (" idle" );
162
121
m_state = ISPYSTATE_IDLE;
163
122
}
164
123
}
165
124
}
166
125
126
+ void
127
+ Ispy::set_sprite_action (std::string action, int loops)
128
+ {
129
+ switch (m_dir)
130
+ {
131
+ case Direction::DOWN: m_sprite->set_action (action + " -down" , loops); break ;
132
+ case Direction::UP: m_sprite->set_action (action + " -up" , loops); break ;
133
+ case Direction::LEFT: m_sprite->set_action (action + " -left" , loops); break ;
134
+ case Direction::RIGHT: m_sprite->set_action (action + " -right" , loops); break ;
135
+ default : break ;
136
+ }
137
+ }
138
+
167
139
void
168
140
Ispy::on_flip (float height)
169
141
{
0 commit comments