X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Ffish.cpp;h=8ff95bbf712351782a6a977fdf85c2c86e0e8ef4;hb=12a28b64dcce9c7ff706451b4f3aecd201cc8a5f;hp=43ceb5e706d5890d3cd9403f0eb620045d28158c;hpb=714a30abd887def6331a193216387e66cbfbd1bb;p=supertux.git diff --git a/src/badguy/fish.cpp b/src/badguy/fish.cpp index 43ceb5e70..8ff95bbf7 100644 --- a/src/badguy/fish.cpp +++ b/src/badguy/fish.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux // Copyright (C) 2006 Matthias Braun // -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,40 +12,31 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// along with this program. If not, see . -#include +#include "badguy/fish.hpp" -#include "fish.hpp" -#include "tile.hpp" -#include "object/tilemap.hpp" -#include "log.hpp" +#include "sprite/sprite.hpp" +#include "supertux/object_factory.hpp" +#include "supertux/tile.hpp" static const float FISH_JUMP_POWER = -600; static const float FISH_WAIT_TIME = 1; -Fish::Fish(const lisp::Lisp& reader) - : BadGuy(reader, "images/creatures/fish/fish.sprite", LAYER_TILES-1), stop_y(0) +Fish::Fish(const Reader& reader) : + BadGuy(reader, "images/creatures/fish/fish.sprite", LAYER_TILES-1), + waiting(), + stop_y(0) { - physic.gravity_enabled = true; + physic.enable_gravity(true); } -Fish::Fish(const Vector& pos) - : BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1), stop_y(0) -{ - physic.gravity_enabled = true; -} - -void -Fish::write(lisp::Writer& writer) +Fish::Fish(const Vector& pos) : + BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1), + waiting(), + stop_y(0) { - writer.start_list("fish"); - - writer.write_float("x", start_position.x); - writer.write_float("y", start_position.y); - - writer.end_list("fish"); + physic.enable_gravity(true); } void @@ -68,14 +57,20 @@ Fish::draw(DrawingContext& context) if(waiting.started()) return; - BadGuy::draw(context); + if (get_state() == STATE_FALLING) { + sprite->set_action("down"); + sprite->draw(context, get_pos(), layer); + } + else if (get_state() == STATE_ACTIVE) { + sprite->draw(context, get_pos(), layer); + } } HitResponse Fish::hit(const CollisionHit& hit) { if(hit.top) { - physic.vy = 0; + physic.set_velocity_y(0); } return CONTINUE; @@ -84,7 +79,7 @@ Fish::hit(const CollisionHit& hit) void Fish::collision_tile(uint32_t tile_attributes) { - if ((tile_attributes & Tile::WATER) && (physic.vy >= 0)) { + if ((tile_attributes & Tile::WATER) && (physic.get_velocity_y() >= 0)) { // initialize stop position if uninitialized if (stop_y == 0) stop_y = get_pos().y + get_bbox().get_height(); @@ -111,13 +106,13 @@ Fish::active_update(float elapsed_time) // set sprite if(!frozen) - sprite->set_action(physic.vy < 0 ? "normal" : "down"); + sprite->set_action(physic.get_velocity_y() < 0 ? "normal" : "down"); // we can't afford flying out of the tilemap, 'cause the engine would remove us. if ((get_pos().y - 31.8) < 0) // too high, let us fall { - physic.vy = 0; - physic.gravity_enabled = true; + physic.set_velocity_y(0); + physic.enable_gravity(true); } } @@ -125,24 +120,24 @@ void Fish::start_waiting() { waiting.start(FISH_WAIT_TIME); - set_group(COLGROUP_DISABLED); - physic.gravity_enabled = false; - physic.vy = 0; + set_colgroup_active(COLGROUP_DISABLED); + physic.enable_gravity(false); + physic.set_velocity_y(0); } void Fish::jump() { - physic.vy = FISH_JUMP_POWER; - physic.gravity_enabled = true; - set_group(COLGROUP_MOVING); + physic.set_velocity_y(FISH_JUMP_POWER); + physic.enable_gravity(true); + set_colgroup_active(COLGROUP_MOVING); } void Fish::freeze() { BadGuy::freeze(); - sprite->set_action(physic.vy < 0 ? "iced" : "iced-down"); + sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down"); waiting.stop(); } @@ -159,4 +154,6 @@ Fish::is_freezable() const return true; } -IMPLEMENT_FACTORY(Fish, "fish") +IMPLEMENT_FACTORY(Fish, "fish"); + +/* EOF */