4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "spidermite.hpp"
25 #include "lisp/writer.hpp"
26 #include "object_factory.hpp"
27 #include "object/player.hpp"
28 #include "sprite/sprite.hpp"
30 static const float FLYTIME = 1.2f;
31 static const float FLYSPEED = -100.0f;
33 SpiderMite::SpiderMite(const lisp::Lisp& reader)
34 : BadGuy(reader, "images/creatures/spidermite/spidermite.sprite")
36 physic.enable_gravity(false);
39 SpiderMite::SpiderMite(const Vector& pos)
40 : BadGuy(pos, "images/creatures/spidermite/spidermite.sprite")
42 physic.enable_gravity(false);
46 SpiderMite::write(lisp::Writer& writer)
48 writer.start_list("spidermite");
50 writer.write("x", start_position.x);
51 writer.write("y", start_position.y);
53 writer.end_list("spidermite");
57 SpiderMite::initialize()
59 sprite->set_action(dir == LEFT ? "left" : "right");
61 physic.set_velocity_y(FLYSPEED);
62 timer.start(FLYTIME/2);
66 SpiderMite::collision_squished(GameObject& object)
68 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
69 kill_squished(object);
74 SpiderMite::collision_solid(const CollisionHit& hit)
76 if(hit.top || hit.bottom) { // hit floor or roof?
77 physic.set_velocity_y(0);
82 SpiderMite::active_update(float elapsed_time)
87 physic.set_velocity_y(-FLYSPEED);
88 } else if(mode == FLY_DOWN) {
90 physic.set_velocity_y(FLYSPEED);
94 movement=physic.get_movement(elapsed_time);
96 Player* player = this->get_nearest_player();
98 dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT;
99 sprite->set_action(dir == LEFT ? "left" : "right");
103 IMPLEMENT_FACTORY(SpiderMite, "spidermite")