projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Do not resurrect squished bouncing snowball when colliding with badguy or tile
[supertux.git]
/
src
/
badguy
/
fish.cpp
diff --git
a/src/badguy/fish.cpp
b/src/badguy/fish.cpp
index
ebd14c3
..
c8bf809
100644
(file)
--- a/
src/badguy/fish.cpp
+++ b/
src/badguy/fish.cpp
@@
-1,12
+1,10
@@
-// $Id$
-//
// SuperTux
// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// SuperTux
// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
-// 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
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-14,45
+12,37
@@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// 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 <http://www.gnu.org/licenses/>.
-#include
<config.h>
+#include
"badguy/fish.hpp"
-#include "
fish
.hpp"
-#include "
tile
.hpp"
-#include "
object/tilemap
.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_JUMP_POWER =
-
600;
static const float FISH_WAIT_TIME = 1;
static const float FISH_WAIT_TIME = 1;
-Fish::Fish(const lisp::Lisp& reader)
- : BadGuy(reader, "images/creatures/fish/fish.sprite")
+Fish::Fish(const Reader& reader) :
+ BadGuy(reader, "images/creatures/fish/fish.sprite", LAYER_TILES-1),
+ waiting(),
+ stop_y(0)
{
physic.enable_gravity(true);
}
{
physic.enable_gravity(true);
}
-Fish::Fish(const Vector& pos)
- : BadGuy(pos, "images/creatures/fish/fish.sprite")
+Fish::Fish(const Vector& pos) :
+ BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1),
+ waiting(),
+ stop_y(0)
{
physic.enable_gravity(true);
}
void
{
physic.enable_gravity(true);
}
void
-Fish::
write(lisp::Writer& writer
)
+Fish::
collision_solid(const CollisionHit& chit
)
{
{
- writer.start_list("fish");
-
- writer.write_float("x", start_position.x);
- writer.write_float("y", start_position.y);
-
- writer.end_list("fish");
-}
-
-HitResponse
-Fish::collision_solid(GameObject& , const CollisionHit& chit)
-{
- return hit(chit);
+ hit(chit);
}
HitResponse
}
HitResponse
@@
-67,13
+57,19
@@
Fish::draw(DrawingContext& context)
if(waiting.started())
return;
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
}
HitResponse
-Fish::hit(const CollisionHit&
c
hit)
+Fish::hit(const CollisionHit& hit)
{
{
- if(
chit.normal.y < .5) { // hit ceiling
+ if(
hit.top) {
physic.set_velocity_y(0);
}
physic.set_velocity_y(0);
}
@@
-83,9
+79,18
@@
Fish::hit(const CollisionHit& chit)
void
Fish::collision_tile(uint32_t tile_attributes)
{
void
Fish::collision_tile(uint32_t tile_attributes)
{
- if(tile_attributes & Tile::WATER) {
- start_waiting();
- movement = Vector(0, 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();
+
+ // stop when we have reached the stop position
+ if (get_pos().y >= stop_y) {
+ if(!frozen)
+ start_waiting();
+ movement = Vector(0, 0);
+ }
+
}
}
}
}
@@
-98,10
+103,11
@@
Fish::active_update(float elapsed_time)
if(waiting.check()) {
jump();
}
if(waiting.check()) {
jump();
}
-
+
// set sprite
// set sprite
- sprite->set_action(physic.get_velocity_y() > 0 ? "normal" : "down");
-
+ if(!frozen)
+ 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
{
// 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
{
@@
-114,7
+120,7
@@
void
Fish::start_waiting()
{
waiting.start(FISH_WAIT_TIME);
Fish::start_waiting()
{
waiting.start(FISH_WAIT_TIME);
- set_
group
(COLGROUP_DISABLED);
+ set_
colgroup_active
(COLGROUP_DISABLED);
physic.enable_gravity(false);
physic.set_velocity_y(0);
}
physic.enable_gravity(false);
physic.set_velocity_y(0);
}
@@
-124,7
+130,28
@@
Fish::jump()
{
physic.set_velocity_y(FISH_JUMP_POWER);
physic.enable_gravity(true);
{
physic.set_velocity_y(FISH_JUMP_POWER);
physic.enable_gravity(true);
- set_group(COLGROUP_MOVING);
+ set_colgroup_active(COLGROUP_MOVING);
+}
+
+void
+Fish::freeze()
+{
+ BadGuy::freeze();
+ sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down");
+ waiting.stop();
+}
+
+void
+Fish::unfreeze()
+{ // does this happen at all? (or do fishes die when they fall frozen?)
+ BadGuy::unfreeze();
+ start_waiting();
+}
+
+bool
+Fish::is_freezable() const
+{
+ return true;
}
}
-IMPLEMENT_FACTORY(Fish, "fish")
+/* EOF */