![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Matis Requis 201241242
Dependencies: mbed
Tempest Game
Game Screen
The board is made of 12 columns. The Hero stays at the top of the column
Game Controls
To control the hero spaceship point the joystick to the column you want the hero to go to.
Press the A button to shoot a bullet in the column you are currently in.
Hero/Hero.cpp@4:8e3ba8d6d915, 2020-05-22 (annotated)
- Committer:
- MatisRequis
- Date:
- Fri May 22 10:29:49 2020 +0000
- Revision:
- 4:8e3ba8d6d915
- Parent:
- 2:d59a92e65bd9
- Child:
- 5:a3c9a5837a7c
Hero movement done, now depends on joystick position
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MatisRequis | 2:d59a92e65bd9 | 1 | #include "Hero.h" |
MatisRequis | 2:d59a92e65bd9 | 2 | |
MatisRequis | 2:d59a92e65bd9 | 3 | Hero::Hero() { |
MatisRequis | 2:d59a92e65bd9 | 4 | |
MatisRequis | 2:d59a92e65bd9 | 5 | } |
MatisRequis | 2:d59a92e65bd9 | 6 | |
MatisRequis | 2:d59a92e65bd9 | 7 | Hero::~Hero() { |
MatisRequis | 2:d59a92e65bd9 | 8 | |
MatisRequis | 2:d59a92e65bd9 | 9 | } |
MatisRequis | 2:d59a92e65bd9 | 10 | |
MatisRequis | 2:d59a92e65bd9 | 11 | void Hero::init(int column) { |
MatisRequis | 2:d59a92e65bd9 | 12 | _column = column; |
MatisRequis | 2:d59a92e65bd9 | 13 | } |
MatisRequis | 2:d59a92e65bd9 | 14 | |
MatisRequis | 2:d59a92e65bd9 | 15 | void Hero::draw(N5110 &lcd) { |
MatisRequis | 4:8e3ba8d6d915 | 16 | |
MatisRequis | 4:8e3ba8d6d915 | 17 | |
MatisRequis | 4:8e3ba8d6d915 | 18 | char buffer[3]; |
MatisRequis | 4:8e3ba8d6d915 | 19 | sprintf(buffer,"%2d", _column); |
MatisRequis | 4:8e3ba8d6d915 | 20 | lcd.printString(buffer,0, 0); |
MatisRequis | 4:8e3ba8d6d915 | 21 | |
MatisRequis | 4:8e3ba8d6d915 | 22 | char ruffer[3]; |
MatisRequis | 4:8e3ba8d6d915 | 23 | sprintf(ruffer,"%2d", _d); |
MatisRequis | 4:8e3ba8d6d915 | 24 | lcd.printString(ruffer,70, 0); |
MatisRequis | 4:8e3ba8d6d915 | 25 | |
MatisRequis | 4:8e3ba8d6d915 | 26 | char tuffer[3]; |
MatisRequis | 4:8e3ba8d6d915 | 27 | sprintf(tuffer,"%2d", _mag); |
MatisRequis | 4:8e3ba8d6d915 | 28 | lcd.printString(tuffer,0, 24); |
MatisRequis | 4:8e3ba8d6d915 | 29 | |
MatisRequis | 2:d59a92e65bd9 | 30 | Vector2D xypos = getxy(); |
MatisRequis | 2:d59a92e65bd9 | 31 | |
MatisRequis | 2:d59a92e65bd9 | 32 | _x = xypos.x; |
MatisRequis | 2:d59a92e65bd9 | 33 | _y = xypos.y; |
MatisRequis | 2:d59a92e65bd9 | 34 | |
MatisRequis | 2:d59a92e65bd9 | 35 | if (_column < 3 && _column >= 0) { |
MatisRequis | 2:d59a92e65bd9 | 36 | lcd.drawRect(_x+4, _y, 6, 2, FILL_BLACK); |
MatisRequis | 4:8e3ba8d6d915 | 37 | lcd.drawLine(_x+2, _y+1, _x+11, _y+1, 1); |
MatisRequis | 4:8e3ba8d6d915 | 38 | lcd.drawLine(_x+2, _y+3, _x+3, _y+4, 1); |
MatisRequis | 4:8e3ba8d6d915 | 39 | lcd.drawLine(_x+11, _y+3, _x+10, _y+4, 1); |
MatisRequis | 2:d59a92e65bd9 | 40 | |
MatisRequis | 2:d59a92e65bd9 | 41 | } else if (_column < 6 && _column > 2) { |
MatisRequis | 4:8e3ba8d6d915 | 42 | lcd.drawLine(_x, _y+4, _x, _y+9, 1); |
MatisRequis | 4:8e3ba8d6d915 | 43 | lcd.drawLine(_x-1, _y+2,_x-1, _y+11, 1); |
MatisRequis | 4:8e3ba8d6d915 | 44 | lcd.drawLine(_x-3, _y+2, _x-4, _y+3, 1); |
MatisRequis | 4:8e3ba8d6d915 | 45 | lcd.drawLine(_x-3, _y+11, _x-4, _y+10, 1); |
MatisRequis | 2:d59a92e65bd9 | 46 | |
MatisRequis | 2:d59a92e65bd9 | 47 | } else if (_column < 9 && _column > 5) { |
MatisRequis | 4:8e3ba8d6d915 | 48 | lcd.drawLine(_x-4, _y, _x-9, _y, 1); |
MatisRequis | 4:8e3ba8d6d915 | 49 | lcd.drawLine(_x-2, _y-1, _x-11, _y-1, 1); |
MatisRequis | 4:8e3ba8d6d915 | 50 | lcd.drawLine(_x-2, _y-3, _x-3, _y-4, 1); |
MatisRequis | 4:8e3ba8d6d915 | 51 | lcd.drawLine(_x-11, _y-3, _x-10, _y-4, 1); |
MatisRequis | 4:8e3ba8d6d915 | 52 | |
MatisRequis | 4:8e3ba8d6d915 | 53 | } else if (_column < 12 && _column > 8) { |
MatisRequis | 4:8e3ba8d6d915 | 54 | lcd.drawLine(_x, _y-4, _x, _y-9, 1); |
MatisRequis | 4:8e3ba8d6d915 | 55 | lcd.drawLine(_x+1, _y-2, _x+1, _y-11, 1); |
MatisRequis | 4:8e3ba8d6d915 | 56 | lcd.drawLine(_x+3, _y-2, _x+4, _y-4, 1); |
MatisRequis | 4:8e3ba8d6d915 | 57 | lcd.drawLine(_x+3, _y-11, _x+4, _y-10, 1); |
MatisRequis | 2:d59a92e65bd9 | 58 | } |
MatisRequis | 2:d59a92e65bd9 | 59 | } |
MatisRequis | 2:d59a92e65bd9 | 60 | |
MatisRequis | 4:8e3ba8d6d915 | 61 | |
MatisRequis | 4:8e3ba8d6d915 | 62 | void Hero::update(float d, float mag, int a) { |
MatisRequis | 4:8e3ba8d6d915 | 63 | |
MatisRequis | 4:8e3ba8d6d915 | 64 | _d = d; |
MatisRequis | 4:8e3ba8d6d915 | 65 | _mag = mag; |
MatisRequis | 2:d59a92e65bd9 | 66 | |
MatisRequis | 4:8e3ba8d6d915 | 67 | if (_d < 0) { |
MatisRequis | 4:8e3ba8d6d915 | 68 | } else if (_d <= 15) { |
MatisRequis | 4:8e3ba8d6d915 | 69 | _column = 1; |
MatisRequis | 4:8e3ba8d6d915 | 70 | } else if (_d <= 45) { |
MatisRequis | 4:8e3ba8d6d915 | 71 | _column = 2; |
MatisRequis | 4:8e3ba8d6d915 | 72 | } else if (_d <= 75) { |
MatisRequis | 4:8e3ba8d6d915 | 73 | _column = 3; |
MatisRequis | 4:8e3ba8d6d915 | 74 | } else if (_d <= 105) { |
MatisRequis | 4:8e3ba8d6d915 | 75 | _column = 4; |
MatisRequis | 4:8e3ba8d6d915 | 76 | } else if (_d <= 135) { |
MatisRequis | 4:8e3ba8d6d915 | 77 | _column = 5; |
MatisRequis | 4:8e3ba8d6d915 | 78 | } else if (_d <= 165) { |
MatisRequis | 4:8e3ba8d6d915 | 79 | _column = 6; |
MatisRequis | 4:8e3ba8d6d915 | 80 | } else if (_d <= 195) { |
MatisRequis | 4:8e3ba8d6d915 | 81 | _column = 7; |
MatisRequis | 4:8e3ba8d6d915 | 82 | } else if (_d <= 225) { |
MatisRequis | 4:8e3ba8d6d915 | 83 | _column = 8; |
MatisRequis | 4:8e3ba8d6d915 | 84 | } else if (_d <= 255) { |
MatisRequis | 4:8e3ba8d6d915 | 85 | _column = 9; |
MatisRequis | 4:8e3ba8d6d915 | 86 | } else if (_d <= 285) { |
MatisRequis | 4:8e3ba8d6d915 | 87 | _column = 10; |
MatisRequis | 4:8e3ba8d6d915 | 88 | } else if (_d <= 315) { |
MatisRequis | 4:8e3ba8d6d915 | 89 | _column = 11; |
MatisRequis | 4:8e3ba8d6d915 | 90 | } else if (_d <= 345) { |
MatisRequis | 4:8e3ba8d6d915 | 91 | _column = 0; |
MatisRequis | 4:8e3ba8d6d915 | 92 | } else { |
MatisRequis | 4:8e3ba8d6d915 | 93 | _column = 1; |
MatisRequis | 2:d59a92e65bd9 | 94 | } |
MatisRequis | 2:d59a92e65bd9 | 95 | } |
MatisRequis | 2:d59a92e65bd9 | 96 | |
MatisRequis | 4:8e3ba8d6d915 | 97 | |
MatisRequis | 2:d59a92e65bd9 | 98 | Vector2D Hero::getxy() { |
MatisRequis | 2:d59a92e65bd9 | 99 | if (_column == 0) { |
MatisRequis | 2:d59a92e65bd9 | 100 | Vector2D p = {21, 1}; |
MatisRequis | 2:d59a92e65bd9 | 101 | return p; |
MatisRequis | 2:d59a92e65bd9 | 102 | } else if (_column == 1) { |
MatisRequis | 2:d59a92e65bd9 | 103 | Vector2D p = {35, 1}; |
MatisRequis | 2:d59a92e65bd9 | 104 | return p; |
MatisRequis | 2:d59a92e65bd9 | 105 | } else if (_column == 2) { |
MatisRequis | 4:8e3ba8d6d915 | 106 | Vector2D p = {48, 1}; |
MatisRequis | 2:d59a92e65bd9 | 107 | return p; |
MatisRequis | 2:d59a92e65bd9 | 108 | } else if (_column == 3) { |
MatisRequis | 4:8e3ba8d6d915 | 109 | Vector2D p = {64, 3}; |
MatisRequis | 2:d59a92e65bd9 | 110 | return p; |
MatisRequis | 2:d59a92e65bd9 | 111 | } else if (_column == 4) { |
MatisRequis | 4:8e3ba8d6d915 | 112 | Vector2D p = {64, 17}; |
MatisRequis | 2:d59a92e65bd9 | 113 | return p; |
MatisRequis | 2:d59a92e65bd9 | 114 | } else if (_column == 5) { |
MatisRequis | 4:8e3ba8d6d915 | 115 | Vector2D p = {64, 30}; |
MatisRequis | 2:d59a92e65bd9 | 116 | return p; |
MatisRequis | 2:d59a92e65bd9 | 117 | } else if (_column == 6) { |
MatisRequis | 4:8e3ba8d6d915 | 118 | Vector2D p = {62, 46}; |
MatisRequis | 2:d59a92e65bd9 | 119 | return p; |
MatisRequis | 2:d59a92e65bd9 | 120 | } else if (_column == 7) { |
MatisRequis | 4:8e3ba8d6d915 | 121 | Vector2D p = {48, 46}; |
MatisRequis | 2:d59a92e65bd9 | 122 | return p; |
MatisRequis | 2:d59a92e65bd9 | 123 | } else if (_column == 8) { |
MatisRequis | 4:8e3ba8d6d915 | 124 | Vector2D p = {35, 46}; |
MatisRequis | 2:d59a92e65bd9 | 125 | return p; |
MatisRequis | 2:d59a92e65bd9 | 126 | } else if (_column == 9) { |
MatisRequis | 4:8e3ba8d6d915 | 127 | Vector2D p = {19, 44}; |
MatisRequis | 2:d59a92e65bd9 | 128 | return p; |
MatisRequis | 2:d59a92e65bd9 | 129 | } else if (_column == 10) { |
MatisRequis | 4:8e3ba8d6d915 | 130 | Vector2D p = {19, 30}; |
MatisRequis | 2:d59a92e65bd9 | 131 | return p; |
MatisRequis | 2:d59a92e65bd9 | 132 | } else if (_column == 11) { |
MatisRequis | 2:d59a92e65bd9 | 133 | Vector2D p = {19, 17}; |
MatisRequis | 2:d59a92e65bd9 | 134 | return p; |
MatisRequis | 4:8e3ba8d6d915 | 135 | } else { |
MatisRequis | 4:8e3ba8d6d915 | 136 | Vector2D p = {0,0}; |
MatisRequis | 4:8e3ba8d6d915 | 137 | return p; |
MatisRequis | 4:8e3ba8d6d915 | 138 | } |
MatisRequis | 2:d59a92e65bd9 | 139 | } |