00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "badguy/fish.hpp"
00018
00019 #include "sprite/sprite.hpp"
00020 #include "supertux/object_factory.hpp"
00021 #include "supertux/tile.hpp"
00022
00023 static const float FISH_JUMP_POWER = -600;
00024 static const float FISH_WAIT_TIME = 1;
00025
00026 Fish::Fish(const Reader& reader) :
00027 BadGuy(reader, "images/creatures/fish/fish.sprite", LAYER_TILES-1),
00028 waiting(),
00029 stop_y(0)
00030 {
00031 physic.enable_gravity(true);
00032 }
00033
00034 Fish::Fish(const Vector& pos) :
00035 BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1),
00036 waiting(),
00037 stop_y(0)
00038 {
00039 physic.enable_gravity(true);
00040 }
00041
00042 void
00043 Fish::collision_solid(const CollisionHit& chit)
00044 {
00045 hit(chit);
00046 }
00047
00048 HitResponse
00049 Fish::collision_badguy(BadGuy& , const CollisionHit& chit)
00050 {
00051 return hit(chit);
00052 }
00053
00054 void
00055 Fish::draw(DrawingContext& context)
00056 {
00057 if(waiting.started())
00058 return;
00059
00060 if (get_state() == STATE_FALLING) {
00061 sprite->set_action("down");
00062 sprite->draw(context, get_pos(), layer);
00063 }
00064 else if (get_state() == STATE_ACTIVE) {
00065 sprite->draw(context, get_pos(), layer);
00066 }
00067 }
00068
00069 HitResponse
00070 Fish::hit(const CollisionHit& hit)
00071 {
00072 if(hit.top) {
00073 physic.set_velocity_y(0);
00074 }
00075
00076 return CONTINUE;
00077 }
00078
00079 void
00080 Fish::collision_tile(uint32_t tile_attributes)
00081 {
00082 if ((tile_attributes & Tile::WATER) && (physic.get_velocity_y() >= 0)) {
00083
00084
00085 if (stop_y == 0) stop_y = get_pos().y + get_bbox().get_height();
00086
00087
00088 if (get_pos().y >= stop_y) {
00089 if(!frozen)
00090 start_waiting();
00091 movement = Vector(0, 0);
00092 }
00093
00094 }
00095 }
00096
00097 void
00098 Fish::active_update(float elapsed_time)
00099 {
00100 BadGuy::active_update(elapsed_time);
00101
00102
00103 if(waiting.check()) {
00104 jump();
00105 }
00106
00107
00108 if(!frozen)
00109 sprite->set_action(physic.get_velocity_y() < 0 ? "normal" : "down");
00110
00111
00112 if ((get_pos().y - 31.8) < 0)
00113 {
00114 physic.set_velocity_y(0);
00115 physic.enable_gravity(true);
00116 }
00117 }
00118
00119 void
00120 Fish::start_waiting()
00121 {
00122 waiting.start(FISH_WAIT_TIME);
00123 set_colgroup_active(COLGROUP_DISABLED);
00124 physic.enable_gravity(false);
00125 physic.set_velocity_y(0);
00126 }
00127
00128 void
00129 Fish::jump()
00130 {
00131 physic.set_velocity_y(FISH_JUMP_POWER);
00132 physic.enable_gravity(true);
00133 set_colgroup_active(COLGROUP_MOVING);
00134 }
00135
00136 void
00137 Fish::freeze()
00138 {
00139 BadGuy::freeze();
00140 sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down");
00141 waiting.stop();
00142 }
00143
00144 void
00145 Fish::unfreeze()
00146 {
00147 BadGuy::unfreeze();
00148 start_waiting();
00149 }
00150
00151 bool
00152 Fish::is_freezable() const
00153 {
00154 return true;
00155 }
00156
00157