Arturs Kozlovskis / Mbed 2 deprecated ELEC2645_Project_el18ak

Dependencies:   mbed

My_game_clases/Functions.h

Committer:
thestudent
Date:
2020-05-19
Revision:
25:b0c1d7955678
Parent:
24:74a53dd49806

File content as of revision 25:b0c1d7955678:

#ifndef FUNCTIONS_H
#define FUNCTIONS_H

//includes
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Objects.h"

//holds parabolic ball values
/** Struct for parabolic ball's varibales*/
struct Ball{
    int ball_x_pos[10]; /**< Holds parabolic ball's x position(int)*/ 
    float movement_y_counter[10]; /**< Sets the gravity with which the ball will fall(float)*/
    int time[10];/**<Holds the time which is used in the balls movement(int)*/
    int ball_y_pos[10];/**<Holds parabolic ball's y position(int)*/
    int time_incrementer[10];/**<Increments time value(int)*/
    int ball_x_incrementer[10];/**Increments ball's x position(int)*/
    int delta_r[10]; /**< Holds ball's radiuss value(int)*/    
    int ball_trajectory_width[10];/**<Holds the value of ball's trajectories width(int)*/ 
};

//holds linear ball vvalues
/**Struct for linear ball's varables*/
struct Ball_linear{
    int ball_x_pos[10]; /**< Holds ball's x position(int)*/
    int movement_y_counter[10]; /**Sets the gravity with which the ball will fall(int)*/
    int ball_y_pos[10];/**<Ball's y position(int)*/
    int time_incrementer[10];/**<Increments the y(initaly time) value(int)*/
    int ball_x_incrementer[10];/**<Increments ball's x value(int)*/
    int delta_r[10];/**< Holds ball's radiuss value(int)*/    
};

/**Functions class
* @brief Contains the game engine
* @author Arturs Kozlovskis
* @date April,2020
*/
class Functions 
{
public:
    /**Constructor*/
    Functions();
    
    /** Draw parabolic ball
    * @param N5110 class object
    * @param Objects class object
    * @param Gamepad class object
    * @param c tell the function which ball to chose from(int)
    */
    void ball_position_parabolic( N5110 &lcd, Objects &objects,Gamepad &pad, int c);//governs the balls movement in a parabolic way
   
     /** Draw linear ball
    * @param N5110 class object
    * @param Objects class object
    * @param Gamepad class object
    * @param c tell the function which ball to chose from(int)
    */
    void ball_position_linear (N5110 &lcd, Objects &objects,Gamepad &pad, int c);//governs the balls movement in a linear way
    
    /** Check for collisions
    * @param N5110 class object
    * @param Objects class object
    * @param Gamepad class object
    */
    void collision_checker(N5110 &lcd,Objects &objects,Gamepad &pad);//checks if the shot has coma into contact with the ball
    
    /** Find the collided ball(linear)
    * @param x value of pixel that caused the collision
    * @param y value of pixel that caused the collision
    */
    void ball1_finder(int x, int y);//checks which ball has been hit by a shot and then decreses it size(linear)
    
    /** Find the collided ball(parabolic)
    * @param x value of pixel that caused the collision
    * @param y value of pixel that caused the collision
    */
    void ball_finder(int x, int y);//checks which ball has been hit by a shot and then decreses it size(parabolic)
    
    /**Check if cannon has been hit
    * @param N5110 class object
    * @param Objects class object
    * @return bool if collision has happened or not(bool)
    */
    bool cannon_smash(N5110 &lcd,Objects &objects);// checks if the cannon has crashed with anything
    
    /** Generate a random value
    * @param Gamepad class object
    * @return a random value in range of 0 to 100(int)
    */
    int random(Gamepad &pad);//generates a random number
    
    /**Govern the linear ball movement and creation
    * @param N5110 class object
    * @param Objects class object
    * @param Gamepad class object
    */
    void ball_creater_linear(N5110 &lcd, Objects &objects, Gamepad &pad);//controls ball making and their movement equations
    
     /**Govern the parabolic ball movement and creation
    * @param N5110 class object
    * @param Objects class object
    * @param Gamepad class object
    */
    void ball_creater_parabolic(N5110 &lcd, Objects &objects, Gamepad &pad);//controls ball making and their movement
    
    /**Round a value 
    * @param Number  value that needs rounding
    * @return a rounded value of passed value
    */
    int round(float number); //rounds a number
    
    /**Get score
    * @return the players current score
    */
    int get_score();//gets the players score
    
private:
    //variables
    int _initial_radiuss;//holds the intial ball radiuss which is 2
    int _cannon_y_pos; // holds the cannons y position
    int _score;//holds the score
    int _counter;//checks if the parabolic ball has to go up or down
    int _previous; //the previous parabolic x value
    int _now;// the current parabolic x value
    vector <int> created_balls;//holds linear balls
    vector <int> created_ball;//holds the parabolic balls
    int _note_count; //holds the number of how many notes the note array has
    float _bpm; //beats per minute
};
#endif