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@23:cd38e48635e7, 2020-05-18 (annotated)
- Committer:
- thestudent
- Date:
- Mon May 18 10:54:22 2020 +0000
- Revision:
- 23:cd38e48635e7
- Parent:
- 22:f1811602a817
- Child:
- 24:74a53dd49806
Added some sound features;
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 | 21:32429d8e90ff | 48 | * @param chosen ball(int) |
| thestudent | 21:32429d8e90ff | 49 | */ |
| thestudent | 12:f7dfd44569b6 | 50 | void ball_position_parabolic( N5110 &lcd, Objects &objects, int c);//governs the balls movement in a parabolic way |
| thestudent | 21:32429d8e90ff | 51 | |
| thestudent | 21:32429d8e90ff | 52 | /** Draw linear ball |
| thestudent | 21:32429d8e90ff | 53 | * @param N5110 class object |
| thestudent | 21:32429d8e90ff | 54 | * @param Object class object |
| thestudent | 21:32429d8e90ff | 55 | * @param chosen ball(int) |
| thestudent | 21:32429d8e90ff | 56 | */ |
| thestudent | 12:f7dfd44569b6 | 57 | void ball_position_linear (N5110 &lcd, Objects &objects, int c);//governs the balls movement in a linear way |
| thestudent | 21:32429d8e90ff | 58 | |
| thestudent | 21:32429d8e90ff | 59 | /** Check for collisions |
| thestudent | 21:32429d8e90ff | 60 | * @param N5110 class object |
| thestudent | 21:32429d8e90ff | 61 | * @param Object class object |
| thestudent | 21:32429d8e90ff | 62 | */ |
| thestudent | 9:4b11ee1155ad | 63 | void collision_checker(N5110 &lcd,Objects &objects);//checks if the shot has coma into contact with the ball |
| thestudent | 21:32429d8e90ff | 64 | |
| thestudent | 21:32429d8e90ff | 65 | /** Find the collided ball(linear) |
| thestudent | 21:32429d8e90ff | 66 | * @param x value of pixel that cause the collision |
| thestudent | 21:32429d8e90ff | 67 | * @param y value of pixel that cause the collision |
| thestudent | 21:32429d8e90ff | 68 | */ |
| thestudent | 10:f5b920a6a71a | 69 | 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 | 70 | |
| thestudent | 21:32429d8e90ff | 71 | /** Find the collided ball(parabolic) |
| thestudent | 21:32429d8e90ff | 72 | * @param x value of pixel that cause the collision |
| thestudent | 21:32429d8e90ff | 73 | * @param y value of pixel that cause the collision |
| thestudent | 21:32429d8e90ff | 74 | */ |
| thestudent | 10:f5b920a6a71a | 75 | 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 | 76 | |
| thestudent | 21:32429d8e90ff | 77 | /**Check if cannon has been hit |
| thestudent | 21:32429d8e90ff | 78 | * @param N5110 class object |
| thestudent | 21:32429d8e90ff | 79 | * @param Object class object |
| thestudent | 21:32429d8e90ff | 80 | * @return if collision has happened(bool) |
| thestudent | 21:32429d8e90ff | 81 | */ |
| thestudent | 11:4722bf70b2be | 82 | bool cannon_smash(N5110 &lcd,Objects &objects);// checks if the cannon has crashed with anything |
| thestudent | 21:32429d8e90ff | 83 | |
| thestudent | 21:32429d8e90ff | 84 | /** Generate a random value |
| thestudent | 21:32429d8e90ff | 85 | * @param Gamepad class object |
| thestudent | 21:32429d8e90ff | 86 | * @return the random value(int) |
| thestudent | 21:32429d8e90ff | 87 | */ |
| thestudent | 11:4722bf70b2be | 88 | int random(Gamepad &pad);//generates a random number |
| thestudent | 21:32429d8e90ff | 89 | |
| thestudent | 21:32429d8e90ff | 90 | /**Govern the linear ball movement and creation |
| thestudent | 21:32429d8e90ff | 91 | * @param N5110 class object |
| thestudent | 21:32429d8e90ff | 92 | * @param Object class object |
| thestudent | 21:32429d8e90ff | 93 | * @param Gamepad class object |
| thestudent | 21:32429d8e90ff | 94 | */ |
| thestudent | 14:739115711bf8 | 95 | void ball_creater_linear(N5110 &lcd, Objects &objects, Gamepad &pad);//controls ball making and their movement equations |
| thestudent | 21:32429d8e90ff | 96 | |
| thestudent | 21:32429d8e90ff | 97 | /**Govern the parabolic ball movement and creation |
| thestudent | 21:32429d8e90ff | 98 | * @param N5110 class object |
| thestudent | 21:32429d8e90ff | 99 | * @param Object class object |
| thestudent | 21:32429d8e90ff | 100 | * @param Gamepad class object |
| thestudent | 21:32429d8e90ff | 101 | */ |
| thestudent | 14:739115711bf8 | 102 | void ball_creater_parabolic(N5110 &lcd, Objects &objects, Gamepad &pad);//controls ball making and their movement |
| thestudent | 21:32429d8e90ff | 103 | |
| thestudent | 21:32429d8e90ff | 104 | /**Round a value |
| thestudent | 21:32429d8e90ff | 105 | * @param the number that needs rounding |
| thestudent | 21:32429d8e90ff | 106 | * @return rounded value |
| thestudent | 21:32429d8e90ff | 107 | */ |
| thestudent | 15:3f558f8b54ea | 108 | int round(float number); //rounds a number |
| thestudent | 21:32429d8e90ff | 109 | |
| thestudent | 21:32429d8e90ff | 110 | /**Get score |
| thestudent | 21:32429d8e90ff | 111 | * @return the current score |
| thestudent | 21:32429d8e90ff | 112 | */ |
| thestudent | 13:1dbef50789ed | 113 | int get_score();//gets the players score |
| thestudent | 13:1dbef50789ed | 114 | |
| thestudent | 6:33bdb54c2c88 | 115 | private: |
| thestudent | 21:32429d8e90ff | 116 | //variables |
| thestudent | 6:33bdb54c2c88 | 117 | int _initial_radiuss;//holds the intial ball radiuss which is 2 |
| thestudent | 10:f5b920a6a71a | 118 | int _cannon_y_pos; // holds the cannons y position |
| thestudent | 13:1dbef50789ed | 119 | int _score;//holds the score |
| thestudent | 21:32429d8e90ff | 120 | int _counter;//checks if the parabolic ball has to go up or down |
| thestudent | 21:32429d8e90ff | 121 | int _previous; //the previous parabolic x value |
| thestudent | 21:32429d8e90ff | 122 | int _now;// the current parabolic x value |
| thestudent | 21:32429d8e90ff | 123 | vector <int> created_balls;//holds linear balls |
| thestudent | 21:32429d8e90ff | 124 | vector <int> created_ball;//holds the parabolic balls |
| thestudent | 22:f1811602a817 | 125 | int _note_count; //holds the number of how many notes the note array has |
| thestudent | 6:33bdb54c2c88 | 126 | }; |
| thestudent | 6:33bdb54c2c88 | 127 | #endif |