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

📄 mopoidball.h

📁 mopoid game symbian os application development
💻 H
字号:
/*
========================================================================
 Name        : MopoidBall.h
 Author      : 
 Copyright   : 
 Description : Handles the ball of the Mopoid game.
 License     : 
 
========================================================================
*/
#ifndef __MOPOIDBALL_H__
#define __MOPOIDBALL_H__

#include <e32std.h>
#include <e32math.h>
#include "MopoidPanel.h"
#include "MopoidGrid.h"
#include "MopoidSettings.h"

class TBall {
public:
	TBall();

	/**
	 * Store a pointer to the settings object.
	 * This is requied - without the pointer assigned, you will get
	 * null pointer exceptions (KERN-EXEC 3) as there are no checks
	 * for performance reasons.
	 * This class does not take ownership of this object.
	 */
	void SetSettingsPointer(CMopoidSettings* aSettings);
	
    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 CheckBrickCollisionL(CMopoidGrid* 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;
    
private:
	/**
	 * Pointer to the settings object, required for
	 * various calculations.
	 * Will need the size of some objects from the settings object.
	 */
	CMopoidSettings* iSettings;
};



#endif

⌨️ 快捷键说明

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