namespace {
const float KICKSPEED = 500;
const int MAXSQUISHES = 10;
+ const float NOKICK_TIME = 0.1f;
}
MrIceBlock::MrIceBlock(const lisp::Lisp& reader)
: WalkingBadguy(reader, "images/creatures/mr_iceblock/mr_iceblock.sprite", "left", "right"), ice_state(ICESTATE_NORMAL), squishcount(0)
{
walk_speed = 80;
- max_drop_height = 600;
+ max_drop_height = 600;
sound_manager->preload("sounds/iceblock_bump.wav");
sound_manager->preload("sounds/stomp.wav");
sound_manager->preload("sounds/kick.wav");
MrIceBlock::MrIceBlock(const Vector& pos, Direction d)
: WalkingBadguy(pos, d, "images/creatures/mr_iceblock/mr_iceblock.sprite", "left", "right"), ice_state(ICESTATE_NORMAL), squishcount(0)
{
- walk_speed = 80;
- max_drop_height = 600;
+ walk_speed = 80;
+ max_drop_height = 600;
sound_manager->preload("sounds/iceblock_bump.wav");
sound_manager->preload("sounds/stomp.wav");
sound_manager->preload("sounds/kick.wav");
BadGuy::active_update(elapsed_time);
}
+bool
+MrIceBlock::can_break(){
+ return ice_state == ICESTATE_KICKED;
+}
+
void
MrIceBlock::collision_solid(const CollisionHit& hit)
{
WalkingBadguy::collision_solid(hit);
break;
case ICESTATE_KICKED: {
-#if 0
- // TODO move these into bonusblock class
- BonusBlock* bonusblock = dynamic_cast<BonusBlock*> (&object);
- if(bonusblock) {
- bonusblock->try_open();
- }
- Brick* brick = dynamic_cast<Brick*> (&object);
- if(brick) {
- brick->try_break();
- }
-#endif
if(hit.right && dir == RIGHT) {
dir = LEFT;
sound_manager->play("sounds/iceblock_bump.wav", get_pos());
+ if(++squishcount >= MAXSQUISHES) { kill_fall(); break; }
physic.set_velocity_x(-KICKSPEED);
} else if(hit.left && dir == LEFT) {
dir = RIGHT;
sound_manager->play("sounds/iceblock_bump.wav", get_pos());
+ if(++squishcount >= MAXSQUISHES) { kill_fall(); break; }
physic.set_velocity_x(KICKSPEED);
}
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
if(ice_state == ICESTATE_GRABBED)
return FORCE_MOVE;
+ if(dir == UP) {
+ return FORCE_MOVE;
+ }
+
// handle kicks from left or right side
if(ice_state == ICESTATE_FLAT && get_state() == STATE_ACTIVE) {
if(hit.left) {
return FORCE_MOVE;
}
}
-
+
return BadGuy::collision_player(player, hit);
}
}
bool
-MrIceBlock::collision_squished(Player& player)
+MrIceBlock::collision_squished(GameObject& object)
{
switch(ice_state) {
case ICESTATE_KICKED:
}
set_state(ICESTATE_FLAT);
+ nokick_timer.start(NOKICK_TIME);
break;
case ICESTATE_FLAT:
- if(player.get_pos().x < get_pos().x) {
- dir = RIGHT;
- } else {
- dir = LEFT;
+ {
+ MovingObject* movingobject = dynamic_cast<MovingObject*>(&object);
+ if (movingobject && (movingobject->get_pos().x < get_pos().x)) {
+ dir = RIGHT;
+ } else {
+ dir = LEFT;
+ }
}
- set_state(ICESTATE_KICKED);
+ if (nokick_timer.check()) set_state(ICESTATE_KICKED);
break;
case ICESTATE_GRABBED:
assert(false);
break;
}
- player.bounce(*this);
+ Player* player = dynamic_cast<Player*>(&object);
+ if (player) player->bounce(*this);
return true;
}
{
if(ice_state == state)
return;
-
- if(state == ICESTATE_FLAT)
- flags |= FLAG_PORTABLE;
- else
- flags &= ~FLAG_PORTABLE;
switch(state) {
case ICESTATE_NORMAL:
WalkingBadguy::activate();
break;
case ICESTATE_FLAT:
- sound_manager->play("sounds/stomp.wav", get_pos());
- physic.set_velocity_x(0);
- physic.set_velocity_y(0);
-
- sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
+ if(dir == UP) {
+ physic.set_velocity_y(-KICKSPEED);
+ bbox.set_size(34, 31.8f);
+ } else {
+ sound_manager->play("sounds/stomp.wav", get_pos());
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
+
+ sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
+ }
flat_timer.start(4);
break;
case ICESTATE_KICKED:
physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED);
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
// we should slide above 1 block holes now...
- bbox.set_size(34, 31.8);
+ bbox.set_size(34, 31.8f);
break;
case ICESTATE_GRABBED:
flat_timer.stop();
MrIceBlock::ungrab(MovingObject& , Direction dir)
{
this->dir = dir;
- set_state(ICESTATE_KICKED);
+ set_state(dir == UP ? ICESTATE_FLAT : ICESTATE_KICKED);
set_group(COLGROUP_MOVING);
}
+bool
+MrIceBlock::is_portable() const
+{
+ return ice_state == ICESTATE_FLAT;
+}
+
IMPLEMENT_FACTORY(MrIceBlock, "mriceblock")