📄 mopoidball.h
字号:
/*
* ============================================================================
* Name : TBall from MopoidBall.h
* Part of : Mopoid
* Created : 16.01.2004 by Andreas Jakl / Mopius - http://www.mopius.com/
* Description:
* Handles the ball of the Mopoid game.
* Version : 1.02
* Copyright:
* 'Mopoid' is free software; you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* 'Mopoid' is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 'Mopoid'; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* ============================================================================
*/
#ifndef __MOPOIDPANEL_H__
#define __MOPOIDPANEL_H__
#include <e32std.h>
#include <e32math.h>
#include "MopoidPanel.h"
#include "MopoidGrid.h"
class TBall {
public:
TBall();
enum TCollisionOffset {
ELeft = -1,
ECenter,
ERight
};
/**
* Calculate the next position of the ball using its current speed, taking
* the time difference to the last frame (parameter) into account. The new
* location information will be stored in iPosNew (TPoint), iXnew and iYnew (TReal).
* @param aStep time difference to the last frame
* @return ETrue if the ball hit a wall and was reflected, otherwise EFalse.
*/
TBool Move(TReal aStep);
/**
* Copies the next position that was calculated by the Move-function to the current
* coordinates.
*/
void ConvertToPos();
/**
* Checks if the ball is currently colliding with the panel. If it is, the ball will
* be reflected according to where it hit the panel.
* @param aPanel contains information about the panel.
* @param aStep time difference to the last frame
* @return ETrue if the ball hit the panel and was reflected, otherwise EFalse.
*/
TBool CheckPanelCollision(const TPanel& aPanel, TReal aStep);
/**
* Checks if the ball hits a brick of the grid. If yes, the according event will
* be sent to the grid so that it will handle the brick hit. The ball will be
* reflected.
* @param aGrid contains information about the grid and its bricks.
* @param aStep time difference to the last frame
* @return information about the brick that was hit. If no brick was hit, it will
* return an empty brick with the type EBrickInactive.
*/
TBrick::TBrickType CheckBrickCollision(TMopoidGrid& aGrid, TReal aStep, TCollisionOffset aSide);
/**
* Checks if our ball has fallen below the lower border of the panel.
* @param aPanel the panel information object.
* @return ETrue if the ball is dead (below panel), EFalse otherwise.
*/
TBool CheckDeath(const TPanel& aPanel);
private:
/**
* Reflect the ball at the x- and y-axis.
*/
void BounceXY();
/**
* Reflect the ball at the x-axis.
*/
void BounceX();
/**
* Reflect the ball at the y-axis.
*/
void BounceY();
/**
* Make ball faster in x-direction.
*/
void SpeedUpX();
/**
* Make ball faster in y-direction.
*/
void SpeedUpY();
public:
/**
* Current screen position of the ball.
*/
TPoint iPos;
/**
* Next position of the ball, calculated by Move().
*/
TPoint iPosNew;
/**
* Current exact position of the ball (x-axis).
*/
TReal iX;
/**
* Current exact position of the ball (y-axis).
*/
TReal iY;
/**
* Next exact position of the ball (x-axis).
*/
TReal iXnew;
/**
* Next exact position of the ball (y-axis).
*/
TReal iYnew;
/**
* Speed in x-direction.
*/
TReal iVx;
/**
* Speed in y-direction.
*/
TReal iVy;
/**
* Size of the ball bitmap.
*/
TSize iSize;
/**
* Size of the ball bitmap divided by 2 (to speed up calculations which need this).
*/
TSize iSizeHalf;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -