Yeti Class Reference

#include <yeti.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 Yeti (const Reader &lisp)
 ~Yeti ()
void draw (DrawingContext &context)
 Called when the badguy is drawn.
void initialize ()
 called immediately before the first call to initialize
void active_update (float elapsed_time)
 called each frame when the badguy is activated.
void collision_solid (const CollisionHit &hit)
 Called when the badguy collided with solid ground.
bool collision_squished (GameObject &object)
 Called when the player hit the badguy from above.
void kill_squished (GameObject &object)
void kill_fall ()
 Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).

Private Types

enum  YetiState {
  JUMP_DOWN, RUN, JUMP_UP, BE_ANGRY,
  SQUISHED
}

Private Member Functions

void run ()
void jump_up ()
void be_angry ()
void drop_stalactite ()
void jump_down ()
void draw_hit_points (DrawingContext &context)
void take_hit (Player &player)

Private Attributes

YetiState state
Timer state_timer
Timer safe_timer
int stomp_count
int hit_points
SurfacePtr hud_head


Detailed Description

Definition at line 25 of file yeti.hpp.


Member Enumeration Documentation

enum Yeti::YetiState [private]

Enumerator:
JUMP_DOWN 
RUN 
JUMP_UP 
BE_ANGRY 
SQUISHED 

Definition at line 51 of file yeti.hpp.

00051                  {
00052     JUMP_DOWN,
00053     RUN,
00054     JUMP_UP,
00055     BE_ANGRY,
00056     SQUISHED
00057   };


Constructor & Destructor Documentation

Yeti::Yeti ( const Reader lisp  ) 

Definition at line 54 of file yeti.cpp.

References BadGuy::countMe, Surface::create(), hit_points, hud_head, INITIAL_HITPOINTS, SoundManager::preload(), and sound_manager.

00054                                :
00055   BadGuy(reader, "images/creatures/yeti/yeti.sprite"),
00056   state(),
00057   state_timer(),
00058   safe_timer(),
00059   stomp_count(),
00060   hit_points(),
00061   hud_head()
00062 {
00063   hit_points = INITIAL_HITPOINTS;
00064   countMe = false;
00065   sound_manager->preload("sounds/yeti_gna.wav");
00066   sound_manager->preload("sounds/yeti_roar.wav");
00067   hud_head = Surface::create("images/creatures/yeti/hudlife.png");
00068 }

Yeti::~Yeti (  ) 

Definition at line 70 of file yeti.cpp.

00071 {
00072 }


Member Function Documentation

void Yeti::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 82 of file yeti.cpp.

References BadGuy::draw(), draw_hit_points(), game_time, safe_timer, and Timer::started().

00083 {
00084   // we blink when we are safe
00085   if(safe_timer.started() && size_t(game_time*40)%2)
00086     return;
00087 
00088   draw_hit_points(context);
00089 
00090   BadGuy::draw(context);
00091 }

void Yeti::initialize (  )  [virtual]

called immediately before the first call to initialize

Reimplemented from BadGuy.

Definition at line 75 of file yeti.cpp.

References BadGuy::dir, jump_down(), and RIGHT.

00076 {
00077   dir = RIGHT;
00078   jump_down();
00079 }

void Yeti::active_update ( float  elapsed_time  )  [virtual]

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 113 of file yeti.cpp.

References BE_ANGRY, be_angry(), Timer::check(), BadGuy::dir, Physic::get_movement(), MovingObject::get_pos(), JUMP_DOWN, JUMP_DOWN_VX, JUMP_UP, jump_up(), JUMP_UP_VX, LEFT, LEFT_JUMP_X, LEFT_STAND_X, MovingObject::movement, BadGuy::physic, SoundManager::play(), GameObject::remove_me(), RIGHT, RIGHT_JUMP_X, RIGHT_STAND_X, RUN, RUN_VX, Physic::set_velocity_x(), Physic::set_velocity_y(), sound_manager, MovingSprite::sprite, SQUISHED, state, state_timer, and STOMP_VY.

00114 {
00115   switch(state) {
00116     case JUMP_DOWN:
00117       physic.set_velocity_x((dir==RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX);
00118       break;
00119     case RUN:
00120       physic.set_velocity_x((dir==RIGHT)?+RUN_VX:-RUN_VX);
00121       if (((dir == RIGHT) && (get_pos().x >= RIGHT_JUMP_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_JUMP_X))) jump_up();
00122       break;
00123     case JUMP_UP:
00124       physic.set_velocity_x((dir==RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX);
00125       if (((dir == RIGHT) && (get_pos().x >= RIGHT_STAND_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_STAND_X))) be_angry();
00126       break;
00127     case BE_ANGRY:
00128       if(state_timer.check()) {
00129         sound_manager->play("sounds/yeti_gna.wav");
00130         physic.set_velocity_y(STOMP_VY);
00131         sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left");
00132       }
00133       break;
00134     case SQUISHED:
00135       if (state_timer.check()) {
00136         remove_me();
00137       }
00138       break;
00139   }
00140 
00141   movement = physic.get_movement(elapsed_time);
00142 }

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

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 268 of file yeti.cpp.

References BE_ANGRY, CollisionHit::bottom, BadGuy::dir, drop_stalactite(), jump_down(), JUMP_DOWN, jump_up(), JUMP_UP, CollisionHit::left, BadGuy::physic, CollisionHit::right, RIGHT, RUN, run(), Physic::set_velocity_y(), MovingSprite::sprite, SQUISHED, Timer::start(), Timer::started(), state, state_timer, stomp_count, STOMP_WAIT, and CollisionHit::top.

00269 {
00270   if(hit.top || hit.bottom) {
00271     // hit floor or roof
00272     physic.set_velocity_y(0);
00273     switch (state) {
00274       case JUMP_DOWN:
00275         run();
00276         break;
00277       case RUN:
00278         break;
00279       case JUMP_UP:
00280         break;
00281       case BE_ANGRY:
00282         // we just landed
00283         if(!state_timer.started()) {
00284           sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
00285           stomp_count++;
00286           drop_stalactite();
00287 
00288           // go to other side after 3 jumps
00289           if(stomp_count == 3) {
00290             jump_down();
00291           } else {
00292             // jump again
00293             state_timer.start(STOMP_WAIT);
00294           }
00295         }
00296         break;
00297       case SQUISHED:
00298         break;
00299     }
00300   } else if(hit.left || hit.right) {
00301     // hit wall
00302     jump_up();
00303   }
00304 }

bool Yeti::collision_squished ( GameObject object  )  [virtual]

Called when the player hit the badguy from above.

You should return true if the badguy was squished, false if squishing wasn't possible

Reimplemented from BadGuy.

Definition at line 186 of file yeti.cpp.

References kill_squished().

00187 {
00188   kill_squished(object);
00189 
00190   return true;
00191 }

void Yeti::kill_squished ( GameObject object  ) 

Reimplemented from BadGuy.

Definition at line 194 of file yeti.cpp.

References Player::bounce(), and take_hit().

Referenced by collision_squished().

00195 {
00196   Player* player = dynamic_cast<Player*>(&object);
00197   if (player) {
00198     player->bounce(*this);
00199     take_hit(*player);
00200   }
00201 }

void Yeti::kill_fall (  )  [virtual]

Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).

Reimplemented from BadGuy.

Definition at line 230 of file yeti.cpp.

00231 {
00232   // shooting bullets or being invincible won't work :)
00233 }

void Yeti::run (  )  [private]

Definition at line 154 of file yeti.cpp.

References BadGuy::dir, BadGuy::physic, RIGHT, RUN, RUN_VX, Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, and state.

Referenced by collision_solid().

00155 {
00156   sprite->set_action((dir==RIGHT)?"run-right":"run-left");
00157   physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX));
00158   physic.set_velocity_y(0);
00159   state = RUN;
00160 }

void Yeti::jump_up (  )  [private]

Definition at line 163 of file yeti.cpp.

References BadGuy::dir, JUMP_UP, JUMP_UP_VX, JUMP_UP_VY, BadGuy::physic, RIGHT, Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, and state.

Referenced by active_update(), and collision_solid().

00164 {
00165   sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
00166   physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX));
00167   physic.set_velocity_y(JUMP_UP_VY);
00168   state = JUMP_UP;
00169 }

void Yeti::be_angry (  )  [private]

Definition at line 172 of file yeti.cpp.

References BE_ANGRY, BadGuy::dir, LEFT, BadGuy::physic, RIGHT, Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, Timer::start(), state, state_timer, stomp_count, and STOMP_WAIT.

Referenced by active_update().

00173 {
00174   //turn around
00175   dir = (dir==RIGHT) ? LEFT : RIGHT;
00176 
00177   sprite->set_action((dir==RIGHT) ? "stand-right" : "stand-left");
00178   physic.set_velocity_x(0);
00179   physic.set_velocity_y(0);
00180   stomp_count = 0;
00181   state = BE_ANGRY;
00182   state_timer.start(STOMP_WAIT);
00183 }

void Yeti::drop_stalactite (  )  [private]

Definition at line 236 of file yeti.cpp.

References Sector::camera, Sector::current(), Sector::gameobjects, MovingObject::get_bbox(), Rectf::get_middle(), BadGuy::get_nearest_player(), hit_points, Camera::shake(), stomp_count, and Vector::x.

Referenced by collision_solid().

00237 {
00238   // make a stalactite falling down and shake camera a bit
00239   Sector::current()->camera->shake(.1f, 0, 10);
00240 
00241   Player* player = this->get_nearest_player();
00242   if (!player) return;
00243 
00244   Sector* sector = Sector::current();
00245   for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
00246       i != sector->gameobjects.end(); ++i) {
00247     YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
00248     if(stalactite && stalactite->is_hanging()) {
00249       float distancex;
00250       if (hit_points >= 3) {
00251         // drop stalactites within 3 of player, going out with each jump
00252         distancex = fabsf(stalactite->get_bbox().get_middle().x - player->get_bbox().get_middle().x);
00253         if(distancex < stomp_count*32) {
00254           stalactite->start_shaking();
00255         }
00256       }
00257       else { /* if (hitpoints < 3) */
00258         // drop every 3rd pair of stalactites
00259         if(((((int)stalactite->get_pos().x + 16) / 64) % 3) == (stomp_count % 3)) {
00260           stalactite->start_shaking();
00261         }
00262       }
00263     } /* if(stalactite && stalactite->is_hanging()) */
00264   }
00265 }

void Yeti::jump_down (  )  [private]

Definition at line 145 of file yeti.cpp.

References BadGuy::dir, JUMP_DOWN, JUMP_DOWN_VX, JUMP_DOWN_VY, BadGuy::physic, RIGHT, Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, and state.

Referenced by collision_solid(), and initialize().

00146 {
00147   sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
00148   physic.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX));
00149   physic.set_velocity_y(JUMP_DOWN_VY);
00150   state = JUMP_DOWN;
00151 }

void Yeti::draw_hit_points ( DrawingContext context  )  [private]

Definition at line 94 of file yeti.cpp.

References BORDER_X, BORDER_Y, DrawingContext::draw_surface(), hit_points, hud_head, LAYER_FOREGROUND1, DrawingContext::pop_transform(), DrawingContext::push_transform(), and DrawingContext::set_translation().

Referenced by draw().

00095 {
00096   int i;
00097 
00098   if (hud_head)
00099   {
00100     context.push_transform();
00101     context.set_translation(Vector(0, 0));
00102 
00103     for (i = 0; i < hit_points; ++i)
00104     {
00105       context.draw_surface(hud_head, Vector(BORDER_X + (i * hud_head->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1);
00106     }
00107 
00108     context.pop_transform();
00109   }
00110 }

void Yeti::take_hit ( Player player  )  [private]

Definition at line 203 of file yeti.cpp.

References COLGROUP_MOVING_ONLY_STATIC, Physic::enable_gravity(), hit_points, BadGuy::physic, SoundManager::play(), BadGuy::run_dead_script(), SAFE_TIME, safe_timer, BadGuy::set_colgroup_active(), Physic::set_velocity_x(), Physic::set_velocity_y(), sound_manager, MovingSprite::sprite, SQUISHED, Timer::start(), Timer::started(), state, state_timer, and YETI_SQUISH_TIME.

Referenced by kill_squished().

00204 {
00205   if(safe_timer.started())
00206     return;
00207 
00208   sound_manager->play("sounds/yeti_roar.wav");
00209   hit_points--;
00210 
00211   if(hit_points <= 0) {
00212     // We're dead
00213     physic.enable_gravity(true);
00214     physic.set_velocity_x(0);
00215     physic.set_velocity_y(0);
00216 
00217     state = SQUISHED;
00218     state_timer.start(YETI_SQUISH_TIME);
00219     set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC);
00220     sprite->set_action("dead");
00221 
00222     run_dead_script();
00223   }
00224   else {
00225     safe_timer.start(SAFE_TIME);
00226   }
00227 }


Member Data Documentation

YetiState Yeti::state [private]

Reimplemented from BadGuy.

Definition at line 60 of file yeti.hpp.

Referenced by active_update(), be_angry(), collision_solid(), jump_down(), jump_up(), run(), and take_hit().

Timer Yeti::state_timer [private]

Reimplemented from BadGuy.

Definition at line 61 of file yeti.hpp.

Referenced by active_update(), be_angry(), collision_solid(), and take_hit().

Timer Yeti::safe_timer [private]

Definition at line 62 of file yeti.hpp.

Referenced by draw(), and take_hit().

int Yeti::stomp_count [private]

Definition at line 63 of file yeti.hpp.

Referenced by be_angry(), collision_solid(), and drop_stalactite().

int Yeti::hit_points [private]

Definition at line 64 of file yeti.hpp.

Referenced by draw_hit_points(), drop_stalactite(), take_hit(), and Yeti().

SurfacePtr Yeti::hud_head [private]

Definition at line 65 of file yeti.hpp.

Referenced by draw_hit_points(), and Yeti().


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