4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "object/tilemap.hpp"
27 static const float FISH_JUMP_POWER = -600;
28 static const float FISH_WAIT_TIME = 1;
30 Fish::Fish(const lisp::Lisp& reader)
31 : BadGuy(reader, "images/creatures/fish/fish.sprite", LAYER_TILES-1), stop_y(0)
33 physic.enable_gravity(true);
36 Fish::Fish(const Vector& pos)
37 : BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1), stop_y(0)
39 physic.enable_gravity(true);
43 Fish::write(lisp::Writer& writer)
45 writer.start_list("fish");
47 writer.write_float("x", start_position.x);
48 writer.write_float("y", start_position.y);
50 writer.end_list("fish");
54 Fish::collision_solid(const CollisionHit& chit)
60 Fish::collision_badguy(BadGuy& , const CollisionHit& chit)
66 Fish::draw(DrawingContext& context)
71 BadGuy::draw(context);
75 Fish::hit(const CollisionHit& hit)
78 physic.set_velocity_y(0);
85 Fish::collision_tile(uint32_t tile_attributes)
87 if ((tile_attributes & Tile::WATER) && (physic.get_velocity_y() >= 0)) {
89 // initialize stop position if uninitialized
90 if (stop_y == 0) stop_y = get_pos().y + get_bbox().get_height();
92 // stop when we have reached the stop position
93 if (get_pos().y >= stop_y) {
96 movement = Vector(0, 0);
103 Fish::active_update(float elapsed_time)
105 BadGuy::active_update(elapsed_time);
107 // waited long enough?
108 if(waiting.check()) {
114 sprite->set_action(physic.get_velocity_y() < 0 ? "normal" : "down");
116 // we can't afford flying out of the tilemap, 'cause the engine would remove us.
117 if ((get_pos().y - 31.8) < 0) // too high, let us fall
119 physic.set_velocity_y(0);
120 physic.enable_gravity(true);
125 Fish::start_waiting()
127 waiting.start(FISH_WAIT_TIME);
128 set_colgroup_active(COLGROUP_DISABLED);
129 physic.enable_gravity(false);
130 physic.set_velocity_y(0);
136 physic.set_velocity_y(FISH_JUMP_POWER);
137 physic.enable_gravity(true);
138 set_colgroup_active(COLGROUP_MOVING);
145 sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down");
151 { // does this happen at all? (or do fishes die when they fall frozen?)
157 Fish::is_freezable() const
162 IMPLEMENT_FACTORY(Fish, "fish")