3 #include "mriceblock.h"
5 static const float WALKSPEED = 80;
6 static const float KICKSPEED = 500;
7 static const int MAXSQUISHES = 10;
9 MrIceBlock::MrIceBlock(LispReader& reader)
10 : ice_state(ICESTATE_NORMAL), squishcount(0)
12 reader.read_float("x", start_position.x);
13 reader.read_float("y", start_position.y);
14 bbox.set_size(31.8, 31.8);
15 sprite = sprite_manager->create("mriceblock");
16 set_direction = false;
19 MrIceBlock::MrIceBlock(float pos_x, float pos_y, Direction d)
20 : ice_state(ICESTATE_NORMAL), squishcount(0)
22 start_position.x = pos_x;
23 start_position.y = pos_y;
24 bbox.set_size(31.8, 31.8);
25 sprite = sprite_manager->create("mriceblock");
27 initial_direction = d;
31 MrIceBlock::write(LispWriter& writer)
33 writer.start_list("mriceblock");
35 writer.write_float("x", get_pos().x);
36 writer.write_float("y", get_pos().y);
38 writer.end_list("mriceblock");
42 MrIceBlock::activate()
44 if (set_direction) {dir = initial_direction;}
45 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
46 sprite->set_action(dir == LEFT ? "left" : "right");
50 MrIceBlock::active_action(float elapsed_time)
52 if(ice_state == ICESTATE_FLAT && flat_timer.check()) {
54 ice_state = ICESTATE_NORMAL;
55 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
56 sprite->set_action(dir == LEFT ? "left" : "right");
58 BadGuy::active_action(elapsed_time);
62 MrIceBlock::collision_solid(GameObject& , const CollisionHit& hit)
64 if(fabsf(hit.normal.y) > .5) { // floor or roof
65 physic.set_velocity_y(0);
71 dir = dir == LEFT ? RIGHT : LEFT;
72 sprite->set_action(dir == LEFT ? "left" : "right");
73 physic.set_velocity_x(-physic.get_velocity_x());
76 dir = dir == LEFT ? RIGHT : LEFT;
77 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
78 physic.set_velocity_x(-physic.get_velocity_x());
79 SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(),
80 Sector::current()->player->get_pos());
83 physic.set_velocity_x(0);
91 MrIceBlock::collision_squished(Player& player)
97 if(squishcount >= MAXSQUISHES) {
103 SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(),
105 physic.set_velocity_x(0);
106 physic.set_velocity_y(0);
108 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
110 ice_state = ICESTATE_FLAT;
115 SoundManager::get()->play_sound(IDToSound(SND_KICK), this,
118 if(player.get_pos().x < get_pos().x) {
123 physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED);
124 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
125 ice_state = ICESTATE_KICKED;
130 player.bounce(*this);