src/badguy/spidermite.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "badguy/spidermite.hpp"
00018 
00019 #include "object/player.hpp"
00020 #include "sprite/sprite.hpp"
00021 #include "supertux/object_factory.hpp"
00022 
00023 static const float FLYTIME = 1.2f;
00024 static const float MOVE_SPEED = -100.0f;
00025 
00026 SpiderMite::SpiderMite(const Reader& reader) :
00027   BadGuy(reader, "images/creatures/spidermite/spidermite.sprite"),
00028   mode(),
00029   timer()
00030 {
00031   physic.enable_gravity(false);
00032 }
00033 
00034 SpiderMite::SpiderMite(const Vector& pos) :
00035   BadGuy(pos, "images/creatures/spidermite/spidermite.sprite"), 
00036   mode(),
00037   timer()
00038 {
00039   physic.enable_gravity(false);
00040 }
00041 
00042 void
00043 SpiderMite::initialize()
00044 {
00045   sprite->set_action(dir == LEFT ? "left" : "right");
00046   mode = FLY_UP;
00047   physic.set_velocity_y(MOVE_SPEED);
00048   timer.start(FLYTIME/2);
00049 }
00050 
00051 bool
00052 SpiderMite::collision_squished(GameObject& object)
00053 {
00054   sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
00055   kill_squished(object);
00056   return true;
00057 }
00058 
00059 void
00060 SpiderMite::collision_solid(const CollisionHit& hit)
00061 {
00062   if(hit.top || hit.bottom) { // hit floor or roof?
00063     physic.set_velocity_y(0);
00064   }
00065 }
00066 
00067 void
00068 SpiderMite::active_update(float elapsed_time)
00069 {
00070   if(timer.check()) {
00071     if(mode == FLY_UP) {
00072       mode = FLY_DOWN;
00073       physic.set_velocity_y(-MOVE_SPEED);
00074     } else if(mode == FLY_DOWN) {
00075       mode = FLY_UP;
00076       physic.set_velocity_y(MOVE_SPEED);
00077     }
00078     timer.start(FLYTIME);
00079   }
00080   movement=physic.get_movement(elapsed_time);
00081 
00082   Player* player = this->get_nearest_player();
00083   if (player) {
00084     dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT;
00085     sprite->set_action(dir == LEFT ? "left" : "right");
00086   }
00087 }
00088 
00089 /* EOF */

Generated on Mon Jun 9 03:38:17 2014 for SuperTux by  doxygen 1.5.1