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.
Dependencies: mbed
shot/shot.h@21:e3866e4fe5fb, 2020-05-22 (annotated)
- Committer:
- el19zf
- Date:
- Fri May 22 04:49:26 2020 +0000
- Revision:
- 21:e3866e4fe5fb
- Parent:
- 19:5083339b55e8
Final Submission. I have read and agreed with Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el19zf | 4:b12a49f0b730 | 1 | #ifndef SHOT_H |
el19zf | 4:b12a49f0b730 | 2 | #define SHOT_H |
el19zf | 4:b12a49f0b730 | 3 | |
el19zf | 4:b12a49f0b730 | 4 | #include "mbed.h" |
el19zf | 4:b12a49f0b730 | 5 | #include "Gamepad.h" |
el19zf | 4:b12a49f0b730 | 6 | #include "N5110.h" |
el19zf | 4:b12a49f0b730 | 7 | #include <vector> |
el19zf | 6:dce38fe4e092 | 8 | #include <time.h> |
el19zf | 6:dce38fe4e092 | 9 | #include <stdlib.h> |
el19zf | 4:b12a49f0b730 | 10 | |
el19zf | 13:eb60628db8bf | 11 | /**struct of shot position type and direction*/ |
el19zf | 7:c49f3d3b672f | 12 | struct shot_posandtype { |
el19zf | 5:6774b7272e85 | 13 | int x; |
el19zf | 5:6774b7272e85 | 14 | int y; |
el19zf | 5:6774b7272e85 | 15 | int type; |
el19zf | 5:6774b7272e85 | 16 | int dir; |
el19zf | 5:6774b7272e85 | 17 | }; |
el19zf | 4:b12a49f0b730 | 18 | |
el19zf | 21:e3866e4fe5fb | 19 | /** shot class |
el19zf | 21:e3866e4fe5fb | 20 | *@brief set several kinds of shot and come from all around |
el19zf | 21:e3866e4fe5fb | 21 | *@author Zeyu Feng |
el19zf | 21:e3866e4fe5fb | 22 | *@13 April 2020 |
el19zf | 21:e3866e4fe5fb | 23 | */ |
el19zf | 7:c49f3d3b672f | 24 | class shot |
el19zf | 7:c49f3d3b672f | 25 | { |
el19zf | 7:c49f3d3b672f | 26 | |
el19zf | 7:c49f3d3b672f | 27 | public: |
el19zf | 13:eb60628db8bf | 28 | |
el19zf | 13:eb60628db8bf | 29 | /**constructor*/ |
el19zf | 4:b12a49f0b730 | 30 | shot(); |
el19zf | 13:eb60628db8bf | 31 | /**destructor*/ |
el19zf | 4:b12a49f0b730 | 32 | ~shot(); |
el19zf | 19:5083339b55e8 | 33 | /**generate first 7 shots vector include position type direction by iterating through the vector*/ |
el19zf | 6:dce38fe4e092 | 34 | void init(); |
el19zf | 13:eb60628db8bf | 35 | |
el19zf | 19:5083339b55e8 | 36 | /**produce a init position of shots((21,0);(42,0);(63,0);(21,45);(42,45);(63,45)) |
el19zf | 19:5083339b55e8 | 37 | *@param vector_i(shot_posandtype*) |
el19zf | 19:5083339b55e8 | 38 | */ |
el19zf | 15:3571beaaeed8 | 39 | void init_pos(shot_posandtype *i); |
el19zf | 13:eb60628db8bf | 40 | |
el19zf | 19:5083339b55e8 | 41 | /**update shots in their directions*/ |
el19zf | 15:3571beaaeed8 | 42 | void update(); |
el19zf | 13:eb60628db8bf | 43 | |
el19zf | 19:5083339b55e8 | 44 | /**resize shots as time goes on |
el19zf | 19:5083339b55e8 | 45 | generate shots in empty vector */ |
el19zf | 13:eb60628db8bf | 46 | void update_shot(); |
el19zf | 13:eb60628db8bf | 47 | |
el19zf | 19:5083339b55e8 | 48 | /**draw updated shots iterating through the vector*/ |
el19zf | 4:b12a49f0b730 | 49 | void draw(N5110 &lcd); |
el19zf | 13:eb60628db8bf | 50 | |
el19zf | 13:eb60628db8bf | 51 | /**if beyoud border, delete it and generate new one, keep total number constant*/ |
el19zf | 6:dce38fe4e092 | 52 | void delete_shot(); |
el19zf | 19:5083339b55e8 | 53 | |
el19zf | 13:eb60628db8bf | 54 | /**control difficulty of game(size) |
el19zf | 13:eb60628db8bf | 55 | *@param timerflag(int) |
el19zf | 19:5083339b55e8 | 56 | *@param increment(float) per 1/6 s |
el19zf | 13:eb60628db8bf | 57 | *@param max(int) |
el19zf | 13:eb60628db8bf | 58 | */ |
el19zf | 13:eb60628db8bf | 59 | void gen_shot(int timer_flag, float increment, int max); |
el19zf | 13:eb60628db8bf | 60 | |
el19zf | 19:5083339b55e8 | 61 | /**accessors set the size of shots |
el19zf | 13:eb60628db8bf | 62 | *@param size(int) |
el19zf | 13:eb60628db8bf | 63 | */ |
el19zf | 8:8287d2ef965d | 64 | void set_size(int size); |
el19zf | 15:3571beaaeed8 | 65 | |
el19zf | 19:5083339b55e8 | 66 | /**accessors create a shot vector for testing*/ |
el19zf | 15:3571beaaeed8 | 67 | void set_shot(int x, int y, int type, int Direction); |
el19zf | 13:eb60628db8bf | 68 | |
el19zf | 13:eb60628db8bf | 69 | /**mutators get size |
el19zf | 13:eb60628db8bf | 70 | *@return current size |
el19zf | 13:eb60628db8bf | 71 | */ |
el19zf | 8:8287d2ef965d | 72 | int get_size(); |
el19zf | 15:3571beaaeed8 | 73 | |
el19zf | 19:5083339b55e8 | 74 | /** mutators get position of the shot for testing*/ |
el19zf | 15:3571beaaeed8 | 75 | Vector2D get_shot(); |
el19zf | 7:c49f3d3b672f | 76 | |
el19zf | 4:b12a49f0b730 | 77 | private: |
el19zf | 19:5083339b55e8 | 78 | /** creat vectors for my struct 'shot_posandtype' |
el19zf | 19:5083339b55e8 | 79 | vector is useful as it is possible to remove or add elements*/ |
el19zf | 5:6774b7272e85 | 80 | std::vector<shot_posandtype> _p; |
el19zf | 19:5083339b55e8 | 81 | |
el19zf | 19:5083339b55e8 | 82 | /**vector size must an integer*/ |
el19zf | 8:8287d2ef965d | 83 | int _size; |
el19zf | 19:5083339b55e8 | 84 | |
el19zf | 19:5083339b55e8 | 85 | /**it's too fast to generate 1 shot per 1/6 second, |
el19zf | 19:5083339b55e8 | 86 | generate a float number (0-1),use f_to_i convert to _size*/ |
el19zf | 13:eb60628db8bf | 87 | float _size_f; |
el19zf | 19:5083339b55e8 | 88 | |
el19zf | 15:3571beaaeed8 | 89 | Vector2D _shot_pos; |
el19zf | 4:b12a49f0b730 | 90 | }; |
el19zf | 4:b12a49f0b730 | 91 | #endif |
el19zf | 7:c49f3d3b672f | 92 | |
el19zf | 4:b12a49f0b730 | 93 | |
el19zf | 7:c49f3d3b672f | 94 | |
el19zf | 7:c49f3d3b672f | 95 |