src/object/skull_tile.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 "math/random_generator.hpp"
00018 #include "object/player.hpp"
00019 #include "object/skull_tile.hpp"
00020 #include "sprite/sprite.hpp"
00021 #include "supertux/object_factory.hpp"
00022 #include "supertux/sector.hpp"
00023 
00024 static const float CRACKTIME = 0.3f;
00025 static const float FALLTIME = 0.8f;
00026 
00027 SkullTile::SkullTile(const Reader& lisp) :
00028   MovingSprite(lisp, "images/objects/skull_tile/skull_tile.sprite", LAYER_TILES, COLGROUP_STATIC), 
00029   physic(),
00030   timer(),
00031   hit(false), 
00032   falling(false)
00033 {
00034 }
00035 
00036 HitResponse
00037 SkullTile::collision(GameObject& other, const CollisionHit& )
00038 {
00039   Player* player = dynamic_cast<Player*> (&other);
00040   if(player)
00041     hit = true;
00042 
00043   return FORCE_MOVE;
00044 }
00045 
00046 void
00047 SkullTile::draw(DrawingContext& context)
00048 {
00049   Vector pos = get_pos();
00050   // shaking
00051   if(timer.get_timegone() > CRACKTIME) {
00052     pos.x += graphicsRandom.rand(-3, 3);
00053   }
00054 
00055   sprite->draw(context, pos, layer);
00056 }
00057 
00058 void
00059 SkullTile::update(float elapsed_time)
00060 {
00061   if(falling) {
00062     movement = physic.get_movement(elapsed_time);
00063     if(!Sector::current()->inside(bbox)) {
00064       remove_me();
00065       return;
00066     }
00067   } else if(hit) {
00068     if(timer.check()) {
00069       falling = true;
00070       physic.enable_gravity(true);
00071       timer.stop();
00072     } else if(!timer.started()) {
00073       timer.start(FALLTIME);
00074     }
00075   } else {
00076     timer.stop();
00077   }
00078   hit = false;
00079 }
00080 
00081 /* EOF */

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