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@21:32429d8e90ff, 2020-05-12 (annotated)
- Committer:
- thestudent
- Date:
- Tue May 12 15:12:59 2020 +0000
- Revision:
- 21:32429d8e90ff
- Parent:
- 15:3f558f8b54ea
- Child:
- 22:f1811602a817
Final version
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 | 21:32429d8e90ff | 10 | /**Function class | 
| thestudent | 21:32429d8e90ff | 11 | * @brief Contains the game engine | 
| thestudent | 21:32429d8e90ff | 12 | * @author Arturs Kozlovskis | 
| thestudent | 21:32429d8e90ff | 13 | * @date April,2020 | 
| thestudent | 21:32429d8e90ff | 14 | */ | 
| thestudent | 21:32429d8e90ff | 15 | |
| thestudent | 21:32429d8e90ff | 16 | //holds parabolic ball values | 
| thestudent | 7:82079de8bcd6 | 17 | struct Ball{ | 
| thestudent | 14:739115711bf8 | 18 | int ball_x_pos[10]; // balls x position | 
| thestudent | 8:09eb8fe2bb20 | 19 | float movement_y_counter[10]; //sets the gravity with which the ball will fall | 
| thestudent | 7:82079de8bcd6 | 20 | 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 | 
| thestudent | 7:82079de8bcd6 | 21 | int ball_y_pos[10];//balls_y_position | 
| thestudent | 7:82079de8bcd6 | 22 | int time_incrementer[10];//increments time value | 
| thestudent | 7:82079de8bcd6 | 23 | int ball_x_incrementer[10];//increments movement_x_pos value | 
| thestudent | 7:82079de8bcd6 | 24 | int delta_r[10]; // defines the ball size | 
| thestudent | 21:32429d8e90ff | 25 | int ball_trajectory_width[10]; | 
| thestudent | 7:82079de8bcd6 | 26 | }; | 
| thestudent | 21:32429d8e90ff | 27 | |
| thestudent | 21:32429d8e90ff | 28 | //holds linear ball vvalues | 
| thestudent | 7:82079de8bcd6 | 29 | struct Ball_linear{ | 
| thestudent | 9:4b11ee1155ad | 30 | int ball_x_pos[10]; // moves the ball across the screen | 
| thestudent | 7:82079de8bcd6 | 31 | int movement_y_counter[10]; //sets the gravity with which the ball will fall | 
| thestudent | 7:82079de8bcd6 | 32 | int ball_y_pos[10];//balls_y_position | 
| thestudent | 7:82079de8bcd6 | 33 | int time_incrementer[10];//increments time value | 
| thestudent | 7:82079de8bcd6 | 34 | int ball_x_incrementer[10];//increments movement_x_pos value | 
| thestudent | 7:82079de8bcd6 | 35 | int delta_r[10]; // defines the ball size | 
| thestudent | 7:82079de8bcd6 | 36 | }; | 
| thestudent | 7:82079de8bcd6 | 37 | |
| thestudent | 9:4b11ee1155ad | 38 | class Functions | 
| thestudent | 6:33bdb54c2c88 | 39 | { | 
| thestudent | 6:33bdb54c2c88 | 40 | public: | 
| thestudent | 21:32429d8e90ff | 41 | /**Constructor*/ | 
| thestudent | 6:33bdb54c2c88 | 42 | Functions(); | 
| thestudent | 21:32429d8e90ff | 43 | |
| thestudent | 21:32429d8e90ff | 44 | /** Draw parabolic ball | 
| thestudent | 21:32429d8e90ff | 45 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 46 | * @param Object class object | 
| thestudent | 21:32429d8e90ff | 47 | * @param chosen ball(int) | 
| thestudent | 21:32429d8e90ff | 48 | */ | 
| thestudent | 12:f7dfd44569b6 | 49 | void ball_position_parabolic( N5110 &lcd, Objects &objects, int c);//governs the balls movement in a parabolic way | 
| thestudent | 21:32429d8e90ff | 50 | |
| thestudent | 21:32429d8e90ff | 51 | /** Draw linear ball | 
| thestudent | 21:32429d8e90ff | 52 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 53 | * @param Object class object | 
| thestudent | 21:32429d8e90ff | 54 | * @param chosen ball(int) | 
| thestudent | 21:32429d8e90ff | 55 | */ | 
| thestudent | 12:f7dfd44569b6 | 56 | void ball_position_linear (N5110 &lcd, Objects &objects, int c);//governs the balls movement in a linear way | 
| thestudent | 21:32429d8e90ff | 57 | |
| thestudent | 21:32429d8e90ff | 58 | /** Check for collisions | 
| thestudent | 21:32429d8e90ff | 59 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 60 | * @param Object class object | 
| thestudent | 21:32429d8e90ff | 61 | */ | 
| thestudent | 9:4b11ee1155ad | 62 | void collision_checker(N5110 &lcd,Objects &objects);//checks if the shot has coma into contact with the ball | 
| thestudent | 21:32429d8e90ff | 63 | |
| thestudent | 21:32429d8e90ff | 64 | /** Find the collided ball(linear) | 
| thestudent | 21:32429d8e90ff | 65 | * @param x value of pixel that cause the collision | 
| thestudent | 21:32429d8e90ff | 66 | * @param y value of pixel that cause the collision | 
| thestudent | 21:32429d8e90ff | 67 | */ | 
| thestudent | 10:f5b920a6a71a | 68 | 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 | 69 | |
| thestudent | 21:32429d8e90ff | 70 | /** Find the collided ball(parabolic) | 
| thestudent | 21:32429d8e90ff | 71 | * @param x value of pixel that cause the collision | 
| thestudent | 21:32429d8e90ff | 72 | * @param y value of pixel that cause the collision | 
| thestudent | 21:32429d8e90ff | 73 | */ | 
| thestudent | 10:f5b920a6a71a | 74 | 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 | 75 | |
| thestudent | 21:32429d8e90ff | 76 | /**Check if cannon has been hit | 
| thestudent | 21:32429d8e90ff | 77 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 78 | * @param Object class object | 
| thestudent | 21:32429d8e90ff | 79 | * @return if collision has happened(bool) | 
| thestudent | 21:32429d8e90ff | 80 | */ | 
| thestudent | 11:4722bf70b2be | 81 | bool cannon_smash(N5110 &lcd,Objects &objects);// checks if the cannon has crashed with anything | 
| thestudent | 21:32429d8e90ff | 82 | |
| thestudent | 21:32429d8e90ff | 83 | /** Generate a random value | 
| thestudent | 21:32429d8e90ff | 84 | * @param Gamepad class object | 
| thestudent | 21:32429d8e90ff | 85 | * @return the random value(int) | 
| thestudent | 21:32429d8e90ff | 86 | */ | 
| thestudent | 11:4722bf70b2be | 87 | int random(Gamepad &pad);//generates a random number | 
| thestudent | 21:32429d8e90ff | 88 | |
| thestudent | 21:32429d8e90ff | 89 | /**Govern the linear ball movement and creation | 
| thestudent | 21:32429d8e90ff | 90 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 91 | * @param Object class object | 
| thestudent | 21:32429d8e90ff | 92 | * @param Gamepad class object | 
| thestudent | 21:32429d8e90ff | 93 | */ | 
| thestudent | 14:739115711bf8 | 94 | void ball_creater_linear(N5110 &lcd, Objects &objects, Gamepad &pad);//controls ball making and their movement equations | 
| thestudent | 21:32429d8e90ff | 95 | |
| thestudent | 21:32429d8e90ff | 96 | /**Govern the parabolic ball movement and creation | 
| thestudent | 21:32429d8e90ff | 97 | * @param N5110 class object | 
| thestudent | 21:32429d8e90ff | 98 | * @param Object class object | 
| thestudent | 21:32429d8e90ff | 99 | * @param Gamepad class object | 
| thestudent | 21:32429d8e90ff | 100 | */ | 
| thestudent | 14:739115711bf8 | 101 | void ball_creater_parabolic(N5110 &lcd, Objects &objects, Gamepad &pad);//controls ball making and their movement | 
| thestudent | 21:32429d8e90ff | 102 | |
| thestudent | 21:32429d8e90ff | 103 | /**Round a value | 
| thestudent | 21:32429d8e90ff | 104 | * @param the number that needs rounding | 
| thestudent | 21:32429d8e90ff | 105 | * @return rounded value | 
| thestudent | 21:32429d8e90ff | 106 | */ | 
| thestudent | 15:3f558f8b54ea | 107 | int round(float number); //rounds a number | 
| thestudent | 21:32429d8e90ff | 108 | |
| thestudent | 21:32429d8e90ff | 109 | /**Get score | 
| thestudent | 21:32429d8e90ff | 110 | * @return the current score | 
| thestudent | 21:32429d8e90ff | 111 | */ | 
| thestudent | 13:1dbef50789ed | 112 | int get_score();//gets the players score | 
| thestudent | 13:1dbef50789ed | 113 | |
| thestudent | 6:33bdb54c2c88 | 114 | private: | 
| thestudent | 21:32429d8e90ff | 115 | //variables | 
| thestudent | 6:33bdb54c2c88 | 116 | int _initial_radiuss;//holds the intial ball radiuss which is 2 | 
| thestudent | 10:f5b920a6a71a | 117 | int _cannon_y_pos; // holds the cannons y position | 
| thestudent | 13:1dbef50789ed | 118 | int _score;//holds the score | 
| thestudent | 21:32429d8e90ff | 119 | int _counter;//checks if the parabolic ball has to go up or down | 
| thestudent | 21:32429d8e90ff | 120 | int _previous; //the previous parabolic x value | 
| thestudent | 21:32429d8e90ff | 121 | int _now;// the current parabolic x value | 
| thestudent | 21:32429d8e90ff | 122 | vector <int> created_balls;//holds linear balls | 
| thestudent | 21:32429d8e90ff | 123 | vector <int> created_ball;//holds the parabolic balls | 
| thestudent | 6:33bdb54c2c88 | 124 | }; | 
| thestudent | 6:33bdb54c2c88 | 125 | #endif |