sprite->set_action(dir == LEFT ? "large-left" : "large-right");
sound_manager->preload("sounds/mr_tree.ogg");
sound_manager->preload("sounds/mr_treehit.ogg");
- recently_changed_direction = false;
}
void
void
MrTree::active_update(float elapsed_time)
{
- recently_changed_direction = false;
if ((mystate == STATE_INVINCIBLE) && (invincible_timer.check())) {
mystate = STATE_NORMAL;
activate();
}
- if (on_ground() && might_fall() && !recently_changed_direction )
+ if (on_ground() && might_fall())
{
- recently_changed_direction = true;
dir = (dir == LEFT ? RIGHT : LEFT);
activate();
}
if(hit.top || hit.bottom) {
physic.set_velocity_y(0);
} else {
- if( recently_changed_direction ) return;
- recently_changed_direction = true;
- dir = dir == LEFT ? RIGHT : LEFT;
- activate();
+ if( ( hit.left && dir == LEFT )|| (hit.right && dir == RIGHT ) ){
+ dir = dir == LEFT ? RIGHT : LEFT;
+ activate();
+ }
}
}
HitResponse
MrTree::collision_badguy(BadGuy& , const CollisionHit& hit)
{
- if(hit.left || hit.right) {
- if( recently_changed_direction ) return CONTINUE;
- recently_changed_direction = true;
+ if( ( hit.left && dir == LEFT )|| (hit.right && dir == RIGHT ) ){
dir = dir == LEFT ? RIGHT : LEFT;
activate();
}
sound_manager->preload("sounds/iceblock_bump.wav");
sound_manager->preload("sounds/stomp.wav");
sound_manager->preload("sounds/kick.wav");
- recently_changed_direction = false;
}
Snail::Snail(const Vector& pos, Direction d)
sound_manager->preload("sounds/iceblock_bump.wav");
sound_manager->preload("sounds/stomp.wav");
sound_manager->preload("sounds/kick.wav");
- recently_changed_direction = false;
}
void
void
Snail::active_update(float elapsed_time)
{
- recently_changed_direction = false;
switch (state) {
case STATE_NORMAL:
if (on_ground() && might_fall(601)) {
- if( recently_changed_direction ) break;
- recently_changed_direction = true;
dir = (dir == LEFT ? RIGHT : LEFT);
sprite->set_action(dir == LEFT ? "left" : "right");
physic.set_velocity_x(-physic.get_velocity_x());
switch(state) {
case STATE_NORMAL:
- if( recently_changed_direction ) break;
- recently_changed_direction = true;
- dir = dir == LEFT ? RIGHT : LEFT;
- sprite->set_action(dir == LEFT ? "left" : "right");
- physic.set_velocity_x(-physic.get_velocity_x());
+ if( (dir == LEFT && hit.left) || ( dir == RIGHT && hit.right) ){
+ dir = dir == LEFT ? RIGHT : LEFT;
+ sprite->set_action(dir == LEFT ? "left" : "right");
+ physic.set_velocity_x(-physic.get_velocity_x());
+ }
break;
case STATE_FLAT:
brick->try_break();
}
#endif
- if( recently_changed_direction ) break;
- recently_changed_direction = true;
- dir = (dir == LEFT) ? RIGHT : LEFT;
- sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
+ if( ( dir == LEFT && hit.left ) || ( dir == RIGHT && hit.right) ){
+ dir = (dir == LEFT) ? RIGHT : LEFT;
+ sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
- physic.set_velocity_x(-physic.get_velocity_x()*0.75);
- if (fabsf(physic.get_velocity_x()) < WALKSPEED) be_normal();
+ physic.set_velocity_x(-physic.get_velocity_x()*0.75);
+ if (fabsf(physic.get_velocity_x()) < WALKSPEED) be_normal();
+ }
break;
}
{
switch(state) {
case STATE_NORMAL:
- if(hit.left || hit.right) {
- if( recently_changed_direction ) return CONTINUE;
- recently_changed_direction = true;
- dir = (dir == LEFT) ? RIGHT : LEFT;
- sprite->set_action(dir == LEFT ? "left" : "right");
+ // printf("Snail <-> Badguy %s %s %s %s %s\n", hit.left?"left":"", hit.right?"right":"", hit.top?"top":"", hit.bottom?"bottom":"", hit.crush?"crush":"");
+ if( hit.left && dir == LEFT ){
+ dir = RIGHT;
+ sprite->set_action( "right" );
+ physic.set_velocity_x(-physic.get_velocity_x());
+ } else if( hit.right && dir == RIGHT ){
+ dir = LEFT;
+ sprite->set_action( "left" );
physic.set_velocity_x(-physic.get_velocity_x());
}
return CONTINUE;