Project Submission (late)

Dependencies:   mbed

Committer:
el17tc
Date:
Fri May 10 14:52:28 2019 +0000
Revision:
3:83e79d31930c
Parent:
0:72f372170a73
final commit, API is added.; I'm not sure if there is a specific statement of academic integrity wanted but- I declare that this work is 100% my own, I have not plagiarised any work or attempted to fabricate any part of it for extra marks.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17tc 0:72f372170a73 1 #include "Drawer.h"
el17tc 0:72f372170a73 2 #include "GraphicMatrices.h"
el17tc 0:72f372170a73 3
el17tc 3:83e79d31930c 4 // constructor simply assigns the passed pointers to the
el17tc 3:83e79d31930c 5 // class' internal fields for storage
el17tc 0:72f372170a73 6 Drawer::Drawer(Player* playerPtr, N5110* screenPtr) {
el17tc 0:72f372170a73 7 player = playerPtr;
el17tc 0:72f372170a73 8 lcd = screenPtr;
el17tc 0:72f372170a73 9 }
el17tc 0:72f372170a73 10
el17tc 0:72f372170a73 11 void Drawer::drawBranch1(Vector2Di loc) {
el17tc 0:72f372170a73 12 Vector2Di peekDirection = player->direction;
el17tc 3:83e79d31930c 13 peekDirection.rotateVector(-PI/2); // rotate vector left
el17tc 3:83e79d31930c 14 loc.addVector(peekDirection); // then move forward one
el17tc 0:72f372170a73 15
el17tc 0:72f372170a73 16 lcd->drawSprite(0,3,42,21,(int *)greenBranchG);
el17tc 0:72f372170a73 17 if (player->checkLocation(loc, 0, 0)) {
el17tc 3:83e79d31930c 18 //if the square in front is open
el17tc 0:72f372170a73 19 lcd->drawSprite(0,9,30,21,(int *)sideSquare1G);
el17tc 0:72f372170a73 20 loc.addVector(player->direction); // move forward
el17tc 0:72f372170a73 21 }
el17tc 0:72f372170a73 22 else if (player->checkLocation(loc, 0, 2)) {
el17tc 3:83e79d31930c 23 // if the square in front is the exit
el17tc 0:72f372170a73 24 lcd->drawSprite(0,9,30,21,(int *)sideSquare1G);
el17tc 3:83e79d31930c 25 lcd->drawSprite(0,8,32,21,(int *)exit2); // draw the exit graphic for this position
el17tc 0:72f372170a73 26 return;
el17tc 0:72f372170a73 27 }
el17tc 0:72f372170a73 28 else {
el17tc 0:72f372170a73 29 return;
el17tc 0:72f372170a73 30 }
el17tc 0:72f372170a73 31 if (player->checkLocation(loc, -PI/2, 0))
el17tc 0:72f372170a73 32 lcd->drawSprite(0,12,24,7,(int *)sideBranch1G);
el17tc 0:72f372170a73 33 if (player->checkLocation(loc, 0, 0))
el17tc 0:72f372170a73 34 lcd->drawSprite(10,13,22,11,(int *)sideSquare2G);
el17tc 0:72f372170a73 35 else if (player->checkLocation(loc, 0, 2)) {
el17tc 0:72f372170a73 36 lcd->drawSprite(10,13,22,11,(int *)sideSquare2G);
el17tc 0:72f372170a73 37 lcd->drawSprite(15,15,18,6,(int *)exit6);
el17tc 0:72f372170a73 38 }
el17tc 0:72f372170a73 39 }
el17tc 0:72f372170a73 40
el17tc 0:72f372170a73 41 void Drawer::drawBranch2(Vector2Di loc) {
el17tc 0:72f372170a73 42 Vector2Di peekDirection = player->direction;
el17tc 0:72f372170a73 43 peekDirection.rotateVector(PI/2);
el17tc 0:72f372170a73 44 loc.addVector(peekDirection);
el17tc 0:72f372170a73 45 lcd->drawSprite(63,3,42,21,(int *)greenBranchG);
el17tc 0:72f372170a73 46 if (player->checkLocation(loc, 0, 0)) {
el17tc 0:72f372170a73 47 lcd->drawSprite(63,9,30,21,(int *)sideSquare6G);
el17tc 0:72f372170a73 48 loc.addVector(player->direction);
el17tc 0:72f372170a73 49 }
el17tc 0:72f372170a73 50 else if (player->checkLocation(loc, 0, 2)) {
el17tc 0:72f372170a73 51 //lcd->drawSprite(63,9,30,21,(int *)sideSquare6G);
el17tc 0:72f372170a73 52 lcd->drawSprite(63,8,32,21,(int *)exit2);
el17tc 0:72f372170a73 53 return;
el17tc 0:72f372170a73 54 }
el17tc 0:72f372170a73 55 else {
el17tc 0:72f372170a73 56 return;
el17tc 0:72f372170a73 57 }
el17tc 0:72f372170a73 58 if (player->checkLocation(loc, PI/2, 0))
el17tc 0:72f372170a73 59 lcd->drawSprite(77,12,24,7,(int *)sideBranch1G);
el17tc 0:72f372170a73 60 if (player->checkLocation(loc, 0, 0))
el17tc 0:72f372170a73 61 lcd->drawSprite(63,13,22,11,(int *)sideSquare7G);
el17tc 0:72f372170a73 62 else if (player->checkLocation(loc, 0, 2)) {
el17tc 0:72f372170a73 63 lcd->drawSprite(63,13,22,11,(int *)sideSquare7G);
el17tc 0:72f372170a73 64 lcd->drawSprite(63,15,18,6,(int *)exit5);
el17tc 0:72f372170a73 65 }
el17tc 0:72f372170a73 66 }
el17tc 0:72f372170a73 67
el17tc 0:72f372170a73 68
el17tc 0:72f372170a73 69 void Drawer::drawBranch3(Vector2Di loc) {
el17tc 0:72f372170a73 70 Vector2Di peekDirection = player->direction;
el17tc 0:72f372170a73 71 peekDirection.rotateVector(-PI/2);
el17tc 0:72f372170a73 72 loc.addVector(peekDirection);
el17tc 0:72f372170a73 73 lcd->drawSprite(22,12,24,8,(int *)orangeBranchG);
el17tc 0:72f372170a73 74 if (player->checkLocation(loc, 0, 0)) {
el17tc 0:72f372170a73 75 lcd->drawSprite(22,17,14,8,(int *)sideSquare3G);
el17tc 0:72f372170a73 76 loc.addVector(player->direction);
el17tc 0:72f372170a73 77 }
el17tc 0:72f372170a73 78 else if (player->checkLocation(loc, 0, 2)) {
el17tc 0:72f372170a73 79 //lcd->drawSprite(22,17,14,8,(int *)sideSquare3G);
el17tc 0:72f372170a73 80 lcd->drawSprite(22,15,18,8,(int *)exit4);
el17tc 0:72f372170a73 81 return;
el17tc 0:72f372170a73 82 }
el17tc 0:72f372170a73 83 else {
el17tc 0:72f372170a73 84 return;
el17tc 0:72f372170a73 85 }
el17tc 0:72f372170a73 86 if (player->checkLocation(loc, 0, 0)) {
el17tc 0:72f372170a73 87 lcd->drawSprite(28,19,10,2,(int *)sideSquare4G);
el17tc 0:72f372170a73 88 }
el17tc 0:72f372170a73 89 else {
el17tc 0:72f372170a73 90 return;
el17tc 0:72f372170a73 91 }
el17tc 0:72f372170a73 92 }
el17tc 0:72f372170a73 93 void Drawer::drawBranch4(Vector2Di loc) {
el17tc 0:72f372170a73 94 Vector2Di peekDirection = player->direction;
el17tc 0:72f372170a73 95 peekDirection.rotateVector(PI/2);
el17tc 0:72f372170a73 96 loc.addVector(peekDirection);
el17tc 0:72f372170a73 97 lcd->drawSprite(54,12,24,8,(int *)orangeBranchG);
el17tc 0:72f372170a73 98 if (player->checkLocation(loc, 0, 0)) {
el17tc 0:72f372170a73 99 lcd->drawSprite(54,17,14,8,(int *)sideSquare8G);
el17tc 0:72f372170a73 100 loc.addVector(player->direction);
el17tc 0:72f372170a73 101 }
el17tc 0:72f372170a73 102 else if (player->checkLocation(loc, 0, 2)) {
el17tc 0:72f372170a73 103 //lcd->drawSprite(54,17,14,8,(int *)sideSquare8G);
el17tc 0:72f372170a73 104 lcd->drawSprite(54,15,18,8,(int *)exit4);
el17tc 0:72f372170a73 105 return;
el17tc 0:72f372170a73 106 }
el17tc 0:72f372170a73 107 else {
el17tc 0:72f372170a73 108 return;
el17tc 0:72f372170a73 109 }
el17tc 0:72f372170a73 110 if (player->checkLocation(loc, 0, 0)) {
el17tc 0:72f372170a73 111 lcd->drawSprite(54,19,10,2,(int *)sideSquare4G);
el17tc 0:72f372170a73 112 }
el17tc 0:72f372170a73 113 else {
el17tc 0:72f372170a73 114 return;
el17tc 0:72f372170a73 115 }
el17tc 0:72f372170a73 116 }
el17tc 0:72f372170a73 117 void Drawer::drawBranch5(Vector2Di loc) {
el17tc 0:72f372170a73 118 Vector2Di peekDirection = player->direction;
el17tc 0:72f372170a73 119 peekDirection.rotateVector(-PI/2);
el17tc 0:72f372170a73 120 loc.addVector(peekDirection);
el17tc 0:72f372170a73 121 lcd->drawSprite(31,18,12,5,(int *)blueBranchG);
el17tc 0:72f372170a73 122 if (player->checkLocation(loc, 0, 0)) {
el17tc 0:72f372170a73 123 lcd->drawSprite(31,20,8,5,(int *)sideSquare5G);
el17tc 0:72f372170a73 124 }
el17tc 0:72f372170a73 125 else if (player->checkLocation(loc, 0, 2)) {
el17tc 0:72f372170a73 126 //lcd->drawSprite(54,17,14,8,(int *)sideSquare5G);
el17tc 0:72f372170a73 127 lcd->drawSprite(31,20,8,5,(int *)exit8);
el17tc 0:72f372170a73 128 return;
el17tc 0:72f372170a73 129 }
el17tc 0:72f372170a73 130 else {
el17tc 0:72f372170a73 131 return;
el17tc 0:72f372170a73 132 }
el17tc 0:72f372170a73 133 }
el17tc 0:72f372170a73 134 void Drawer::drawBranch6(Vector2Di loc) {
el17tc 0:72f372170a73 135 Vector2Di peekDirection = player->direction;
el17tc 0:72f372170a73 136 peekDirection.rotateVector(PI/2);
el17tc 0:72f372170a73 137 loc.addVector(peekDirection);
el17tc 0:72f372170a73 138 lcd->drawSprite(48,18,12,5,(int *)blueBranchG);
el17tc 0:72f372170a73 139 if (player->checkLocation(loc, 0, 0)) {
el17tc 0:72f372170a73 140 lcd->drawSprite(48,20,8,5,(int *)sideSquare9G);
el17tc 0:72f372170a73 141 }
el17tc 0:72f372170a73 142 else if (player->checkLocation(loc, 0, 2)) {
el17tc 0:72f372170a73 143 //lcd->drawSprite(48,20,8,5,(int *)sideSquare9G);
el17tc 0:72f372170a73 144 lcd->drawSprite(48,20,8,5,(int *)exit8);
el17tc 0:72f372170a73 145 return;
el17tc 0:72f372170a73 146 }
el17tc 0:72f372170a73 147 else {
el17tc 0:72f372170a73 148 return;
el17tc 0:72f372170a73 149 }
el17tc 0:72f372170a73 150 }
el17tc 0:72f372170a73 151
el17tc 0:72f372170a73 152 void Drawer::drawScreen() {
el17tc 0:72f372170a73 153 Vector2Di ghostLocation = player->pos;
el17tc 0:72f372170a73 154 // phase 1
el17tc 0:72f372170a73 155 lcd->drawSprite(18,0,48,48,(int *)greenSquareG);
el17tc 0:72f372170a73 156 if (player->checkLocation(ghostLocation, -PI/2, 0)) // if the left square is empty
el17tc 0:72f372170a73 157 drawBranch1(ghostLocation);
el17tc 0:72f372170a73 158 if (player->checkLocation(ghostLocation, PI/2, 0)) // left/right are reversed
el17tc 0:72f372170a73 159 drawBranch2(ghostLocation);
el17tc 0:72f372170a73 160
el17tc 0:72f372170a73 161 if (player->checkLocation(ghostLocation, 0, 0)) { // if the front square is empty
el17tc 0:72f372170a73 162 ghostLocation.addVector(player->direction); // move forward
el17tc 0:72f372170a73 163 }
el17tc 0:72f372170a73 164 else if (player->checkLocation(ghostLocation, 0, 2)) {
el17tc 0:72f372170a73 165 lcd->drawSprite(22,4,40,40,(int *)orangeSquareG);
el17tc 0:72f372170a73 166 lcd->drawSprite(26,8,32,32,(int *)exit1); // if front square is exit
el17tc 0:72f372170a73 167 return;
el17tc 0:72f372170a73 168 }
el17tc 0:72f372170a73 169 else {
el17tc 0:72f372170a73 170 return; // drawing is complete
el17tc 0:72f372170a73 171 }
el17tc 0:72f372170a73 172 // phase 2
el17tc 0:72f372170a73 173 lcd->drawSprite(22,4,40,40,(int *)orangeSquareG);
el17tc 0:72f372170a73 174 if (player->checkLocation(ghostLocation, -PI/2, 0)) // if the left square is empty
el17tc 0:72f372170a73 175 drawBranch3(ghostLocation);
el17tc 0:72f372170a73 176 if (player->checkLocation(ghostLocation, PI/2, 0))
el17tc 0:72f372170a73 177 drawBranch4(ghostLocation);
el17tc 0:72f372170a73 178 if (player->checkLocation(ghostLocation,0, 0)) { // if the front square is empty
el17tc 0:72f372170a73 179 ghostLocation.addVector(player->direction); // move forward
el17tc 0:72f372170a73 180 }
el17tc 0:72f372170a73 181 else if (player->checkLocation(ghostLocation, 0, 2)) {
el17tc 0:72f372170a73 182 lcd->drawSprite(31,13,22,22,(int *)blueSquareG);
el17tc 0:72f372170a73 183 lcd->drawSprite(33,15,18,18,(int *)exit3); // if front square is exit
el17tc 0:72f372170a73 184 return;
el17tc 0:72f372170a73 185 }
el17tc 0:72f372170a73 186 else {
el17tc 0:72f372170a73 187 return; // drawing is complete
el17tc 0:72f372170a73 188 }
el17tc 0:72f372170a73 189 // phase 3
el17tc 0:72f372170a73 190 lcd->drawSprite(31,13,22,22,(int *)blueSquareG);
el17tc 0:72f372170a73 191 if (player->checkLocation(ghostLocation, -PI/2, 0)) // if the left square is empty
el17tc 0:72f372170a73 192 drawBranch5(ghostLocation);
el17tc 0:72f372170a73 193 if (player->checkLocation(ghostLocation, PI/2, 0))
el17tc 0:72f372170a73 194 drawBranch6(ghostLocation);
el17tc 0:72f372170a73 195
el17tc 0:72f372170a73 196 if (player->checkLocation(ghostLocation,0, 0)) { // if the front square is empty
el17tc 0:72f372170a73 197 ghostLocation.addVector(player->direction); // move forward
el17tc 0:72f372170a73 198 }
el17tc 0:72f372170a73 199 else if (player->checkLocation(ghostLocation, 0, 2)) {
el17tc 0:72f372170a73 200 lcd->drawSprite(37,19,10,10,(int *)yellowSquareG);
el17tc 0:72f372170a73 201 lcd->drawSprite(38,20,8,8,(int *)exit7); // if front square is exit
el17tc 0:72f372170a73 202 return;
el17tc 0:72f372170a73 203 }
el17tc 0:72f372170a73 204 else {
el17tc 0:72f372170a73 205 return; // drawing is complete
el17tc 0:72f372170a73 206 }
el17tc 0:72f372170a73 207 // phase 4
el17tc 0:72f372170a73 208 lcd->drawSprite(37,19,10,10,(int *)yellowSquareG);
el17tc 0:72f372170a73 209 if (player->checkLocation(ghostLocation, -PI/2, 0)) // if the left square is empty
el17tc 0:72f372170a73 210 lcd->drawSprite(37,21,6,2,(int *)yellowBranchG);
el17tc 0:72f372170a73 211 if (player->checkLocation(ghostLocation, PI/2, 0))
el17tc 0:72f372170a73 212 lcd->drawSprite(45,21,6,2,(int *)yellowBranchG);
el17tc 0:72f372170a73 213
el17tc 0:72f372170a73 214 if (player->checkLocation(ghostLocation,0, 0)) { // if the front square is empty
el17tc 0:72f372170a73 215 ghostLocation.addVector(player->direction); // move forward
el17tc 0:72f372170a73 216 }
el17tc 0:72f372170a73 217 else {
el17tc 0:72f372170a73 218 return; // drawing is complete
el17tc 0:72f372170a73 219 }
el17tc 0:72f372170a73 220 // phase 5
el17tc 0:72f372170a73 221 lcd->drawSprite(40,22,4,4,(int *)purpleSquareG);
el17tc 0:72f372170a73 222 }