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
Hero/Hero.cpp@11:b6698572e551, 2020-05-27 (annotated)
- Committer:
- MatisRequis
- Date:
- Wed May 27 05:44:34 2020 +0000
- Revision:
- 11:b6698572e551
- Parent:
- 10:2ae9d4145410
- Child:
- 12:1f1907ebebeb
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 |
---|---|---|---|
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 | 10:2ae9d4145410 | 11 | //initialises the hero's starting column |
MatisRequis | 2:d59a92e65bd9 | 12 | void Hero::init(int column) { |
MatisRequis | 2:d59a92e65bd9 | 13 | _column = column; |
MatisRequis | 2:d59a92e65bd9 | 14 | } |
MatisRequis | 10:2ae9d4145410 | 15 | |
MatisRequis | 11:b6698572e551 | 16 | //draws the hero depending on the column |
MatisRequis | 2:d59a92e65bd9 | 17 | void Hero::draw(N5110 &lcd) { |
MatisRequis | 4:8e3ba8d6d915 | 18 | |
MatisRequis | 2:d59a92e65bd9 | 19 | Vector2D xypos = getxy(); |
MatisRequis | 2:d59a92e65bd9 | 20 | |
MatisRequis | 2:d59a92e65bd9 | 21 | _x = xypos.x; |
MatisRequis | 2:d59a92e65bd9 | 22 | _y = xypos.y; |
MatisRequis | 2:d59a92e65bd9 | 23 | |
MatisRequis | 10:2ae9d4145410 | 24 | changes the orientation of the hero depending on the current column |
MatisRequis | 2:d59a92e65bd9 | 25 | if (_column < 3 && _column >= 0) { |
MatisRequis | 2:d59a92e65bd9 | 26 | lcd.drawRect(_x+4, _y, 6, 2, FILL_BLACK); |
MatisRequis | 4:8e3ba8d6d915 | 27 | lcd.drawLine(_x+2, _y+1, _x+11, _y+1, 1); |
MatisRequis | 4:8e3ba8d6d915 | 28 | lcd.drawLine(_x+2, _y+3, _x+3, _y+4, 1); |
MatisRequis | 4:8e3ba8d6d915 | 29 | lcd.drawLine(_x+11, _y+3, _x+10, _y+4, 1); |
MatisRequis | 2:d59a92e65bd9 | 30 | |
MatisRequis | 2:d59a92e65bd9 | 31 | } else if (_column < 6 && _column > 2) { |
MatisRequis | 4:8e3ba8d6d915 | 32 | lcd.drawLine(_x, _y+4, _x, _y+9, 1); |
MatisRequis | 4:8e3ba8d6d915 | 33 | lcd.drawLine(_x-1, _y+2,_x-1, _y+11, 1); |
MatisRequis | 4:8e3ba8d6d915 | 34 | lcd.drawLine(_x-3, _y+2, _x-4, _y+3, 1); |
MatisRequis | 4:8e3ba8d6d915 | 35 | lcd.drawLine(_x-3, _y+11, _x-4, _y+10, 1); |
MatisRequis | 2:d59a92e65bd9 | 36 | |
MatisRequis | 2:d59a92e65bd9 | 37 | } else if (_column < 9 && _column > 5) { |
MatisRequis | 4:8e3ba8d6d915 | 38 | lcd.drawLine(_x-4, _y, _x-9, _y, 1); |
MatisRequis | 4:8e3ba8d6d915 | 39 | lcd.drawLine(_x-2, _y-1, _x-11, _y-1, 1); |
MatisRequis | 4:8e3ba8d6d915 | 40 | lcd.drawLine(_x-2, _y-3, _x-3, _y-4, 1); |
MatisRequis | 4:8e3ba8d6d915 | 41 | lcd.drawLine(_x-11, _y-3, _x-10, _y-4, 1); |
MatisRequis | 4:8e3ba8d6d915 | 42 | |
MatisRequis | 4:8e3ba8d6d915 | 43 | } else if (_column < 12 && _column > 8) { |
MatisRequis | 4:8e3ba8d6d915 | 44 | lcd.drawLine(_x, _y-4, _x, _y-9, 1); |
MatisRequis | 4:8e3ba8d6d915 | 45 | lcd.drawLine(_x+1, _y-2, _x+1, _y-11, 1); |
MatisRequis | 4:8e3ba8d6d915 | 46 | lcd.drawLine(_x+3, _y-2, _x+4, _y-4, 1); |
MatisRequis | 4:8e3ba8d6d915 | 47 | lcd.drawLine(_x+3, _y-11, _x+4, _y-10, 1); |
MatisRequis | 2:d59a92e65bd9 | 48 | } |
MatisRequis | 2:d59a92e65bd9 | 49 | } |
MatisRequis | 2:d59a92e65bd9 | 50 | |
MatisRequis | 10:2ae9d4145410 | 51 | //sets the column depending on the joystick angle |
MatisRequis | 10:2ae9d4145410 | 52 | void Hero::update(float d) { |
MatisRequis | 10:2ae9d4145410 | 53 | |
MatisRequis | 6:037dfa5064a1 | 54 | |
MatisRequis | 10:2ae9d4145410 | 55 | if (d < 0) { |
MatisRequis | 10:2ae9d4145410 | 56 | } else if (d <= 15) { |
MatisRequis | 4:8e3ba8d6d915 | 57 | _column = 1; |
MatisRequis | 10:2ae9d4145410 | 58 | } else if (d <= 45) { |
MatisRequis | 4:8e3ba8d6d915 | 59 | _column = 2; |
MatisRequis | 10:2ae9d4145410 | 60 | } else if (d <= 75) { |
MatisRequis | 4:8e3ba8d6d915 | 61 | _column = 3; |
MatisRequis | 10:2ae9d4145410 | 62 | } else if (d <= 105) { |
MatisRequis | 4:8e3ba8d6d915 | 63 | _column = 4; |
MatisRequis | 10:2ae9d4145410 | 64 | } else if (d <= 135) { |
MatisRequis | 4:8e3ba8d6d915 | 65 | _column = 5; |
MatisRequis | 10:2ae9d4145410 | 66 | } else if (d <= 165) { |
MatisRequis | 4:8e3ba8d6d915 | 67 | _column = 6; |
MatisRequis | 10:2ae9d4145410 | 68 | } else if (d <= 195) { |
MatisRequis | 4:8e3ba8d6d915 | 69 | _column = 7; |
MatisRequis | 10:2ae9d4145410 | 70 | } else if (d <= 225) { |
MatisRequis | 4:8e3ba8d6d915 | 71 | _column = 8; |
MatisRequis | 10:2ae9d4145410 | 72 | } else if (d <= 255) { |
MatisRequis | 4:8e3ba8d6d915 | 73 | _column = 9; |
MatisRequis | 10:2ae9d4145410 | 74 | } else if (d <= 285) { |
MatisRequis | 4:8e3ba8d6d915 | 75 | _column = 10; |
MatisRequis | 10:2ae9d4145410 | 76 | } else if (d <= 315) { |
MatisRequis | 4:8e3ba8d6d915 | 77 | _column = 11; |
MatisRequis | 10:2ae9d4145410 | 78 | } else if (d <= 345) { |
MatisRequis | 4:8e3ba8d6d915 | 79 | _column = 0; |
MatisRequis | 4:8e3ba8d6d915 | 80 | } else { |
MatisRequis | 4:8e3ba8d6d915 | 81 | _column = 1; |
MatisRequis | 2:d59a92e65bd9 | 82 | } |
MatisRequis | 5:a3c9a5837a7c | 83 | |
MatisRequis | 6:037dfa5064a1 | 84 | |
MatisRequis | 2:d59a92e65bd9 | 85 | } |
MatisRequis | 2:d59a92e65bd9 | 86 | |
MatisRequis | 10:2ae9d4145410 | 87 | //returns the current hero position |
MatisRequis | 2:d59a92e65bd9 | 88 | Vector2D Hero::getxy() { |
MatisRequis | 2:d59a92e65bd9 | 89 | if (_column == 0) { |
MatisRequis | 10:2ae9d4145410 | 90 | Vector2D hero_pos = {21, 1}; |
MatisRequis | 10:2ae9d4145410 | 91 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 92 | |
MatisRequis | 2:d59a92e65bd9 | 93 | } else if (_column == 1) { |
MatisRequis | 10:2ae9d4145410 | 94 | Vector2D hero_pos = {35, 1}; |
MatisRequis | 10:2ae9d4145410 | 95 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 96 | |
MatisRequis | 2:d59a92e65bd9 | 97 | } else if (_column == 2) { |
MatisRequis | 10:2ae9d4145410 | 98 | Vector2D hero_pos = {48, 1}; |
MatisRequis | 10:2ae9d4145410 | 99 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 100 | |
MatisRequis | 2:d59a92e65bd9 | 101 | } else if (_column == 3) { |
MatisRequis | 10:2ae9d4145410 | 102 | Vector2D hero_pos = {64, 3}; |
MatisRequis | 10:2ae9d4145410 | 103 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 104 | |
MatisRequis | 2:d59a92e65bd9 | 105 | } else if (_column == 4) { |
MatisRequis | 10:2ae9d4145410 | 106 | Vector2D hero_pos = {64, 17}; |
MatisRequis | 10:2ae9d4145410 | 107 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 108 | |
MatisRequis | 2:d59a92e65bd9 | 109 | } else if (_column == 5) { |
MatisRequis | 10:2ae9d4145410 | 110 | Vector2D hero_pos = {64, 30}; |
MatisRequis | 10:2ae9d4145410 | 111 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 112 | |
MatisRequis | 2:d59a92e65bd9 | 113 | } else if (_column == 6) { |
MatisRequis | 10:2ae9d4145410 | 114 | Vector2D hero_pos = {62, 46}; |
MatisRequis | 10:2ae9d4145410 | 115 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 116 | |
MatisRequis | 2:d59a92e65bd9 | 117 | } else if (_column == 7) { |
MatisRequis | 10:2ae9d4145410 | 118 | Vector2D hero_pos = {48, 46}; |
MatisRequis | 10:2ae9d4145410 | 119 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 120 | |
MatisRequis | 2:d59a92e65bd9 | 121 | } else if (_column == 8) { |
MatisRequis | 10:2ae9d4145410 | 122 | Vector2D hero_pos = {35, 46}; |
MatisRequis | 10:2ae9d4145410 | 123 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 124 | |
MatisRequis | 2:d59a92e65bd9 | 125 | } else if (_column == 9) { |
MatisRequis | 10:2ae9d4145410 | 126 | Vector2D hero_pos = {19, 44}; |
MatisRequis | 10:2ae9d4145410 | 127 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 128 | |
MatisRequis | 2:d59a92e65bd9 | 129 | } else if (_column == 10) { |
MatisRequis | 10:2ae9d4145410 | 130 | Vector2D hero_pos = {19, 30}; |
MatisRequis | 10:2ae9d4145410 | 131 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 132 | |
MatisRequis | 2:d59a92e65bd9 | 133 | } else if (_column == 11) { |
MatisRequis | 10:2ae9d4145410 | 134 | Vector2D hero_pos = {19, 17}; |
MatisRequis | 10:2ae9d4145410 | 135 | return hero_pos; |
MatisRequis | 10:2ae9d4145410 | 136 | |
MatisRequis | 4:8e3ba8d6d915 | 137 | } else { |
MatisRequis | 10:2ae9d4145410 | 138 | Vector2D hero_pos = {0,0}; |
MatisRequis | 10:2ae9d4145410 | 139 | return hero_pos; |
MatisRequis | 4:8e3ba8d6d915 | 140 | } |
MatisRequis | 6:037dfa5064a1 | 141 | } |
MatisRequis | 6:037dfa5064a1 | 142 | |
MatisRequis | 10:2ae9d4145410 | 143 | //returns the current column of the hero |
MatisRequis | 6:037dfa5064a1 | 144 | int Hero::get_column() { |
MatisRequis | 6:037dfa5064a1 | 145 | return _column; |
MatisRequis | 2:d59a92e65bd9 | 146 | } |