Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

TPlayersShip Class Reference

Handles players ship. More...

#include <TPlayersShip.h>

Inheritance diagram for TPlayersShip:

Inheritance graph
[legend]
Collaboration diagram for TPlayersShip:

Collaboration graph
[legend]
List of all members.

Public Methods

 TPlayersShip (TInt16 aX, TInt16 aY, TInt16 aHealth, TInt16 aShipSprite, TInt16 aCrashingStartSprite, TInt16 aCrashingEndSprite)
 Construct a players ship. More...

void AddHealth (TInt16 aHealth)
 Change players health. More...

void SetHealth (TInt16 aHealth)
 Set players health. More...

TInt16 Health ()
 Query players health. More...

TBool Dieing ()
 Is the ship currently exploding. More...

TBool Dead ()
 Is the ship dead. More...

void MoveBy (TInt16 aX, TInt16 aY, TBool aAllowOfScreen)
 Handles movement of players ship. More...


Private Methods

void UpdateSprite ()
 Update sprite. More...


Private Attributes

TInt16 iHealth
 Players health, <=0 is dead. More...

TInt16 iCrashFrame
 which explosion sprite to plot while dieing. More...

TInt16 iShipSprite
 sprite of healthy ship. More...

TInt16 iCrashingStartSprite
 sprite thats starts explosion. More...

TInt16 iCrashingEndSprite
 last sprite of explosion animation. More...

TInt16 iLastX
 last position. More...

TInt16 iLastY
 last position. More...


Detailed Description

Handles players ship.

Handles movement, it keeps the ship sprite within the visible area of the the offscreen map. It also keeps track of the health of the ship, changing the ship sprite to each of the explosion sprites in turn when the health drops to zero.

Definition at line 27 of file TPlayersShip.h.


Constructor & Destructor Documentation

TPlayersShip::TPlayersShip TInt16    aX,
TInt16    aY,
TInt16    aHealth,
TInt16    aShipSprite,
TInt16    aCrashingStartSprite,
TInt16    aCrashingEndSprite
 

Construct a players ship.

Parameters:
aX  Initial X position.
aY  Initial Y position.
aHealth  Initial health.
aShipSprite  Sprite to use for healthy ship.
aCrashingStartSprite  First frame of explosion animation
aCrashingSpriteEnd  Last frame of explosion animation (inclusive)

Definition at line 26 of file TPlayersShip.cpp.

References iLastX, iLastY, TSprite32x24::iX, TSprite32x24::iY, and UpdateSprite().

00028                                                       :
00029   iHealth(aHealth), iCrashFrame(0),
00030   iShipSprite(aShipSprite),
00031   iCrashingStartSprite(aCrashingStartSprite),
00032   iCrashingEndSprite(aCrashingEndSprite) {
00033 
00034   iX=aX;
00035   iY=aY;
00036   iLastX=aX;
00037   iLastY=aY;
00038   UpdateSprite();
00039 }


Member Function Documentation

void TPlayersShip::AddHealth TInt16    aHealth
 

Change players health.

Is iHealth <= 0 player is dead and explosion animation starts.

Definition at line 64 of file TPlayersShip.cpp.

References iHealth, and SetHealth().

Referenced by TBadGuy::HitShip().

00064                                            {
00065   SetHealth(iHealth+aHealth);
00066 }

void TPlayersShip::SetHealth TInt16    aHealth
 

Set players health.

Is aHealth <= 0 player is dead and explosion animation starts.

Definition at line 74 of file TPlayersShip.cpp.

References iCrashFrame, iHealth, and UpdateSprite().

Referenced by AddHealth(), TBadGuy::HitShip(), and CGame::Play().

00074                                            {
00075   if(iCrashFrame==0) {
00076     iHealth=aHealth;
00077     if(iHealth <= 0) {
00078       iHealth=0;
00079       iCrashFrame=2;
00080     }
00081     UpdateSprite();
00082   }
00083 }

TInt16 TPlayersShip::Health  
 

Query players health.

Returns:
Health, Health <=0 is dead or dieing

Definition at line 91 of file TPlayersShip.cpp.

References iHealth.

Referenced by CGame::Play().

00091                              {
00092   return iHealth;
00093 }

TBool TPlayersShip::Dieing  
 

Is the ship currently exploding.

This is used to stop the player finishing the level or shooting while the ship is exploding.

Returns:
ETrue if dieing or dead.

Definition at line 104 of file TPlayersShip.cpp.

References iCrashFrame.

Referenced by CGame::HandleKeys(), and CGame::Play().

00104                            {
00105   return iCrashFrame == 0 ? EFalse : ETrue;
00106 }

TBool TPlayersShip::Dead  
 

Is the ship dead.

Returns:
ETrue if the player has finished exploding.

Definition at line 114 of file TPlayersShip.cpp.

References iCrashFrame, iCrashingEndSprite, and iCrashingStartSprite.

Referenced by CGame::Play().

00114                          {
00115   TInt16 spriteNo=iCrashingStartSprite+((iCrashFrame/2)-1);
00116   if(spriteNo <= iCrashingEndSprite) {
00117     return EFalse;
00118   } else {
00119     return ETrue;
00120   }
00121 }

void TPlayersShip::MoveBy TInt16    aX,
TInt16    aY,
TBool    aAllowOfScreen
 

Handles movement of players ship.

Called for for each frame of the game. The function is used to both move the ship and to animate the explossion of the ship. It could also be used to provide an animated ship, or different ships when the player is moving in different directions, saves last x and y positions so we could do bouncing of bad guys.

Parameters:
aX  X movement of players ship.
aY  Y movement of players ship.
aAllowOfScreen  ETrue at the end of the level to allow the player to fly off the end of the level, and hence finish the level.

Definition at line 139 of file TPlayersShip.cpp.

References iCrashFrame, iLastX, iLastY, TSprite32x24::iX, TSprite32x24::iY, and UpdateSprite().

Referenced by CGame::HandleKeys().

00139                                                                    {
00140   iLastX=iX;
00141   iLastY=iY;
00142   iX+=aX;
00143   iY+=aY;
00144   if(iY<0) iY=0;
00145   if(iY>176) iY=176;
00146   if(iX<16) iX=16;
00147 
00148   // allow player to fly off screen at end of level
00149   if(aAllowOfScreen!=EFalse) {
00150     if(iX>304) iX=304;
00151   } else {
00152     if(iX>288) iX=288;
00153   }  
00154 
00155   // if crashing animate,
00156   if(iCrashFrame!=0) {
00157     iCrashFrame++;
00158   }
00159   UpdateSprite();
00160 }

void TPlayersShip::UpdateSprite   [private]
 

Update sprite.

Either set the sprite to the healthy ship or the correct frame of the explossion.

Definition at line 48 of file TPlayersShip.cpp.

References iCrashFrame, iCrashingEndSprite, iCrashingStartSprite, iShipSprite, and TSprite32x24::SetSpriteNo().

Referenced by MoveBy(), SetHealth(), and TPlayersShip().

00048                                 {
00049   if(iCrashFrame!=0) {
00050     TInt16 spriteNo=iCrashingStartSprite+((iCrashFrame/2)-1);
00051     if(spriteNo <= iCrashingEndSprite)
00052       SetSpriteNo(spriteNo);
00053   } else {
00054     SetSpriteNo(iShipSprite);
00055   }
00056 }


Member Data Documentation

TInt16 TPlayersShip::iHealth [private]
 

Players health, <=0 is dead.

Definition at line 43 of file TPlayersShip.h.

Referenced by AddHealth(), Health(), and SetHealth().

TInt16 TPlayersShip::iCrashFrame [private]
 

which explosion sprite to plot while dieing.

Definition at line 44 of file TPlayersShip.h.

Referenced by Dead(), Dieing(), MoveBy(), SetHealth(), and UpdateSprite().

TInt16 TPlayersShip::iShipSprite [private]
 

sprite of healthy ship.

Definition at line 45 of file TPlayersShip.h.

Referenced by UpdateSprite().

TInt16 TPlayersShip::iCrashingStartSprite [private]
 

sprite thats starts explosion.

Definition at line 46 of file TPlayersShip.h.

Referenced by Dead(), and UpdateSprite().

TInt16 TPlayersShip::iCrashingEndSprite [private]
 

last sprite of explosion animation.

Definition at line 47 of file TPlayersShip.h.

Referenced by Dead(), and UpdateSprite().

TInt16 TPlayersShip::iLastX [private]
 

last position.

Definition at line 48 of file TPlayersShip.h.

Referenced by MoveBy(), and TPlayersShip().

TInt16 TPlayersShip::iLastY [private]
 

last position.

Definition at line 49 of file TPlayersShip.h.

Referenced by MoveBy(), and TPlayersShip().


The documentation for this class was generated from the following files:
Documentation for Game (Beta) version 1.44.