2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "badguy/fish.hpp"
19 #include "sprite/sprite.hpp"
20 #include "supertux/object_factory.hpp"
21 #include "supertux/tile.hpp"
23 static const float FISH_JUMP_POWER = -600;
24 static const float FISH_WAIT_TIME = 1;
26 Fish::Fish(const Reader& reader) :
27 BadGuy(reader, "images/creatures/fish/fish.sprite", LAYER_TILES-1),
31 physic.enable_gravity(true);
34 Fish::Fish(const Vector& pos) :
35 BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1),
39 physic.enable_gravity(true);
43 Fish::collision_solid(const CollisionHit& chit)
49 Fish::collision_badguy(BadGuy& , const CollisionHit& chit)
55 Fish::draw(DrawingContext& context)
60 if (get_state() == STATE_FALLING) {
61 sprite->set_action("down");
62 sprite->draw(context, get_pos(), layer);
64 else if (get_state() == STATE_ACTIVE) {
65 sprite->draw(context, get_pos(), layer);
70 Fish::hit(const CollisionHit& hit)
73 physic.set_velocity_y(0);
80 Fish::collision_tile(uint32_t tile_attributes)
82 if ((tile_attributes & Tile::WATER) && (physic.get_velocity_y() >= 0)) {
84 // initialize stop position if uninitialized
85 if (stop_y == 0) stop_y = get_pos().y + get_bbox().get_height();
87 // stop when we have reached the stop position
88 if (get_pos().y >= stop_y) {
91 movement = Vector(0, 0);
98 Fish::active_update(float elapsed_time)
100 BadGuy::active_update(elapsed_time);
102 // waited long enough?
103 if(waiting.check()) {
109 sprite->set_action(physic.get_velocity_y() < 0 ? "normal" : "down");
111 // we can't afford flying out of the tilemap, 'cause the engine would remove us.
112 if ((get_pos().y - 31.8) < 0) // too high, let us fall
114 physic.set_velocity_y(0);
115 physic.enable_gravity(true);
120 Fish::start_waiting()
122 waiting.start(FISH_WAIT_TIME);
123 set_colgroup_active(COLGROUP_DISABLED);
124 physic.enable_gravity(false);
125 physic.set_velocity_y(0);
131 physic.set_velocity_y(FISH_JUMP_POWER);
132 physic.enable_gravity(true);
133 set_colgroup_active(COLGROUP_MOVING);
140 sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down");
146 { // does this happen at all? (or do fishes die when they fall frozen?)
152 Fish::is_freezable() const
157 IMPLEMENT_FACTORY(Fish, "fish");