📄 ski.cpp
字号:
/**
*
* @brief Definition of Skiing Classes
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
#include "ski.h"
#include <e32math.h> //Maths
#include <AknUtils.h> //CompletePathWithAppPath utility method
#include <images.mbg>
#include <eikenv.h>
#include "doublebufferedarea.h"
#include "skiconstants.h"
_LIT (KMultiBitmapFilename,"\\System\\Apps\\Skiing\\images.mbm");
//
//TMapPrimitive
//
/*
* C++ constructor
* @param aPosn the position of the map primitive
* @param aType the type of the map primitive
*/
TMapPrimitive::TMapPrimitive(const TPoint& aPosn, TMapPrimitive::TMapObjectType aType) :
iPosn(aPosn),
iType(aType)
{
}
/*
* Position accessor
* @return the primitive position
*/
const TPoint& TMapPrimitive::Posn() const
{
return iPosn;
}
/*
* Type accessor
* @return the primitive type
*/
TMapPrimitive::TMapObjectType TMapPrimitive::Type() const
{
return iType;
}
/*
* Type mutator
* @param aType the primitive type
*/
void TMapPrimitive::SetType(TMapObjectType aType)
{
iType = aType;
}
//
// MMapPrimitiveToRectConverter
//
/*
* Implementation to spawn a rectangle from a point on the map. The point is at the
* bottom centre of the spawned rectangle
* @param aPosn the position of the bottom centre of the spawned rectangle
* @param aSize the size of the rectangle generated
* @return a rectangle of the required dimensions
*/
TRect MMapPrimitiveToRectConverter::CreateRect(TPoint aPosn, TSize aSize) const
{
TRect rect(aPosn, aSize);
// map position is bottom centre of object
rect.Move(-aSize.iWidth / 2, -aSize.iHeight);
return rect;
}
//
//CSkiMap
//
/**
* Symbian OS 2 phase constructor.
*/
CSkiMap* CSkiMap::NewL()
{
CSkiMap* self = NewLC();
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor. The constructed object is left on the cleanup stack
*/
CSkiMap* CSkiMap::NewLC()
{
CSkiMap* self = new (ELeave) CSkiMap;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Symbian OS 2 phase constructor. The constructed object is left on the cleanup stack
* @param aArray a pre-constructed array of map primitives that this map will hold
*/
CSkiMap* CSkiMap::NewLC(CMapPrimitiveArray* aArray)
{
CSkiMap* self = new (ELeave) CSkiMap(aArray);
CleanupStack::PushL(self);
// self->ConstructL();
return self;
}
/*
* Standard c++ constructor
*/
CSkiMap::CSkiMap()
{
}
/*
* Standard c++ constructor
* @param aArray a pre-constructed array of map primitives that this map will hold
*/
CSkiMap::CSkiMap(CMapPrimitiveArray* aArray) :
iArray(aArray)
{
_LIT(KSkiPanic, "Ski Application Panic");
__ASSERT_ALWAYS(aArray != NULL, User::Panic(KSkiPanic, KErrArgument));
}
/*
* destructor
*/
CSkiMap::~CSkiMap()
{
delete iArray;
}
/*
* Accessor to the map primitives in the map
*/
CMapPrimitiveArray& CSkiMap::PrimitiveArray()
{
return *iArray;
}
/*
* Accessor to the map primitives in the map
*/
const CMapPrimitiveArray& CSkiMap::PrimitiveArray() const
{
return *iArray;
}
/*
* Finds all the objects in the map that are within a particular area.
* @param aArea the area in the map to be queried for map objects
* @param aRectRep a reference to an object that can convert the position of a map primitive into a rectangle
* @return a map containing any map objects in the area specified
*/
CSkiMap* CSkiMap::IntersectsLC(const TRect& aArea, const MMapPrimitiveToRectConverter& aRectRep)
{
CMapPrimitiveArray* array = new (ELeave) CMapPrimitiveArray(KSkiArrayGranularity);
CleanupStack::PushL(array);
const TInt count = iArray->Count();
for (TInt ii = 0; ii < count; ii++)
{
TMapPrimitive primitive = iArray->At(ii);
TRect rect = aRectRep.RectangleL(primitive);
TSize size = rect.Size();
// No object on the map will have a rectangle
// equivalent of zero-size - implementations of
// RectangleL return an empty rectangle if there's
// no stored TRect for that type
if ((size.iWidth > 0 || size.iHeight > 0) && rect.Intersects(aArea))
{
array->AppendL(primitive);
}
}
CSkiMap* retval = NewLC(array);
CleanupStack::Pop(2, array);
CleanupStack::PushL(retval);
return retval;
}
/*
* Finds all the objects in the map of the specified type
* @param aType A bitmask of the types required from the map (defined in TMapPrimitive::TMapObjectType)
* @return an array of the required objects on the cleanup stack, empty if none were found
*/
CMapPrimitiveArray* CSkiMap::TypeLC(TInt aType)
{
CMapPrimitiveArray* array = new (ELeave) CMapPrimitiveArray(KSkiArrayGranularity);
CleanupStack::PushL(array);
const TInt count = iArray->Count();
for (TInt ii = 0; ii < count; ii++)
{
TMapPrimitive primitive = iArray->At(ii);
if ((primitive.Type() & aType) != 0)
{
array->AppendL(primitive);
}
}
return array;
}
/*
* Standard 2nd phase construction
*/
void CSkiMap::ConstructL()
{
iArray = new (ELeave) CMapPrimitiveArray(KSkiArrayGranularity);
}
/*
* Accessor to the map limits
* @return the map extents
*/
TSize CSkiMap::MapLimits() const
{
return iLimits;
}
/*
* Set the size of the map
* @param aSize sets the extents of the map
*/
void CSkiMap::SetMapLimits(TSize aSize)
{
iLimits = aSize;
}
//
//TSkiScreenAttribs::
//
/*
* Accessor to the screen bounds
* @return the screen bounds
*/
const TRect& TSkiScreenAttribs::Rect() const
{
return iRect;
}
/*
* Accessor to the screen bounds
* @return the screen bounds
*/
TRect& TSkiScreenAttribs::Rect()
{
return iRect;
}
/*
* Accessor to the screen offset ie. the position of the top left corner of the
* screen on the game map
* @return the screen offset
*/
TPoint TSkiScreenAttribs::Offset() const
{
return iRect.iTl;
}
/*
* Mutator of the screen offset ie. the position of the top left corner of the
* screen on the game map
* @param the new screen offset
*/
void TSkiScreenAttribs::SetOffset(TPoint aOffset)
{
TPoint moveBy = aOffset - iRect.iTl;
iRect.Move(moveBy);
}
/*
* Standard c+ constructor
* @param aRect The size of the screen
*/
TSkiScreenAttribs::TSkiScreenAttribs(const TRect& aRect) :
iRect(aRect)
{
}
/*
* Standard c+ constructor
*/
TSkiScreenAttribs::TSkiScreenAttribs()
{
}
//
//CSkiSprite::
//
/**
* Symbian OS 2 phase constructor.
* @param aBitmap The bitmap
* @param aMask
* @param aType an integer to identify the sprite
*/
CSkiSprite* CSkiSprite::NewL(CFbsBitmap* aBitmap, CFbsBitmap* aMask, TInt aType)
{
CSkiSprite* self = NewLC(aBitmap, aMask, aType);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor. The constructed object is left on the cleanup stack
* @param aMask
* @param aType an integer to identify the sprite
*/
CSkiSprite* CSkiSprite::NewLC(CFbsBitmap* aBitmap, CFbsBitmap* aMask, TInt aType)
{
CSkiSprite* self = new (ELeave) CSkiSprite(aBitmap, aMask, aType);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* C++ constructor
*/
CSkiSprite::CSkiSprite(CFbsBitmap* aBitmap, CFbsBitmap* aMask, TInt aType) :
iBitmap(aBitmap),
iMask(aMask),
iType(aType)
{
}
/**
* Accessor to sprite type information
* @return an integer equivalent to an enumerated value that identifies the type
*/
TInt CSkiSprite::Type() const
{
return iType;
}
/**
* Destructor
*/
CSkiSprite::~CSkiSprite()
{
delete iBitmap;
delete iMask;
}
/**
* Bitmap accessor
* @return a reference to the bitmap
*/
const CFbsBitmap& CSkiSprite::Bitmap() const
{
return *iBitmap;
}
/**
* Bitmap accessor
* @return a reference to the bitmap
*/
CFbsBitmap& CSkiSprite::Bitmap()
{
return *iBitmap;
}
/**
* Bitmap mask accessor
* @return a reference to the bitmap mask
*/
CFbsBitmap* CSkiSprite::Mask()
{
return iMask;
}
/**
* Bitmap mask accessor
* @return a reference to the bitmap mask
*/
const CFbsBitmap* CSkiSprite::Mask() const
{
return iMask;
}
/**
* Standard Symbian OS 2nd phase construction
*/
void CSkiSprite::ConstructL()
{
User::LeaveIfNull(iBitmap);
}
//
//CGameGallery::
//
/**
* Symbian OS 2 phase constructor.
*/
CGameGallery* CGameGallery::NewL()
{
CGameGallery* self = NewLC();
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor. The constructed object is left on the cleanup stack
*/
CGameGallery* CGameGallery::NewLC()
{
CGameGallery* self = new (ELeave) CGameGallery;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Destructor
*/
CGameGallery::~CGameGallery()
{
iArray->ResetAndDestroy();
delete iArray;
}
/**
* Contructor
*/
CGameGallery::CGameGallery()
{
}
/**
* Standard Symbian OS 2nd phase construction
*/
void CGameGallery::ConstructL()
{
iArray = new (ELeave) CSkiSpriteArray(KSkiArrayGranularity);
}
/**
* Accessor to a sprite of a particular type held in the gallery
* @param aType an integer to identify the sprite type required
* @return The requested sprite
* @exception Can leave with KErrNotFound
*/
const CSkiSprite& CGameGallery::SpriteL(TInt aType) const
{
const TInt count = iArray->Count();
for (TInt ii = 0; ii < count; ii++)
{
CSkiSprite* scenery = iArray->At(ii);
if (scenery->Type() == aType)
{
return *scenery;
}
}
User::Leave(KErrNotFound);
// to keep compiler happy
return *(iArray->At(0));
}
/**
* Accessor to a sprite of a particular type held in the gallery
* @param aType an integer to identify the sprite type required
* @return The requested sprite
* @exception Can leave with KErrNotFound
*/
CSkiSprite& CGameGallery::SpriteL(TInt aType)
{
const TInt count = iArray->Count();
for (TInt ii = 0; ii < count; ii++)
{
CSkiSprite* scenery = iArray->At(ii);
if (scenery->Type() == aType)
{
return *scenery;
}
}
User::Leave(KErrNotFound);
// to keep compiler happy
return *(iArray->At(0));
}
/**
* Constructs a sprite from the parameters and adds it to the gallery
* @param aBitmap The bitmap for the sprite
* @param aMask The mask for the sprite
* @param aTpe The sprite type
*/
void CGameGallery::AddBitmapL(CFbsBitmap* aBitmap, CFbsBitmap* aMask, TInt aType) const
{
const TInt count = iArray->Count();
for (TInt ii = 0; ii < count; ii++)
{
CSkiSprite* scenery = iArray->At(ii);
if (scenery->Type() == aType)
{
User::Leave(KErrAlreadyExists);
}
}
CSkiSprite* newScenery = CSkiSprite::NewLC(aBitmap, aMask, aType);
iArray->AppendL(newScenery);
CleanupStack::Pop(newScenery);
}
//
//CMapGallery::
//
/**
* Symbian OS 2 phase constructor.
*/
CMapGallery* CMapGallery::NewL()
{
CMapGallery* self = NewLC();
CleanupStack::Pop(self);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -