31 |
using px::V2; |
using px::V2; |
32 |
using namespace world; |
using namespace world; |
33 |
|
|
34 |
//====================================================================== |
//---------------------------------------- |
35 |
// ACTORS |
// Actor implementation |
36 |
//====================================================================== |
//---------------------------------------- |
37 |
|
|
38 |
Actor::Actor(const char *kind, const px::V2 &p) |
Actor::Actor(const char *kind, const px::V2 &p) |
39 |
: Object(kind), actorinfo(p, V2()), |
: Object(kind), actorinfo(p, V2()), |
40 |
m_sprite(), |
m_sprite(), |
143 |
|
|
144 |
|
|
145 |
//---------------------------------------- |
//---------------------------------------- |
146 |
// Rotor |
// Rotor implementation |
147 |
//---------------------------------------- |
//---------------------------------------- |
148 |
namespace |
namespace |
149 |
{ |
{ |
297 |
RISING_VORTEX, // appear in vortex |
RISING_VORTEX, // appear in vortex |
298 |
JUMP_VORTEX, // jump out of vortex (here player controls actor) |
JUMP_VORTEX, // jump out of vortex (here player controls actor) |
299 |
}; |
}; |
|
State state; |
|
|
|
|
|
static const int minSinkDepth = 0; // normal level |
|
|
static const int maxSinkDepth = 7; // at that level the actor dies |
|
300 |
|
|
301 |
union { |
enum HaloState { |
302 |
struct { |
NOHALO, HALOBLINK, HALONORMAL |
303 |
double sinkDepth; // how deep actor has sunk |
}; |
|
int sinkModel; // current model |
|
|
} sink; |
|
|
struct { |
|
|
double normal_time; // while jumping out of vortex: time at normal level |
|
|
} vortex; |
|
|
} shared; |
|
304 |
|
|
|
display::SpriteHandle m_halosprite; |
|
|
double m_shield_rest_time; |
|
|
static const double SHIELD_TIME = 10.0; |
|
|
enum HaloState { NOHALO, HALOBLINK, HALONORMAL } m_halostate; |
|
305 |
|
|
306 |
void disable_shield(); |
void disable_shield(); |
307 |
void update_halo(); |
void update_halo(); |
|
bool has_halo(); |
|
308 |
void change_state_noshield (State newstate); |
void change_state_noshield (State newstate); |
309 |
|
|
310 |
|
|
338 |
|
|
339 |
bool is_dead() { return state == DEAD; } |
bool is_dead() { return state == DEAD; } |
340 |
bool is_flying() { return state == JUMPING; } |
bool is_flying() { return state == JUMPING; } |
341 |
bool is_on_floor() { return state == NORMAL || state == SINKING || state == JUMP_VORTEX || state==APPEARING; } |
bool is_on_floor(); |
342 |
bool can_drop_items() { return state == NORMAL || state == SINKING || state == JUMP_VORTEX || state==JUMPING; } |
bool can_drop_items(); |
343 |
bool can_pickup_items() { return state == NORMAL || state == SINKING || state == JUMP_VORTEX; } |
bool can_pickup_items(); |
344 |
|
bool has_shield() const; |
345 |
|
|
346 |
// Object interface. |
// Object interface. |
347 |
void message(const string &m, const Value &); |
void message(const string &m, const Value &); |
348 |
|
|
349 |
|
|
350 |
|
/* |
351 |
|
* Variables. |
352 |
|
*/ |
353 |
|
State state; // The marble's current state |
354 |
|
|
355 |
|
static const int minSinkDepth = 0; // normal level |
356 |
|
static const int maxSinkDepth = 7; // at that level the actor dies |
357 |
|
|
358 |
|
union { |
359 |
|
struct { |
360 |
|
double sinkDepth; // how deep actor has sunk |
361 |
|
int sinkModel; // current model |
362 |
|
} sink; |
363 |
|
struct { |
364 |
|
double normal_time; // while jumping out of vortex: time at normal level |
365 |
|
} vortex; |
366 |
|
} shared; |
367 |
|
|
368 |
|
display::SpriteHandle m_halosprite; |
369 |
|
double m_shield_rest_time; |
370 |
|
static const double SHIELD_TIME = 10.0; |
371 |
|
HaloState m_halostate; |
372 |
}; |
}; |
373 |
} |
} |
374 |
|
|
384 |
ai->mass = mass; |
ai->mass = mass; |
385 |
} |
} |
386 |
|
|
387 |
|
bool BasicBall::is_on_floor() |
388 |
|
{ |
389 |
|
return state == NORMAL || state == SINKING || |
390 |
|
state == JUMP_VORTEX || state==APPEARING; |
391 |
|
} |
392 |
|
|
393 |
|
bool BasicBall::can_drop_items() |
394 |
|
{ |
395 |
|
return state == NORMAL || state == SINKING || |
396 |
|
state == JUMP_VORTEX || state==JUMPING; |
397 |
|
} |
398 |
|
|
399 |
|
bool BasicBall::can_pickup_items() |
400 |
|
{ |
401 |
|
return state == NORMAL || state == SINKING || state == JUMP_VORTEX; |
402 |
|
} |
403 |
|
|
404 |
void BasicBall::change_state_noshield (State newstate) |
void BasicBall::change_state_noshield (State newstate) |
405 |
{ |
{ |
406 |
if (!has_halo()) |
if (!has_shield()) |
407 |
change_state(newstate); |
change_state(newstate); |
408 |
} |
} |
409 |
|
|
441 |
break; |
break; |
442 |
case APPEARING: |
case APPEARING: |
443 |
if ((m == "shatter" || m == "drown" || m == "fall") |
if ((m == "shatter" || m == "drown" || m == "fall") |
444 |
&& !has_halo()) |
&& !has_shield()) |
445 |
{ |
{ |
446 |
// Give an "emergency" shield to the actor if it would die |
// Give an "emergency" shield to the actor if it would die |
447 |
// after appearing. |
// after appearing. |
666 |
void |
void |
667 |
BasicBall::disable_shield() |
BasicBall::disable_shield() |
668 |
{ |
{ |
669 |
if (has_halo()) { |
if (has_shield()) { |
670 |
m_shield_rest_time = 0; |
m_shield_rest_time = 0; |
671 |
update_halo(); |
update_halo(); |
672 |
} |
} |
673 |
} |
} |
674 |
|
|
675 |
bool |
bool |
676 |
BasicBall::has_halo() |
BasicBall::has_shield() const |
677 |
{ |
{ |
678 |
return m_shield_rest_time > 0; |
return m_shield_rest_time > 0; |
679 |
} |
} |