Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
My_game_clases/Functions.h
- Committer:
- thestudent
- Date:
- 2020-05-15
- Revision:
- 22:f1811602a817
- Parent:
- 21:32429d8e90ff
- Child:
- 23:cd38e48635e7
File content as of revision 22:f1811602a817:
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
//includes
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Objects.h"
/**Function class
* @brief Contains the game engine
* @author Arturs Kozlovskis
* @date April,2020
*/
//holds parabolic ball values
struct Ball{
int ball_x_pos[10]; // balls x position
float movement_y_counter[10]; //sets the gravity with which the ball will fall
int time[10];//the time as in the y postion of the ball which will governed by equation y = _y_initial + _movement_y_counter * _time^2
int ball_y_pos[10];//balls_y_position
int time_incrementer[10];//increments time value
int ball_x_incrementer[10];//increments movement_x_pos value
int delta_r[10]; // defines the ball size
int ball_trajectory_width[10];
};
//holds linear ball vvalues
struct Ball_linear{
int ball_x_pos[10]; // moves the ball across the screen
int movement_y_counter[10]; //sets the gravity with which the ball will fall
int ball_y_pos[10];//balls_y_position
int time_incrementer[10];//increments time value
int ball_x_incrementer[10];//increments movement_x_pos value
int delta_r[10]; // defines the ball size
};
class Functions
{
public:
/**Constructor*/
Functions();
/** Draw parabolic ball
* @param N5110 class object
* @param Object class object
* @param chosen ball(int)
*/
void ball_position_parabolic( N5110 &lcd, Objects &objects, int c);//governs the balls movement in a parabolic way
/** Draw linear ball
* @param N5110 class object
* @param Object class object
* @param chosen ball(int)
*/
void ball_position_linear (N5110 &lcd, Objects &objects, int c);//governs the balls movement in a linear way
/** Check for collisions
* @param N5110 class object
* @param Object class object
*/
void collision_checker(N5110 &lcd,Objects &objects);//checks if the shot has coma into contact with the ball
/** Find the collided ball(linear)
* @param x value of pixel that cause the collision
* @param y value of pixel that cause 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 cause the collision
* @param y value of pixel that cause 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 Object class object
* @return if collision has happened(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 the random value(int)
*/
int random(Gamepad &pad);//generates a random number
/**Govern the linear ball movement and creation
* @param N5110 class object
* @param Object 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 Object 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 the number that needs rounding
* @return rounded value
*/
int round(float number); //rounds a number
/**Get score
* @return the 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
};
#endif