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@24:74a53dd49806, 2020-05-18 (annotated)
- Committer:
- thestudent
- Date:
- Mon May 18 11:27:07 2020 +0000
- Revision:
- 24:74a53dd49806
- Parent:
- 23:cd38e48635e7
- Child:
- 25:b0c1d7955678
Added sound feature. When ball is destroyed produce an sound effect
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| thestudent | 6:33bdb54c2c88 | 1 | #ifndef FUNCTIONS_H | 
| thestudent | 6:33bdb54c2c88 | 2 | #define FUNCTIONS_H | 
| thestudent | 6:33bdb54c2c88 | 3 | |
| thestudent | 6:33bdb54c2c88 | 4 | //includes | 
| thestudent | 6:33bdb54c2c88 | 5 | #include "mbed.h" | 
| thestudent | 6:33bdb54c2c88 | 6 | #include "N5110.h" | 
| thestudent | 6:33bdb54c2c88 | 7 | #include "Gamepad.h" | 
| thestudent | 6:33bdb54c2c88 | 8 | #include "Objects.h" | 
| thestudent | 6:33bdb54c2c88 | 9 | |
| thestudent | 23:cd38e48635e7 | 10 | //holds parabolic ball values | 
| thestudent | 23:cd38e48635e7 | 11 | /** Struct for parabolic ball's varibales*/ | 
| thestudent | 23:cd38e48635e7 | 12 | struct Ball{ | 
| thestudent | 23:cd38e48635e7 | 13 | int ball_x_pos[10]; /**< Holds parabolic ball's x position(int)*/ | 
| thestudent | 23:cd38e48635e7 | 14 | float movement_y_counter[10]; /**< Sets the gravity with which the ball will fall(float)*/ | 
| thestudent | 23:cd38e48635e7 | 15 | int time[10];/**<Holds the time which is used in the balls movement(int)*/ | 
| thestudent | 23:cd38e48635e7 | 16 | int ball_y_pos[10];/**<Holds parabolic ball's y position(int)*/ | 
| thestudent | 23:cd38e48635e7 | 17 | int time_incrementer[10];/**<Increments time value(int)*/ | 
| thestudent | 23:cd38e48635e7 | 18 | int ball_x_incrementer[10];/**Increments ball's x position(int)*/ | 
| thestudent | 23:cd38e48635e7 | 19 | int delta_r[10]; /**< Holds ball's radiuss value(int)*/ | 
| thestudent | 23:cd38e48635e7 | 20 | int ball_trajectory_width[10];/**<Holds the value of ball's trajectories width(int)*/ | 
| thestudent | 23:cd38e48635e7 | 21 | }; | 
| thestudent | 23:cd38e48635e7 | 22 | |
| thestudent | 23:cd38e48635e7 | 23 | //holds linear ball vvalues | 
| thestudent | 23:cd38e48635e7 | 24 | /**Struct for linear ball's varables*/ | 
| thestudent | 23:cd38e48635e7 | 25 | struct Ball_linear{ | 
| thestudent | 23:cd38e48635e7 | 26 | int ball_x_pos[10]; /**< Holds ball's x position(int)*/ | 
| thestudent | 23:cd38e48635e7 | 27 | int movement_y_counter[10]; /**Sets the gravity with which the ball will fall(int)*/ | 
| thestudent | 23:cd38e48635e7 | 28 | int ball_y_pos[10];/**<Ball's y position(int)*/ | 
| thestudent | 23:cd38e48635e7 | 29 | int time_incrementer[10];/**<Increments the y(initaly time) value(int)*/ | 
| thestudent | 23:cd38e48635e7 | 30 | int ball_x_incrementer[10];/**<Increments ball's x value(int)*/ | 
| thestudent | 23:cd38e48635e7 | 31 | int delta_r[10];/**< Holds ball's radiuss value(int)*/ | 
| thestudent | 23:cd38e48635e7 | 32 | }; | 
| thestudent | 23:cd38e48635e7 | 33 | |
| thestudent | 21:32429d8e90ff | 34 | /**Function class | 
| thestudent | 21:32429d8e90ff | 35 | * @brief Contains the game engine | 
| thestudent | 21:32429d8e90ff | 36 | * @author Arturs Kozlovskis | 
| thestudent | 21:32429d8e90ff | 37 | * @date April,2020 | 
| thestudent | 21:32429d8e90ff | 38 | */ | 
| thestudent | 9:4b11ee1155ad | 39 | class Functions | 
| thestudent | 6:33bdb54c2c88 | 40 | { | 
| thestudent | 6:33bdb54c2c88 | 41 | public: | 
| thestudent | 21:32429d8e90ff | 42 | /**Constructor*/ | 
| thestudent | 6:33bdb54c2c88 | 43 | Functions(); | 
| thestudent | 21:32429d8e90ff | 44 | |
| thestudent | 21:32429d8e90ff | 45 | /** Draw parabolic ball | 
| thestudent | 21:32429d8e90ff | 46 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 47 | * @param Object class object | 
| thestudent | 24:74a53dd49806 | 48 | * @param Gamepad class object | 
| thestudent | 21:32429d8e90ff | 49 | * @param chosen ball(int) | 
| thestudent | 21:32429d8e90ff | 50 | */ | 
| thestudent | 24:74a53dd49806 | 51 | void ball_position_parabolic( N5110 &lcd, Objects &objects,Gamepad &pad, int c);//governs the balls movement in a parabolic way | 
| thestudent | 21:32429d8e90ff | 52 | |
| thestudent | 21:32429d8e90ff | 53 | /** Draw linear ball | 
| thestudent | 21:32429d8e90ff | 54 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 55 | * @param Object class object | 
| thestudent | 24:74a53dd49806 | 56 | * @param Gamepad class object | 
| thestudent | 21:32429d8e90ff | 57 | * @param chosen ball(int) | 
| thestudent | 21:32429d8e90ff | 58 | */ | 
| thestudent | 24:74a53dd49806 | 59 | void ball_position_linear (N5110 &lcd, Objects &objects,Gamepad &pad, int c);//governs the balls movement in a linear way | 
| thestudent | 21:32429d8e90ff | 60 | |
| thestudent | 21:32429d8e90ff | 61 | /** Check for collisions | 
| thestudent | 21:32429d8e90ff | 62 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 63 | * @param Object class object | 
| thestudent | 24:74a53dd49806 | 64 | * @param Gamepad class object | 
| thestudent | 21:32429d8e90ff | 65 | */ | 
| thestudent | 24:74a53dd49806 | 66 | void collision_checker(N5110 &lcd,Objects &objects,Gamepad &pad);//checks if the shot has coma into contact with the ball | 
| thestudent | 21:32429d8e90ff | 67 | |
| thestudent | 21:32429d8e90ff | 68 | /** Find the collided ball(linear) | 
| thestudent | 21:32429d8e90ff | 69 | * @param x value of pixel that cause the collision | 
| thestudent | 21:32429d8e90ff | 70 | * @param y value of pixel that cause the collision | 
| thestudent | 21:32429d8e90ff | 71 | */ | 
| thestudent | 10:f5b920a6a71a | 72 | void ball1_finder(int x, int y);//checks which ball has been hit by a shot and then decreses it size(linear) | 
| thestudent | 21:32429d8e90ff | 73 | |
| thestudent | 21:32429d8e90ff | 74 | /** Find the collided ball(parabolic) | 
| thestudent | 21:32429d8e90ff | 75 | * @param x value of pixel that cause the collision | 
| thestudent | 21:32429d8e90ff | 76 | * @param y value of pixel that cause the collision | 
| thestudent | 21:32429d8e90ff | 77 | */ | 
| thestudent | 10:f5b920a6a71a | 78 | void ball_finder(int x, int y);//checks which ball has been hit by a shot and then decreses it size(parabolic) | 
| thestudent | 21:32429d8e90ff | 79 | |
| thestudent | 21:32429d8e90ff | 80 | /**Check if cannon has been hit | 
| thestudent | 21:32429d8e90ff | 81 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 82 | * @param Object class object | 
| thestudent | 21:32429d8e90ff | 83 | * @return if collision has happened(bool) | 
| thestudent | 21:32429d8e90ff | 84 | */ | 
| thestudent | 11:4722bf70b2be | 85 | bool cannon_smash(N5110 &lcd,Objects &objects);// checks if the cannon has crashed with anything | 
| thestudent | 21:32429d8e90ff | 86 | |
| thestudent | 21:32429d8e90ff | 87 | /** Generate a random value | 
| thestudent | 21:32429d8e90ff | 88 | * @param Gamepad class object | 
| thestudent | 21:32429d8e90ff | 89 | * @return the random value(int) | 
| thestudent | 21:32429d8e90ff | 90 | */ | 
| thestudent | 11:4722bf70b2be | 91 | int random(Gamepad &pad);//generates a random number | 
| thestudent | 21:32429d8e90ff | 92 | |
| thestudent | 21:32429d8e90ff | 93 | /**Govern the linear ball movement and creation | 
| thestudent | 21:32429d8e90ff | 94 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 95 | * @param Object class object | 
| thestudent | 21:32429d8e90ff | 96 | * @param Gamepad class object | 
| thestudent | 21:32429d8e90ff | 97 | */ | 
| thestudent | 14:739115711bf8 | 98 | void ball_creater_linear(N5110 &lcd, Objects &objects, Gamepad &pad);//controls ball making and their movement equations | 
| thestudent | 21:32429d8e90ff | 99 | |
| thestudent | 21:32429d8e90ff | 100 | /**Govern the parabolic ball movement and creation | 
| thestudent | 21:32429d8e90ff | 101 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 102 | * @param Object class object | 
| thestudent | 21:32429d8e90ff | 103 | * @param Gamepad class object | 
| thestudent | 21:32429d8e90ff | 104 | */ | 
| thestudent | 14:739115711bf8 | 105 | void ball_creater_parabolic(N5110 &lcd, Objects &objects, Gamepad &pad);//controls ball making and their movement | 
| thestudent | 21:32429d8e90ff | 106 | |
| thestudent | 21:32429d8e90ff | 107 | /**Round a value | 
| thestudent | 21:32429d8e90ff | 108 | * @param the number that needs rounding | 
| thestudent | 21:32429d8e90ff | 109 | * @return rounded value | 
| thestudent | 21:32429d8e90ff | 110 | */ | 
| thestudent | 15:3f558f8b54ea | 111 | int round(float number); //rounds a number | 
| thestudent | 21:32429d8e90ff | 112 | |
| thestudent | 21:32429d8e90ff | 113 | /**Get score | 
| thestudent | 21:32429d8e90ff | 114 | * @return the current score | 
| thestudent | 21:32429d8e90ff | 115 | */ | 
| thestudent | 13:1dbef50789ed | 116 | int get_score();//gets the players score | 
| thestudent | 13:1dbef50789ed | 117 | |
| thestudent | 6:33bdb54c2c88 | 118 | private: | 
| thestudent | 21:32429d8e90ff | 119 | //variables | 
| thestudent | 6:33bdb54c2c88 | 120 | int _initial_radiuss;//holds the intial ball radiuss which is 2 | 
| thestudent | 10:f5b920a6a71a | 121 | int _cannon_y_pos; // holds the cannons y position | 
| thestudent | 13:1dbef50789ed | 122 | int _score;//holds the score | 
| thestudent | 21:32429d8e90ff | 123 | int _counter;//checks if the parabolic ball has to go up or down | 
| thestudent | 21:32429d8e90ff | 124 | int _previous; //the previous parabolic x value | 
| thestudent | 21:32429d8e90ff | 125 | int _now;// the current parabolic x value | 
| thestudent | 21:32429d8e90ff | 126 | vector <int> created_balls;//holds linear balls | 
| thestudent | 21:32429d8e90ff | 127 | vector <int> created_ball;//holds the parabolic balls | 
| thestudent | 22:f1811602a817 | 128 | int _note_count; //holds the number of how many notes the note array has | 
| thestudent | 24:74a53dd49806 | 129 | float _bpm; //beats per minute | 
| thestudent | 6:33bdb54c2c88 | 130 | }; | 
| thestudent | 6:33bdb54c2c88 | 131 | #endif |