00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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