Fish Class Reference

#include <fish.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 Fish (const Reader &)
 Fish (const Vector &pos)
void draw (DrawingContext &context)
 Called when the badguy is drawn.
void collision_solid (const CollisionHit &hit)
 Called when the badguy collided with solid ground.
HitResponse collision_badguy (BadGuy &, const CollisionHit &)
 Called when the badguy collided with another badguy.
void collision_tile (uint32_t tile_attributes)
 Called when a collision with tile with special attributes occurred.
void active_update (float)
 called each frame when the badguy is activated.
void freeze ()
 Called when hit by an ice bullet, and is_freezable() returns true.
void unfreeze ()
 Called to unfreeze the badguy.
bool is_freezable () const

Private Member Functions

HitResponse hit (const CollisionHit &)
void start_waiting ()
void jump ()

Private Attributes

Timer waiting
float stop_y
 y-coordinate to stop at


Detailed Description

Definition at line 22 of file fish.hpp.


Constructor & Destructor Documentation

Fish::Fish ( const Reader  ) 

Definition at line 26 of file fish.cpp.

References Physic::enable_gravity(), and BadGuy::physic.

00026                                :
00027   BadGuy(reader, "images/creatures/fish/fish.sprite", LAYER_TILES-1), 
00028   waiting(),
00029   stop_y(0)
00030 {
00031   physic.enable_gravity(true);
00032 }

Fish::Fish ( const Vector pos  ) 

Definition at line 34 of file fish.cpp.

References Physic::enable_gravity(), and BadGuy::physic.

00034                             :
00035   BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1), 
00036   waiting(),
00037   stop_y(0)
00038 {
00039   physic.enable_gravity(true);
00040 }


Member Function Documentation

void Fish::draw ( DrawingContext context  )  [virtual]

Called when the badguy is drawn.

The default implementation simply draws the badguy sprite on screen

Reimplemented from BadGuy.

Definition at line 55 of file fish.cpp.

References MovingObject::get_pos(), BadGuy::get_state(), MovingSprite::layer, MovingSprite::sprite, Timer::started(), BadGuy::STATE_ACTIVE, BadGuy::STATE_FALLING, and waiting.

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 }

void Fish::collision_solid ( const CollisionHit hit  )  [virtual]

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 43 of file fish.cpp.

References hit().

00044 {
00045   hit(chit);
00046 }

HitResponse Fish::collision_badguy ( BadGuy ,
const CollisionHit  
) [virtual]

Called when the badguy collided with another badguy.

Reimplemented from BadGuy.

Definition at line 49 of file fish.cpp.

References hit().

00050 {
00051   return hit(chit);
00052 }

void Fish::collision_tile ( uint32_t  tile_attributes  )  [virtual]

Called when a collision with tile with special attributes occurred.

Reimplemented from BadGuy.

Definition at line 80 of file fish.cpp.

References BadGuy::frozen, MovingObject::get_bbox(), Rectf::get_height(), MovingObject::get_pos(), Physic::get_velocity_y(), MovingObject::movement, BadGuy::physic, start_waiting(), stop_y, Tile::WATER, and Vector::y.

00081 {
00082   if ((tile_attributes & Tile::WATER) && (physic.get_velocity_y() >= 0)) {
00083 
00084     // initialize stop position if uninitialized
00085     if (stop_y == 0) stop_y = get_pos().y + get_bbox().get_height();
00086 
00087     // stop when we have reached the stop position
00088     if (get_pos().y >= stop_y) {
00089       if(!frozen)
00090         start_waiting();
00091       movement = Vector(0, 0);
00092     }
00093 
00094   }
00095 }

void Fish::active_update ( float   )  [virtual]

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 98 of file fish.cpp.

References BadGuy::active_update(), Timer::check(), Physic::enable_gravity(), BadGuy::frozen, MovingObject::get_pos(), Physic::get_velocity_y(), jump(), BadGuy::physic, Physic::set_velocity_y(), MovingSprite::sprite, and waiting.

00099 {
00100   BadGuy::active_update(elapsed_time);
00101 
00102   // waited long enough?
00103   if(waiting.check()) {
00104     jump();
00105   }
00106 
00107   // set sprite
00108   if(!frozen)
00109     sprite->set_action(physic.get_velocity_y() < 0 ? "normal" : "down");
00110 
00111   // we can't afford flying out of the tilemap, 'cause the engine would remove us.
00112   if ((get_pos().y - 31.8) < 0) // too high, let us fall
00113   {
00114     physic.set_velocity_y(0);
00115     physic.enable_gravity(true);
00116   }
00117 }

void Fish::freeze (  )  [virtual]

Called when hit by an ice bullet, and is_freezable() returns true.

Reimplemented from BadGuy.

Definition at line 137 of file fish.cpp.

References BadGuy::freeze(), Physic::get_velocity_y(), BadGuy::physic, MovingSprite::sprite, Timer::stop(), and waiting.

00138 {
00139   BadGuy::freeze();
00140   sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down");
00141   waiting.stop();
00142 }

void Fish::unfreeze (  )  [virtual]

Called to unfreeze the badguy.

Reimplemented from BadGuy.

Definition at line 145 of file fish.cpp.

References start_waiting(), and BadGuy::unfreeze().

00146 { // does this happen at all? (or do fishes die when they fall frozen?)
00147   BadGuy::unfreeze();
00148   start_waiting();
00149 }

bool Fish::is_freezable (  )  const [virtual]

Reimplemented from BadGuy.

Definition at line 152 of file fish.cpp.

00153 {
00154   return true;
00155 }

HitResponse Fish::hit ( const CollisionHit  )  [private]

Definition at line 70 of file fish.cpp.

References CONTINUE, BadGuy::physic, and Physic::set_velocity_y().

Referenced by collision_badguy(), and collision_solid().

00071 {
00072   if(hit.top) {
00073     physic.set_velocity_y(0);
00074   }
00075 
00076   return CONTINUE;
00077 }

void Fish::start_waiting (  )  [private]

Definition at line 120 of file fish.cpp.

References COLGROUP_DISABLED, Physic::enable_gravity(), FISH_WAIT_TIME, BadGuy::physic, BadGuy::set_colgroup_active(), Physic::set_velocity_y(), Timer::start(), and waiting.

Referenced by collision_tile(), and unfreeze().

void Fish::jump (  )  [private]

Definition at line 129 of file fish.cpp.

References COLGROUP_MOVING, Physic::enable_gravity(), FISH_JUMP_POWER, BadGuy::physic, BadGuy::set_colgroup_active(), and Physic::set_velocity_y().

Referenced by active_update().


Member Data Documentation

Timer Fish::waiting [private]

Definition at line 45 of file fish.hpp.

Referenced by active_update(), draw(), freeze(), and start_waiting().

float Fish::stop_y [private]

y-coordinate to stop at

Definition at line 46 of file fish.hpp.

Referenced by collision_tile().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:30 2014 for SuperTux by  doxygen 1.5.1