⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spritebase.h

📁 RGA: Biowaste Game Example This C++ application demonstrates how to create a 2D mobile game for S60
💻 H
字号:
/*
* ==============================================================================
*  Name        : SpriteBase.h
*  Part of     : RGA Game Example
*  Interface   :
*  Description : base interface for sprites
*  Version     : 1.0
*
*  Copyright (c) 2007-2008 Nokia Corporation.
*  This material, including documentation and any related
*  computer programs, is protected by copyright controlled by
*  Nokia Corporation.
* ==============================================================================
*/

#ifndef __SPRITEBASE_H__
#define __SPRITEBASE_H__

#include <e32base.h>
#include <e32math.h>

// RGA includes
#include <runtime.h>
#include <graphicscontext.h>
#include <ngibitmap.h>
#include <errorcodes.h>
using namespace ngi;

#include "Vector2.h"

// forward declaration
class CApplicationBase;


class CSpriteBase : public CBase
	{
	public:
		CSpriteBase(CApplicationBase& aApp);
		virtual ~CSpriteBase();
		
		/**
		 * SetPosition
		 * @param aPos new sprite position
		 */
		void SetPosition(const TVector2& aPos);
		
		/**
		 * SetDirection
		 * sets sprite movement vector, length of the vector
		 * is sprites movement in pixels per second
		 * @param aDir new direction vector
		 */
		void SetDirection(const TVector2& aDir);

		/**
		 * SetAcceleration
		 * sets sprite acceleration vector
		 * @param aAcc new direction vector
		 */
		void SetAcceleration(const TVector2& aAcc);
		
		/**
		 * Position
		 * @return reference to sprite position
		 */
		inline TVector2& Position() { return iPos; }

		/**
		 * Direction
		 * @return reference to sprite direction
		 */
		inline TVector2& Direction() { return iDir; }

		/**
		 * Acceleration
		 * @return reference to sprite acceleration
		 */
		inline TVector2& Acceleration() { return iAcc; }
		
		/**
		 * Speed
		 * @return sprite movement speed in pixels per second
		 */
		inline TReal64 Speed() const { return iDir.Length(); }
		
		/**
		 * SetSpeed
		 * sets the sprite movement speed in pixels per second
		 * @param aSpeed sprite speed
		 */
		inline void SetSpeed(const TReal64 aSpeed) { iDir.SetLength(aSpeed); }
		
		/**
		 * Update
		 * update the sprite position by adding its
		 * direction into the position
		 * @param aFrametime frame time multiplier
		 */
		virtual void Update(const TReal64 aFrametime);
		
		/**
		 * Draw
		 * pure virtual draw function
		 * @param aContext context to draw sprite into
		 * @param aCamera camera coordinate to subtract from sprite coordinates
		 */
		virtual void Draw(IGraphicsContext& aContext, const TVector2& aCamera) = 0;
		
		/**
		 * Collision
		 * check collision of two sprites by calculating distance to
		 * sprites centers (bounding sphere check)
		 * @param aSprite sprite to check to
		 * @return ETrue if sprites intersect
		 */
		virtual TBool Collision(CSpriteBase& aSprite) const;
		
		/**
		 * SetSize
		 * @param aSize pixel size of the sprite
		 */
		void SetSize(const TSize& aSize);
		
		/**
		 * Size
		 * returns size of the sprite in pixels
		 * each derived object is responsible of setting
		 * the size correctly
		 * @return size of the sprite
		 */
		virtual TSize Size() const;
		
		/**
		 * IsVisible
		 * derived classes should override this. Default
		 * implementation returns ETrue
		 * @param aCamera camera offset
		 * @return ETrue if sprite is visible on screen
		 */
		virtual TBool IsVisible(const TVector2& aCamera) const;
		
		/**
		 * App
		 * @return reference to application that created this sprite
		 */
		CApplicationBase& App();
		
		/**
		 * SetId
		 * set sprite identifier
		 * @param aId new identifier number
		 */
		void SetId(TUint32 aId);
		
		/**
		 * Id
		 * @return identifier number of this sprite
		 */
		TUint32 Id() const;
		
		
	protected:	// Data
		CApplicationBase&		iApp;
		
		TUint32					iId;
		
		TSize					iSize;
		
		TVector2				iPos;
		TVector2				iDir;
		TVector2				iAcc;
	};

#endif /* __SPRITEBASE_H__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -