2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "badguy/spidermite.hpp"
19 #include "object/player.hpp"
20 #include "sprite/sprite.hpp"
21 #include "supertux/object_factory.hpp"
23 static const float FLYTIME = 1.2f;
24 static const float MOVE_SPEED = -100.0f;
26 SpiderMite::SpiderMite(const Reader& reader) :
27 BadGuy(reader, "images/creatures/spidermite/spidermite.sprite"),
31 physic.enable_gravity(false);
34 SpiderMite::SpiderMite(const Vector& pos) :
35 BadGuy(pos, "images/creatures/spidermite/spidermite.sprite"),
39 physic.enable_gravity(false);
43 SpiderMite::initialize()
45 sprite->set_action(dir == LEFT ? "left" : "right");
47 physic.set_velocity_y(MOVE_SPEED);
48 timer.start(FLYTIME/2);
52 SpiderMite::collision_squished(GameObject& object)
54 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
55 kill_squished(object);
60 SpiderMite::collision_solid(const CollisionHit& hit)
62 if(hit.top || hit.bottom) { // hit floor or roof?
63 physic.set_velocity_y(0);
68 SpiderMite::active_update(float elapsed_time)
72 BadGuy::active_update(elapsed_time);
78 physic.set_velocity_y(-MOVE_SPEED);
79 } else if(mode == FLY_DOWN) {
81 physic.set_velocity_y(MOVE_SPEED);
85 movement=physic.get_movement(elapsed_time);
87 Player* player = this->get_nearest_player();
89 dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT;
90 sprite->set_action(dir == LEFT ? "left" : "right");
97 physic.enable_gravity(true);
102 SpiderMite::unfreeze()
105 physic.enable_gravity(false);
110 SpiderMite::is_freezable() const