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

TSprite32x24 Class Reference

Class used for the moving sprites. More...

#include <TSprite32x24.h>

Inheritance diagram for TSprite32x24:

Inheritance graph
[legend]
List of all members.

Public Types

enum  THit {
  EHitNone, EHitShip, EHitShipExtension, EHitLandScape,
  EHitBullet1, EHitBullet2, EHitBullet3, EHitBullet4,
  EHitBullet5, EHitBullet6, EHitBullet7, EHitBullet8
}
 Enum describing what is under the sprite. More...


Public Methods

 TSprite32x24 ()
 Constructor. More...

void Plot (CMap &aMap, const TUint16 *aSprites)
 Plot the sprite to CMap. More...

void Remove ()
 Erases the sprite. More...

THit Hit ()
 Checks what the sprite was plotted over. More...

void SetSpriteNo (TInt16 aSpriteNo)
 Sets the sprite number to plot. More...

void ClearSprite ()
 Set sprite number to -1. More...

TBool Used ()
 Is the sprite currently in use? More...


Public Attributes

TInt16 iX
 X coordinate of the sprite. More...

TInt16 iY
 Y coordinate of the sprite. More...


Protected Attributes

TUint32 iCollision
 Collision information. More...

TInt16 iSpriteNo
 Number of the sprite to plot. More...


Private Methods

void RemoveAsm ()
 Arm assembler to erase the sprite. More...

TUint32 PlotAsm (const TUint16 *aSpriteData)
 Arm assembler to plot the sprite. More...


Private Attributes

TUint16 * iSpritePos
 Memory location to plot the sprite. More...

TUint16 * iDrawEnd
 End of offscreen map. More...

TUint16 iBehindSprite [32 *24]
 Area behind the sprite. More...


Detailed Description

Class used for the moving sprites.

This class plots a 32x24 pixel sprite onto the off screen map (class CMap). The Plot() function stores away the background behind the sprite so that the Remove() function can erase the sprite. The Plot() function checks the top four bits of each pixel of the background for collision information which can be queried with the Hit() member.

Definition at line 30 of file TSprite32x24.h.


Member Enumeration Documentation

enum TSprite32x24::THit
 

Enum describing what is under the sprite.

Enumeration values:
EHitNone  Nothing.
EHitShip  Players ship.
EHitShipExtension  Extension parts of the players ship, unused.
EHitLandScape  Background landscape.
EHitBullet1  Players bullets.
EHitBullet2  Players bullets.
EHitBullet3  Players bullets.
EHitBullet4  Players bullets.
EHitBullet5  Players bullets.
EHitBullet6  Players bullets.
EHitBullet7  Players bullets.
EHitBullet8  Players bullets.

Definition at line 33 of file TSprite32x24.h.

Referenced by CGame::Collisions(), and Hit().

00033             {
00034     EHitNone, 
00035     EHitShip, 
00036     EHitShipExtension, 
00037     EHitLandScape, 
00038     EHitBullet1,  
00039     EHitBullet2,  
00040     EHitBullet3,  
00041     EHitBullet4,  
00042     EHitBullet5,  
00043     EHitBullet6,  
00044     EHitBullet7,  
00045     EHitBullet8,  
00046   };


Constructor & Destructor Documentation

TSprite32x24::TSprite32x24  
 

Constructor.

Definition at line 20 of file TSprite32x24.cpp.

00020                             : iSpritePos(NULL),
00021                                 iDrawEnd(NULL),
00022                                 iCollision(0),
00023                                 iSpriteNo(-1) {
00024 }


Member Function Documentation

void TSprite32x24::Plot CMap   aMap,
const TUint16 *    aSprites
 

Plot the sprite to CMap.

Parameters:
aMap  The offscreen map to plot the sprite to.
aSprites  The sprite data, aSprites + iSpriteNo*32*64 gives the sprite to plot.
Postcondition:
iSpritePos and iDraw end are set up for Remove()

Definition at line 36 of file TSprite32x24.cpp.

References CMap::BlitStart(), CMap::DrawEnd(), TGamePanics::ESpriteNumberNotSet, iCollision, iDrawEnd, iSpriteNo, iSpritePos, iX, iY, TGamePanics::Panic(), and PlotAsm().

Referenced by CGame::DrawEveryThing().

00036                                                           {
00037   __ASSERT_ALWAYS(iSpriteNo!=-1,TGamePanics::Panic(TGamePanics::ESpriteNumberNotSet));
00038 
00039   // work out the location in the offscreen map to plot the sprite
00040   iDrawEnd=aMap.DrawEnd();
00041   iSpritePos= aMap.BlitStart()+(11*64*iY)+(iX*2);
00042 
00043   // wrap at the end of the the offscreen map
00044   if(iSpritePos >= iDrawEnd)
00045     iSpritePos -= (11*64*200); // 11 64 pixel map sprites, 200 lines
00046 
00047   // plot the sprite, storing away the background and checking
00048   // if the background contained a bullet/landscape/players ship etc.
00049   iCollision=PlotAsm(aSprites+(iSpriteNo*32*24));
00050 };

void TSprite32x24::Remove  
 

Erases the sprite.

Precondition:
iSpritePos and iDrawEnd have been set up by Plot()

Definition at line 59 of file TSprite32x24.cpp.

References TGamePanics::ESpriteRemoveCalledWithoutPlot, iDrawEnd, iSpritePos, TGamePanics::Panic(), and RemoveAsm().

Referenced by CGame::RemoveEveryThing().

00059                           {
00060   __ASSERT_ALWAYS(iSpritePos!=NULL && iDrawEnd!=NULL,TGamePanics::Panic(TGamePanics::ESpriteRemoveCalledWithoutPlot));
00061   // put the background back
00062   RemoveAsm();
00063   iSpritePos=NULL;
00064   iDrawEnd=NULL;
00065 }

TSprite32x24::THit TSprite32x24::Hit  
 

Checks what the sprite was plotted over.

Plot() stores away the logical or of each background pixel. The top four bits of each 16bit word of these are then used to determine what the sprite was plotted over. The top four bits of the top word are used for landscape, players ship, and ship extension. The top four bits of the bottom word are used for hitting the players bullets.

Returns:
Collision information.

Definition at line 103 of file TSprite32x24.cpp.

References EHitBullet1, EHitLandScape, EHitNone, EHitShip, EHitShipExtension, iCollision, and THit.

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

00103                                    {
00104   // each two pixel word as 8 bits that aren't used for colour information
00105   // so this uses them to work out what it was behind the sprite
00106   if(iCollision & 0xf000 ) {
00107     return (THit) (((THit) ((iCollision & 0xf000) >> 12)-1) + EHitBullet1);
00108   } else if(iCollision & 0x80000000) {
00109     return EHitLandScape;
00110   } else if(iCollision & 0x20000000) {
00111     return EHitShip;
00112   } else if(iCollision & 0x40000000) {
00113     return EHitShipExtension;
00114   } else {
00115     return EHitNone;
00116   }
00117 };

void TSprite32x24::SetSpriteNo TInt16    aSpriteNo
 

Sets the sprite number to plot.

Will be used by Plot() to select which sprite to draw.

Definition at line 73 of file TSprite32x24.cpp.

References iSpriteNo.

Referenced by TBadGuy::Init(), TBadGuy::Move(), TBadGuy::PathMove(), TBullet::Shoot(), and TPlayersShip::UpdateSprite().

00073                                                {
00074   iSpriteNo = aSpriteNo;
00075 }

void TSprite32x24::ClearSprite  
 

Set sprite number to -1.

Plot() will panic if asked to draw the sprite. Used() will return EFalse if quiered.

Definition at line 83 of file TSprite32x24.cpp.

References iSpriteNo.

Referenced by TBullet::AddHealth(), TBadGuy::Die(), TBadGuy::HitBullet(), TBullet::Move(), and TBadGuy::Move().

00083                                {
00084   iSpriteNo = -1;
00085 }

TBool TSprite32x24::Used  
 

Is the sprite currently in use?

Definition at line 89 of file TSprite32x24.cpp.

References iSpriteNo.

Referenced by CGame::AddBadGuy(), CGame::Collisions(), CGame::DamageBadGuys(), CGame::DrawEveryThing(), CGame::MoveThings(), CGame::RemoveEveryThing(), and CGame::Shoot().

00089                          {
00090   return iSpriteNo < 0 ? EFalse : ETrue;
00091 }

void TSprite32x24::RemoveAsm   [private]
 

Arm assembler to erase the sprite.

Code copies sprite information from iBehindSprite to iSpritePos

The remove will wrap back to the beginning of the draw area is drawing the sprite goes beyond iDrawEnd.

defined in the file removesprite.s

Referenced by Remove().

TInt32 TSprite32x24::PlotAsm const TUint16 *    aSpriteData [private]
 

Arm assembler to plot the sprite.

Code copies sprite information from aSpriteData to iSpritePos, stores the background in iBehindSprite. Will not write pixels that are all 0.

The plot will wrap back to the beginning of the draw area is drawing the sprite goes beyond iDrawEnd.

defined in the file sprite.s

Parameters:
aSpriteData  The sprite information.
Returns:
Collision information. Logical or of all background sprite information for pixels that where plotted (ie non-zero).

Referenced by Plot().


Member Data Documentation

TUint16* TSprite32x24::iSpritePos [private]
 

Memory location to plot the sprite.

Set up from iX and iY by Plot() and NULL'd by Remove(), Must be the first member of class or assembler routines sprites.s and remove_sprite.s muxt changed.

Definition at line 64 of file TSprite32x24.h.

Referenced by Plot(), and Remove().

TUint16* TSprite32x24::iDrawEnd [private]
 

End of offscreen map.

Read from CMap by Plot() and NULL'd by Remove(), Must be the second member of class or assembler routines sprites.s and remove_sprite.s muxt changed.

Definition at line 66 of file TSprite32x24.h.

Referenced by Plot(), and Remove().

TUint16 TSprite32x24::iBehindSprite[32*24] [private]
 

Area behind the sprite.

Stored to by PlotAsm() and used by RemoveAsm() to erase the sprite, Must be the third member of class or assembler routines sprites.s and remove_sprite.s muxt changed.

Definition at line 68 of file TSprite32x24.h.

TUint32 TSprite32x24::iCollision [protected]
 

Collision information.

Orr'd collection of the backgrounds overwritten during the last Plot, used by Hit() to calculate what the sprite was plotted over.

Definition at line 72 of file TSprite32x24.h.

Referenced by Hit(), and Plot().

TInt16 TSprite32x24::iSpriteNo [protected]
 

Number of the sprite to plot.

Definition at line 74 of file TSprite32x24.h.

Referenced by ClearSprite(), Plot(), SetSpriteNo(), and Used().

TInt16 TSprite32x24::iX
 

X coordinate of the sprite.

Runs from 0->351 with 16->303 being the visible section of the screen. Each increment in iX is equal to 2 pixels ie one 32bit word

Definition at line 77 of file TSprite32x24.h.

Referenced by TBadGuy::Init(), TBullet::Move(), TBadGuy::Move(), TPlayersShip::MoveBy(), CGame::MoveThings(), TBadGuy::PathMove(), CGame::Play(), Plot(), TBullet::Shoot(), CGame::Shoot(), TBadGuy::SimpleMove(), and TPlayersShip::TPlayersShip().

TInt16 TSprite32x24::iY
 

Y coordinate of the sprite.

Runs from -24->223 with 0->199 being the visible

Definition at line 79 of file TSprite32x24.h.

Referenced by TBadGuy::Init(), TBadGuy::Move(), TPlayersShip::MoveBy(), CGame::MoveThings(), TBadGuy::PathMove(), Plot(), TBullet::Shoot(), CGame::Shoot(), TBadGuy::SimpleMove(), and TPlayersShip::TPlayersShip().


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