📄 ski.cpp
字号:
return self;
}
/**
* Symbian OS 2 phase constructor. The constructed object is left on the cleanup stack
*/
CMapGallery* CMapGallery::NewLC()
{
CMapGallery* self = new (ELeave) CMapGallery;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Implementation of the MMapPrimitiveToRectConverter mixin method that constructs a
* rectangle that borders the map primitive's sprite
* @param aPrimitive a map primitive of a particular type
* @return a rectangle that borders that map primitive
* @exception can leave with KErrNotFound
*/
TRect CMapGallery::RectangleL(TMapPrimitive aPrimitive) const
{
const TInt count = iArray->Count();
for (TInt ii = 0; ii < count; ii++)
{
CSkiSprite* scenery = iArray->At(ii);
if (scenery->Type() == aPrimitive.Type())
{
return CreateRect(aPrimitive.Posn(), scenery->Bitmap().SizeInPixels());
}
}
return TRect();
}
//
// TMapPrimitiveBoundingRect::
//
/**
* C++ constructor
*/
TMapPrimitiveBoundingRect::TMapPrimitiveBoundingRect()
{
}
/**
* C++ constructor
* @param aSize The size of the bounding rectangle
* @param aHeight The height of the cube
* @param the type of the object bordered by the rectangle
*/
TMapPrimitiveBoundingRect::TMapPrimitiveBoundingRect(TSize aSize, TInt aHeight, TMapPrimitive::TMapObjectType aType) :
iSize(aSize),
iHeight(aHeight),
iType(aType)
{
}
/**
* Bounding rectangle height accessor
* @return the cube height
*/
TInt TMapPrimitiveBoundingRect::Height() const
{
return iHeight;
}
/**
* Bounding rectangle height mutator
* @param the cube height
*/
void TMapPrimitiveBoundingRect::SetHeight(TInt aHeight)
{
iHeight = aHeight;
}
/**
* Bounding rectangle size accessor
* @return the rectangle size
*/
TSize TMapPrimitiveBoundingRect::Size() const
{
return iSize;
}
/**
* Bounding rectangle size mutator
* @param the required rectangle size
*/
void TMapPrimitiveBoundingRect::SetSize(TSize aSize)
{
iSize = aSize;
}
/**
* Bounding rectangle type accessor
* @return the rectangle type
*/
TMapPrimitive::TMapObjectType TMapPrimitiveBoundingRect::Type() const
{
return iType;
}
/**
* Bounding rectangle type mutator
* @param the rectangle type
*/
void TMapPrimitiveBoundingRect::SetType(TMapPrimitive::TMapObjectType aType)
{
iType = aType;
}
//
// CMapPrimitiveBoundingRects::
//
/**
* Standard Symbian OS 2 phase constructor
*/
CMapPrimitiveBoundingRects* CMapPrimitiveBoundingRects::NewL()
{
CMapPrimitiveBoundingRects* self = NewLC();
CleanupStack::Pop(self);
return self;
}
/**
* Standard Symbian OS 2 phase constructor. The object is left on the
* cleanup stack
*/
CMapPrimitiveBoundingRects* CMapPrimitiveBoundingRects::NewLC()
{
CMapPrimitiveBoundingRects* self = new (ELeave)CMapPrimitiveBoundingRects;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Standard C++ 2nd phase contructor
*/
void CMapPrimitiveBoundingRects::ConstructL()
{
iRects = new (ELeave) CBoundingRectArray(KSkiArrayGranularity);
}
/**
* Destructor
*/
CMapPrimitiveBoundingRects::~CMapPrimitiveBoundingRects()
{
delete iRects;
}
/**
* Retrieve the size of a map object's bounding rectangle
* @param aType the object type
* @return the size of the bounding rectangle
* @excpetion Leaves with KErrNotFound if no type in the list matches aType
*/
TSize CMapPrimitiveBoundingRects::SizeL(TMapPrimitive::TMapObjectType aType) const
{
const TInt count = iRects->Count();
for (TInt ii = 0; ii < count; ii++)
{
TMapPrimitiveBoundingRect bounder = iRects->At(ii);
if (bounder.Type() == aType)
{
return bounder.Size();
}
}
return TSize();
}
/**
* Adds the size of a map object's bounding rectangle
* @param aSize the size of the bounding rectangle
* @param aHeight the size of the bounding rectangle
* @param aType the object type
*/
void CMapPrimitiveBoundingRects::AddSizeL(TSize aSize, TInt aHeight, TMapPrimitive::TMapObjectType aType) const
{
const TInt count = iRects->Count();
for (TInt ii = 0; ii < count; ii++)
{
TMapPrimitiveBoundingRect bounder = iRects->At(ii);
if (bounder.Type() == aType)
{
User::Leave(KErrAlreadyExists);
}
}
iRects->AppendL(TMapPrimitiveBoundingRect(aSize, aHeight, aType));
}
/**
* Retrieve a map object's bounding rectangle
* @param aPrimitive the object type
* @return the bounding rectangle
*/
TRect CMapPrimitiveBoundingRects::RectangleL(TMapPrimitive aPrimitive) const
{
const TInt count = iRects->Count();
for (TInt ii = 0; ii < count; ii++)
{
TMapPrimitiveBoundingRect bounder = iRects->At(ii);
if (bounder.Type() == aPrimitive.Type())
{
if (bounder.Height() >= iElevation)
{
return CreateRect(aPrimitive.Posn(), bounder.Size());
}
else
{
break;
}
}
}
return TRect();
}
/**
* Accessor to the map object elevation, used in the collision detection to determine
* if the skier has jumped over an object or not
* @return the elevation
*/
TInt CMapPrimitiveBoundingRects::Elevation() const
{
return iElevation;
}
/**
* Mutator of the map object elevation, used in the collision detection to determine
* if the skier has jumped over an object or not
* @param aElevation the elevation
*/
void CMapPrimitiveBoundingRects::SetElevation(TInt aElevation)
{
iElevation = aElevation;
}
//
// TSkierAttribs::
//
//
// skier physic properties + state enum
//
/**
* C++ constructor
*/
TSkierAttribs::TSkierAttribs()
{
}
/**
* Accessor to a vector representing the skier's position
* @return the position
*/
const TSkiVector& TSkierAttribs::Posn() const
{
return iPosn;
}
/**
* Mutator of a vector representing the skier's position
* @param the position
*/
void TSkierAttribs::SetPosn(const TSkiVector& aPosn)
{
iPosn = aPosn;
}
/**
* Skier elevation accessor
* @return the skier elevation
*/
TInt TSkierAttribs::Elevation() const
{
return iElevation;
}
/**
* Skier elevation mutator
* @param aElevation the skier elevation
*/
void TSkierAttribs::SetElevation(TInt aElevation)
{
iElevation = aElevation;
}
/**
* Accessor to a vector representing the skier's velocity
* @return the velocity
*/
const TSkiVector& TSkierAttribs::Vel() const
{
return iVel;
}
/**
* Mutator of a vector representing the skier's velocity
* @param the velocity
*/
void TSkierAttribs::SetVel(const TSkiVector& aVel)
{
iVel = aVel;
}
/**
* Accessor to a vector representing the skier's acceleration
* @return the acceleration
*/
const TSkiVector& TSkierAttribs::Accel() const
{
return iAccel;
}
/**
* Mutator of a vector representing the skier's acceleration
* @param the acceleration
*/
void TSkierAttribs::SetAccel(const TSkiVector& aAccel)
{
iAccel = aAccel;
}
/**
* Accessor to the size of the force that makes the skier jump
* @return the jump force
*/
TInt TSkierAttribs::JumpForce() const
{
return iJumpForce;
}
/**
* Mutator of the size of the force that makes the skier jump
* @param the jump force
*/
void TSkierAttribs::SetJumpForce(TInt aForce)
{
iJumpForce = aForce;
}
/**
* Accessor to gravity force that brings the skier down to earth
* @return gravity
*/
TInt TSkierAttribs::Gravity() const
{
return iGravity;
}
/**
* Mutator of gravity force
* @param aGravity gravity
*/
void TSkierAttribs::SetGravity(TInt aGravity)
{
iGravity = aGravity;
}
/**
* Returns the state is the skier in
* @return an enumerated value that describes the skier's state or direction
*/
TSkierAttribs::TSkierState TSkierAttribs::State() const
{
return static_cast<TSkierAttribs::TSkierState>(iState);
}
/**
* Puts the skier in a state
* @param aState the required state
*/
void TSkierAttribs::SetState(TSkierAttribs::TSkierState aState)
{
iState = aState;
}
/**
* The time in milliseconds that the skier stays down on the ground
* @return That time that I was just talking about then
*/
TInt TSkierAttribs::FallTickCount() const
{
return iFallTickCount;
}
/**
* Set how long the skier stays on the ground fallen down
* @param aCount how long the skier stays on the ground
*/
void TSkierAttribs::SetFallTickCount(TInt aCount)
{
iFallTickCount = aCount;
}
/**
* Rotates the skier direction clockwise
*/
void TSkierAttribs::RotateClockwise()
{
if (iState != ESkier0)
{
iState--;
}
}
/**
* Rotates the skier direction anti-clockwise
*/
void TSkierAttribs::RotateAntiClockwise()
{
if (iState != ESkier180)
{
iState++;
}
}
/**
* Returns the skier's size
* @return the skier size
*/
TSize TSkierAttribs::SkierSize() const
{
return iSkierSize;
}
/**
* Sets the skier's size
* @param the skier size
*/
void TSkierAttribs::SetSkierSize(TSize aSize)
{
iSkierSize = aSize;
}
//
//CSkier::
//
/**
* Symbian OS 2 phase constructor.
*/
CSkier* CSkier::NewL()
{
CSkier* self = CSkier::NewLC();
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor. The object is left on the cleanup stack
*/
CSkier* CSkier::NewLC()
{
CSkier* self = new (ELeave) CSkier();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* destructor
*/
CSkier::~CSkier()
{
delete iGallery;
}
/**
* Accessor to the skier's sprites
* @return the skier's sprites
*/
CGameGallery& CSkier::Gallery()
{
return *iGallery;
}
/**
* Accessor to the skier's sprites
* @return the skier's sprites
*/
const CGameGallery& CSkier::Gallery() const
{
return *iGallery;
}
/**
* Accessor to the sprite that represents the skier's current state
* @return the current skier sprite
*/
const CSkiSprite& CSkier::SpriteL() const
{
return iGallery->SpriteL(iAttribs.State());
}
/**
* Accessor to the sprite that represents the skier's current state
* @return the current skier sprite
*/
CSkiSprite& CSkier::SpriteL()
{
return iGallery->SpriteL(iAttribs.State());
}
/**
* C++ constructor
*/
CSkier::CSkier()
{
}
/**
* Standard Symbian OS 2nd phase construction
*/
void CSkier::ConstructL()
{
iGallery = CGameGallery::NewL();
}
/**
* Accessor to the skier's attributes
* @return the skier attributes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -