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 static const float FLYTIME = 1.2f;
26 static const float FLYSPEED = -100.0f;
28 SpiderMite::SpiderMite(const lisp::Lisp& reader)
29 : 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")
37 physic.enable_gravity(false);
41 SpiderMite::write(lisp::Writer& writer)
43 writer.start_list("spidermite");
45 writer.write_float("x", start_position.x);
46 writer.write_float("y", start_position.y);
48 writer.end_list("spidermite");
52 SpiderMite::activate()
54 sprite->set_action(dir == LEFT ? "left" : "right");
56 physic.set_velocity_y(FLYSPEED);
57 timer.start(FLYTIME/2);
61 SpiderMite::collision_squished(GameObject& object)
63 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
64 kill_squished(object);
69 SpiderMite::collision_solid(const CollisionHit& hit)
71 if(hit.top || hit.bottom) { // hit floor or roof?
72 physic.set_velocity_y(0);
77 SpiderMite::active_update(float elapsed_time)
82 physic.set_velocity_y(-FLYSPEED);
83 } else if(mode == FLY_DOWN) {
85 physic.set_velocity_y(FLYSPEED);
89 movement=physic.get_movement(elapsed_time);
91 Player* player = this->get_nearest_player();
93 dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT;
94 sprite->set_action(dir == LEFT ? "left" : "right");
98 IMPLEMENT_FACTORY(SpiderMite, "spidermite")