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

📄 sprite.cpp

📁 Symbian -画图程序 graphics-vc.rar
💻 CPP
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */


// INCLUDE FILES
#include "Sprite.h"

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CSprite::CSprite()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CSprite::CSprite( TInt aXVelocity,TInt aYVelocity,
const TPoint& aInitialPosition )
:   iPosition( aInitialPosition ),
    iXVelocity( aXVelocity ),
    iYVelocity( aYVelocity )
    {
    // No implementation required
    }

// -----------------------------------------------------------------------------
// CSprite::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CSprite* CSprite::NewL( TInt aXVelocity,TInt aYVelocity,
                                            const TPoint& aInitialPosition )
    {
    CSprite* self = NewLC( aXVelocity,aYVelocity,aInitialPosition );
    CleanupStack::Pop( self );
    return self;
    }

// -----------------------------------------------------------------------------
// CSprite::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CSprite* CSprite::NewLC( TInt aXVelocity,TInt aYVelocity,
                                            const TPoint& aInitialPosition )
    {
    CSprite* self = new ( ELeave ) CSprite
                                    ( aXVelocity,aYVelocity,aInitialPosition );
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }

// -----------------------------------------------------------------------------
// CSprite::~CFocusEventDocument()
// Destructor.
// -----------------------------------------------------------------------------
//
CSprite::~CSprite()
    {
    // No implementation required
    }

// -----------------------------------------------------------------------------
// CSprite::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CSprite::ConstructL()
    {
    // No implementation required
    }

// -----------------------------------------------------------------------------
// CSprite::Position()
// Return Position.
// -----------------------------------------------------------------------------
//
TPoint CSprite::Position() const
    {
    return iPosition;
    }

// -----------------------------------------------------------------------------
// CSprite::Move()
// Move Sprite.
// -----------------------------------------------------------------------------
//
void CSprite::Move( const TSize& aSize, const TRect& aBounds )
    {
    TBool okToMove = ETrue;

    // Calculate the new sprite position
    TPoint newPostion = iPosition + TPoint( iXVelocity,iYVelocity );

    // Check that the new sprite X position is not out of bounds
    TInt width = aSize.iWidth;
    TInt leftX = newPostion.iX;
    TInt rightX = newPostion.iX + width;
    if ( ( rightX > aBounds.iBr.iX ) || ( leftX < aBounds.iTl.iX ) )
        {
        // If it is, "bounce" the sprite off the edge of the boundary
        iXVelocity = -iXVelocity;
        // and don't let it move this tick
        okToMove = EFalse;
        }

    // Check that the new sprite Y position is not out of bounds
    TInt height = aSize.iHeight;
    TInt topY = newPostion.iY;
    TInt bottomY = newPostion.iY + height;
    if ( ( bottomY > aBounds.iBr.iY ) || ( topY < aBounds.iTl.iY ) )
        {
        // If it is, "bounce" the sprite off the edge of the boundary
        iYVelocity = -iYVelocity;
        // and don't let it move this tick
        okToMove = EFalse;
        }

    // If the sprite can move this tick
    if ( okToMove )
        {
        // Move it
        iPosition = newPostion;
        }
    }

// End of File

⌨️ 快捷键说明

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