📄 tsprite32x24.cpp
字号:
// Copyright 2002 Kenneth Guy,
//
// TSprite32x24.cpp
/** \file TSprite32x24.cpp
implementation of class TSprite32x24 */
#include "TSprite32x24.h"
#include "CGame.h"
#include "CMap.h"
#include "TGamePanics.h"
/** Constructor */
TSprite32x24::TSprite32x24() : iSpritePos(NULL),
iDrawEnd(NULL),
iCollision(0),
iSpriteNo(-1) {
}
/** Plot the sprite to CMap.
@param aMap The offscreen map to plot the sprite to.
@param aSprites The sprite data, aSprites + iSpriteNo*32*64 gives the
sprite to plot.
@post iSpritePos and iDraw end are set up for Remove()
*/
void TSprite32x24::Plot(CMap &aMap,const TUint16 *aSprites) {
__ASSERT_ALWAYS(iSpriteNo!=-1,TGamePanics::Panic(TGamePanics::ESpriteNumberNotSet));
// work out the location in the offscreen map to plot the sprite
iDrawEnd=aMap.DrawEnd();
iSpritePos= aMap.BlitStart()+(11*64*iY)+(iX*2);
// wrap at the end of the the offscreen map
if(iSpritePos >= iDrawEnd)
iSpritePos -= (11*64*200); // 11 64 pixel map sprites, 200 lines
// plot the sprite, storing away the background and checking
// if the background contained a bullet/landscape/players ship etc.
iCollision=PlotAsm(aSprites+(iSpriteNo*32*24));
};
/** Erases the sprite
@pre iSpritePos and iDrawEnd have been set up by Plot()
*/
void TSprite32x24::Remove() {
__ASSERT_ALWAYS(iSpritePos!=NULL && iDrawEnd!=NULL,TGamePanics::Panic(TGamePanics::ESpriteRemoveCalledWithoutPlot));
// put the background back
RemoveAsm();
iSpritePos=NULL;
iDrawEnd=NULL;
}
/** Sets the sprite number to plot.
Will be used by Plot() to select which sprite to draw.
*/
void TSprite32x24::SetSpriteNo(TInt16 aSpriteNo) {
iSpriteNo = aSpriteNo;
}
/** Set sprite number to -1.
Plot() will panic if asked to draw the sprite. Used() will return
EFalse if quiered.
*/
void TSprite32x24::ClearSprite() {
iSpriteNo = -1;
}
/** Is the sprite currently in use? */
TBool TSprite32x24::Used() {
return iSpriteNo < 0 ? EFalse : ETrue;
}
/** 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.
@return Collision information. */
TSprite32x24::THit TSprite32x24::Hit() {
// each two pixel word as 8 bits that aren't used for colour information
// so this uses them to work out what it was behind the sprite
if(iCollision & 0xf000 ) {
return (THit) (((THit) ((iCollision & 0xf000) >> 12)-1) + EHitBullet1);
} else if(iCollision & 0x80000000) {
return EHitLandScape;
} else if(iCollision & 0x20000000) {
return EHitShip;
} else if(iCollision & 0x40000000) {
return EHitShipExtension;
} else {
return EHitNone;
}
};
/** \fn TInt32 TSprite32x24::PlotAsm(const TUint16* aSpriteData)
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
\param aSpriteData The sprite information.
\returns Collision information. Logical or of all background sprite
information for pixels that where plotted (ie non-zero).
*/
/** \fn void TSprite32x24::RemoveAsm()
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
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -