3 #include "mriceblock.h"
4 #include "object/block.h"
6 static const float WALKSPEED = 80;
7 static const float KICKSPEED = 500;
8 static const int MAXSQUISHES = 10;
10 MrIceBlock::MrIceBlock(const lisp::Lisp& reader)
11 : ice_state(ICESTATE_NORMAL), squishcount(0)
13 reader.get("x", start_position.x);
14 reader.get("y", start_position.y);
15 bbox.set_size(31.8, 31.8);
16 sprite = sprite_manager->create("mriceblock");
17 set_direction = false;
20 MrIceBlock::MrIceBlock(float pos_x, float pos_y, Direction d)
21 : ice_state(ICESTATE_NORMAL), squishcount(0)
23 start_position.x = pos_x;
24 start_position.y = pos_y;
25 bbox.set_size(31.8, 31.8);
26 sprite = sprite_manager->create("mriceblock");
28 initial_direction = d;
32 MrIceBlock::write(lisp::Writer& writer)
34 writer.start_list("mriceblock");
36 writer.write_float("x", start_position.x);
37 writer.write_float("y", start_position.y);
39 writer.end_list("mriceblock");
43 MrIceBlock::activate()
45 if (set_direction) {dir = initial_direction;}
46 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
47 sprite->set_action(dir == LEFT ? "left" : "right");
51 MrIceBlock::active_action(float elapsed_time)
53 if(ice_state == ICESTATE_FLAT && flat_timer.check()) {
55 ice_state = ICESTATE_NORMAL;
56 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
57 sprite->set_action(dir == LEFT ? "left" : "right");
59 BadGuy::active_action(elapsed_time);
63 MrIceBlock::collision_solid(GameObject& object, const CollisionHit& hit)
65 if(fabsf(hit.normal.y) > .5) { // floor or roof
66 physic.set_velocity_y(0);
72 dir = dir == LEFT ? RIGHT : LEFT;
73 sprite->set_action(dir == LEFT ? "left" : "right");
74 physic.set_velocity_x(-physic.get_velocity_x());
76 case ICESTATE_KICKED: {
77 BonusBlock* bonusblock = dynamic_cast<BonusBlock*> (&object);
79 bonusblock->try_open();
81 Brick* brick = dynamic_cast<Brick*> (&object);
86 dir = dir == LEFT ? RIGHT : LEFT;
87 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
88 physic.set_velocity_x(-physic.get_velocity_x());
89 SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(),
90 Sector::current()->player->get_pos());
94 physic.set_velocity_x(0);
102 MrIceBlock::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
105 case ICESTATE_NORMAL:
106 if(fabsf(hit.normal.x) > .8) {
107 dir = dir == LEFT ? RIGHT : LEFT;
108 sprite->set_action(dir == LEFT ? "left" : "right");
109 physic.set_velocity_x(-physic.get_velocity_x());
114 case ICESTATE_KICKED:
125 MrIceBlock::collision_squished(Player& player)
128 case ICESTATE_KICKED:
129 case ICESTATE_NORMAL:
131 if(squishcount >= MAXSQUISHES) {
137 SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(),
139 physic.set_velocity_x(0);
140 physic.set_velocity_y(0);
142 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
144 ice_state = ICESTATE_FLAT;
149 SoundManager::get()->play_sound(IDToSound(SND_KICK), this,
152 if(player.get_pos().x < get_pos().x) {
157 physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED);
158 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
159 ice_state = ICESTATE_KICKED;
164 player.bounce(*this);
168 IMPLEMENT_FACTORY(MrIceBlock, "mriceblock")