Adam Baker 201166301

Dependencies:   mbed Gamepad N5110

Committer:
adambakerwa
Date:
Thu May 09 12:19:36 2019 +0000
Revision:
52:beeffd296ea3
Parent:
50:9fc8edf722a8

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adambakerwa 50:9fc8edf722a8 1 #include "Blockhead.h"
adambakerwa 50:9fc8edf722a8 2
adambakerwa 50:9fc8edf722a8 3
adambakerwa 50:9fc8edf722a8 4
adambakerwa 50:9fc8edf722a8 5
adambakerwa 50:9fc8edf722a8 6 // nothing doing in the constructor and destructor
adambakerwa 50:9fc8edf722a8 7 Blockhead::Blockhead()
adambakerwa 50:9fc8edf722a8 8 {
adambakerwa 50:9fc8edf722a8 9
adambakerwa 50:9fc8edf722a8 10 }
adambakerwa 50:9fc8edf722a8 11
adambakerwa 50:9fc8edf722a8 12 Blockhead::~Blockhead()
adambakerwa 50:9fc8edf722a8 13 {
adambakerwa 50:9fc8edf722a8 14
adambakerwa 50:9fc8edf722a8 15 }
adambakerwa 50:9fc8edf722a8 16
adambakerwa 50:9fc8edf722a8 17
adambakerwa 50:9fc8edf722a8 18 //initialise all vairables
adambakerwa 50:9fc8edf722a8 19 void Blockhead::init()
adambakerwa 50:9fc8edf722a8 20 {
adambakerwa 50:9fc8edf722a8 21
adambakerwa 50:9fc8edf722a8 22 _x = 35; //x cordinate of blockhead
adambakerwa 50:9fc8edf722a8 23 _y = 5; //y cordinate of bloc
adambakerwa 50:9fc8edf722a8 24 _jump = 0; //jump counter
adambakerwa 50:9fc8edf722a8 25 _wjr = 0; //wall jump right counter
adambakerwa 50:9fc8edf722a8 26 _wjl = 0; //wall jump left counter
adambakerwa 50:9fc8edf722a8 27 _fall = 0; //fall counter
adambakerwa 50:9fc8edf722a8 28 _sprintright = 0; //right sprint counter
adambakerwa 50:9fc8edf722a8 29 _sprintleft = 0; //left sprint counter
adambakerwa 50:9fc8edf722a8 30 _level = 1; //dont initialise every time so doesnt restart at beggining each time..
adambakerwa 50:9fc8edf722a8 31 _runani = 0; //run counter
adambakerwa 50:9fc8edf722a8 32 _walkani = 0; //wak animation counter
adambakerwa 50:9fc8edf722a8 33 _death = 0; //death counter
adambakerwa 50:9fc8edf722a8 34 }
adambakerwa 50:9fc8edf722a8 35
adambakerwa 50:9fc8edf722a8 36
adambakerwa 50:9fc8edf722a8 37 //initialise all variables, except level
adambakerwa 50:9fc8edf722a8 38 void Blockhead::continue_init()
adambakerwa 50:9fc8edf722a8 39 {
adambakerwa 50:9fc8edf722a8 40
adambakerwa 50:9fc8edf722a8 41
adambakerwa 50:9fc8edf722a8 42 _x = 0; //x cordiante of blockhead
adambakerwa 50:9fc8edf722a8 43 if (_level == 6 || _level == 7 || _level == 9) { //start point differs depending on what level your on
adambakerwa 50:9fc8edf722a8 44 _y = -3; //y cordiante either 5,
adambakerwa 50:9fc8edf722a8 45 } else {
adambakerwa 50:9fc8edf722a8 46 _y = 25; //or 25
adambakerwa 50:9fc8edf722a8 47 }
adambakerwa 50:9fc8edf722a8 48 _jump = 0; //jump counter
adambakerwa 50:9fc8edf722a8 49 _wjr = 0; //wall jump right counter
adambakerwa 50:9fc8edf722a8 50 _wjl = 0; //wall jump left counter
adambakerwa 50:9fc8edf722a8 51 _fall = 0; //fall counter
adambakerwa 50:9fc8edf722a8 52 _sprintright = 0; //sprint right counter
adambakerwa 50:9fc8edf722a8 53 _sprintleft = 0; //sprint left counter
adambakerwa 50:9fc8edf722a8 54 _runani = 0; //run counter
adambakerwa 50:9fc8edf722a8 55 _walkani = 0; //walk animation counter
adambakerwa 50:9fc8edf722a8 56 _death = 0; //death counter
adambakerwa 50:9fc8edf722a8 57
adambakerwa 50:9fc8edf722a8 58
adambakerwa 50:9fc8edf722a8 59 }
adambakerwa 50:9fc8edf722a8 60
adambakerwa 50:9fc8edf722a8 61
adambakerwa 50:9fc8edf722a8 62 //all mechanics controling blockhead (movement from user input, movement from platforms, and gameover)
adambakerwa 50:9fc8edf722a8 63 void Blockhead::blockhead(Pos pos, N5110 &lcd, Gamepad &pad)
adambakerwa 50:9fc8edf722a8 64 {
adambakerwa 50:9fc8edf722a8 65 movement(lcd, pad); //contolls movement of blockhead depending on input
adambakerwa 50:9fc8edf722a8 66 platform_check(pos); //checks if blochead is on or by a moving platform,
adambakerwa 50:9fc8edf722a8 67 on_platform(lcd); //if so, moves blockhead acordingly
adambakerwa 50:9fc8edf722a8 68 gameover(pos, lcd); //intiates death sequence if spike hit or crushed by platform
adambakerwa 50:9fc8edf722a8 69
adambakerwa 50:9fc8edf722a8 70
adambakerwa 50:9fc8edf722a8 71
adambakerwa 50:9fc8edf722a8 72 }
adambakerwa 50:9fc8edf722a8 73
adambakerwa 50:9fc8edf722a8 74
adambakerwa 50:9fc8edf722a8 75 //all the functions which take an input and controll movement of blockhead (in correct order)
adambakerwa 50:9fc8edf722a8 76 void Blockhead::movement(N5110 &lcd, Gamepad &pad)
adambakerwa 50:9fc8edf722a8 77 {
adambakerwa 50:9fc8edf722a8 78 button_press(lcd, pad); //checks if A button is pressed at correct moment (on ground for example), and starts correct counter
adambakerwa 50:9fc8edf722a8 79 _speed = get_speed(pad); //gets speed value according to joystick position
adambakerwa 50:9fc8edf722a8 80 jump(lcd); //performes a jump when jump counter is 1
adambakerwa 50:9fc8edf722a8 81 wall_jump_left(lcd, _speed); //peformes a wall jumo when wjl counter is 1
adambakerwa 50:9fc8edf722a8 82 wall_jump_right(lcd, _speed); //peformes a wall jump when wjr counter is 1
adambakerwa 50:9fc8edf722a8 83 run_left(lcd, _speed); //moves left if speed is less than 0, lower speed is quicker blockhead moves
adambakerwa 50:9fc8edf722a8 84 run_right(lcd, _speed); //moves righ if speed is more than 0, higher speed is quicker blockhead moves
adambakerwa 50:9fc8edf722a8 85 cancel_sprint(lcd, _speed); //cancels sprint if hits wall or joystick is 0
adambakerwa 50:9fc8edf722a8 86 fall(lcd); //falls when no ground below
adambakerwa 50:9fc8edf722a8 87 runner_state(lcd, pad, _speed); //displays different sprites depending on what state runner is in (animating him)
adambakerwa 50:9fc8edf722a8 88 }
adambakerwa 50:9fc8edf722a8 89
adambakerwa 50:9fc8edf722a8 90
adambakerwa 50:9fc8edf722a8 91 //when game over, returns 1
adambakerwa 50:9fc8edf722a8 92 int Blockhead::gameover_flag(Gamepad &pad)
adambakerwa 50:9fc8edf722a8 93 {
adambakerwa 50:9fc8edf722a8 94 if (_death > 8 || fallen(pad) == 1) { //will return 1 when character falls of screen, or death sequence completes,
adambakerwa 50:9fc8edf722a8 95 _gameover = 1;
adambakerwa 50:9fc8edf722a8 96 } else {
adambakerwa 50:9fc8edf722a8 97 _gameover = 0;
adambakerwa 50:9fc8edf722a8 98 }
adambakerwa 50:9fc8edf722a8 99
adambakerwa 50:9fc8edf722a8 100 //printf("_gameove = %d", _gameover); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 101
adambakerwa 50:9fc8edf722a8 102 return _gameover;
adambakerwa 50:9fc8edf722a8 103 }
adambakerwa 50:9fc8edf722a8 104
adambakerwa 50:9fc8edf722a8 105 //starts death sequence if crushed by moving platform or if hit spikes
adambakerwa 50:9fc8edf722a8 106 void Blockhead::gameover(Pos pos, N5110 &lcd)
adambakerwa 50:9fc8edf722a8 107 {
adambakerwa 50:9fc8edf722a8 108 if ((crushed_by_ver(pos) + crushed_by_ver_2(pos) + spike_hit(lcd, pos))>0 && _death==0) {
adambakerwa 50:9fc8edf722a8 109 _death = 1;
adambakerwa 50:9fc8edf722a8 110 }
adambakerwa 50:9fc8edf722a8 111
adambakerwa 50:9fc8edf722a8 112 //printf("_death = %d", _death); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 113 }
adambakerwa 50:9fc8edf722a8 114
adambakerwa 50:9fc8edf722a8 115
adambakerwa 50:9fc8edf722a8 116 //change increment depending on what button is pressed and where the runner is
adambakerwa 50:9fc8edf722a8 117 void Blockhead::button_press(N5110 &lcd, Gamepad &pad)
adambakerwa 50:9fc8edf722a8 118 {
adambakerwa 50:9fc8edf722a8 119
adambakerwa 50:9fc8edf722a8 120 if (pad.check_event(Gamepad::A_PRESSED)) {
adambakerwa 50:9fc8edf722a8 121 if (_ani.pixelsDown(_x,_y,lcd) || _d3 == 3 || _d4 == 3) { //if standing, or if on vertical platform,
adambakerwa 50:9fc8edf722a8 122 _jump = 1; //jump increment begins.
adambakerwa 50:9fc8edf722a8 123 pad.tone(880, 0.1);
adambakerwa 50:9fc8edf722a8 124 } else if (_ani.pixelsLeft(_x,_y,lcd) && _ani.pixelsDown(_x,_y,lcd)==false && _wjr == 0) { //if in air and by wall to left, wall jump right = 1
adambakerwa 50:9fc8edf722a8 125 _wjr++;
adambakerwa 50:9fc8edf722a8 126 pad.tone(1046.502, 0.1);
adambakerwa 50:9fc8edf722a8 127 } else if (_ani.pixelsRight(_x,_y,lcd) && _ani.pixelsDown(_x,_y,lcd) == false && _wjl == 0) { //if in air, and by wall to right, wall jump left = 1
adambakerwa 50:9fc8edf722a8 128 _wjl++;
adambakerwa 50:9fc8edf722a8 129 pad.tone(1046.502, 0.1);
adambakerwa 50:9fc8edf722a8 130 }
adambakerwa 50:9fc8edf722a8 131 }
adambakerwa 50:9fc8edf722a8 132 }
adambakerwa 50:9fc8edf722a8 133
adambakerwa 50:9fc8edf722a8 134
adambakerwa 50:9fc8edf722a8 135 //move n pixels up if no collision
adambakerwa 50:9fc8edf722a8 136 void Blockhead::move_up(N5110 &lcd, int n)
adambakerwa 50:9fc8edf722a8 137 {
adambakerwa 50:9fc8edf722a8 138
adambakerwa 50:9fc8edf722a8 139 for(int i = 0; i < n; i++) {
adambakerwa 50:9fc8edf722a8 140 if (_ani.pixelsUp(_x,_y,lcd) == false) {
adambakerwa 50:9fc8edf722a8 141 _y--;
adambakerwa 50:9fc8edf722a8 142 }
adambakerwa 50:9fc8edf722a8 143 }
adambakerwa 50:9fc8edf722a8 144
adambakerwa 50:9fc8edf722a8 145 //printf("_y = %d", _y); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 146 }
adambakerwa 50:9fc8edf722a8 147
adambakerwa 50:9fc8edf722a8 148
adambakerwa 50:9fc8edf722a8 149 //move n pixels down if no collision
adambakerwa 50:9fc8edf722a8 150 void Blockhead::move_down(N5110 &lcd, int n)
adambakerwa 50:9fc8edf722a8 151 {
adambakerwa 50:9fc8edf722a8 152 for(int i = 0; i < n; i++) {
adambakerwa 50:9fc8edf722a8 153 if (_ani.pixelsDown(_x,_y,lcd) == false) {
adambakerwa 50:9fc8edf722a8 154 _y++;
adambakerwa 50:9fc8edf722a8 155 }
adambakerwa 50:9fc8edf722a8 156 }
adambakerwa 50:9fc8edf722a8 157
adambakerwa 50:9fc8edf722a8 158 //printf("_y = %d", _y); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 159 }
adambakerwa 50:9fc8edf722a8 160
adambakerwa 50:9fc8edf722a8 161
adambakerwa 50:9fc8edf722a8 162 //move n pixels right if no collision
adambakerwa 50:9fc8edf722a8 163 void Blockhead::move_right(N5110 &lcd, int n)
adambakerwa 50:9fc8edf722a8 164 {
adambakerwa 50:9fc8edf722a8 165 for(int i = 0; i < n; i++) {
adambakerwa 50:9fc8edf722a8 166 if (_ani.pixelsRight(_x,_y,lcd) == false) {
adambakerwa 50:9fc8edf722a8 167 _x++;
adambakerwa 50:9fc8edf722a8 168 }
adambakerwa 50:9fc8edf722a8 169 }
adambakerwa 50:9fc8edf722a8 170
adambakerwa 50:9fc8edf722a8 171 //printf("_x = %d", _x); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 172 }
adambakerwa 50:9fc8edf722a8 173
adambakerwa 50:9fc8edf722a8 174
adambakerwa 50:9fc8edf722a8 175 //move n pixels left if no collision
adambakerwa 50:9fc8edf722a8 176 void Blockhead::move_left(N5110 &lcd, int n)
adambakerwa 50:9fc8edf722a8 177 {
adambakerwa 50:9fc8edf722a8 178
adambakerwa 50:9fc8edf722a8 179 for(int i = 0; i < n; i++) {
adambakerwa 50:9fc8edf722a8 180 if (_ani.pixelsLeft(_x,_y,lcd) == false) {
adambakerwa 50:9fc8edf722a8 181 _x--;
adambakerwa 50:9fc8edf722a8 182 }
adambakerwa 50:9fc8edf722a8 183 }
adambakerwa 50:9fc8edf722a8 184
adambakerwa 50:9fc8edf722a8 185 //printf("_x = %d", _x); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 186
adambakerwa 50:9fc8edf722a8 187 }
adambakerwa 50:9fc8edf722a8 188
adambakerwa 50:9fc8edf722a8 189
adambakerwa 50:9fc8edf722a8 190 //peforms jump sequence when _jump is 1
adambakerwa 50:9fc8edf722a8 191 void Blockhead::jump(N5110 &lcd)
adambakerwa 50:9fc8edf722a8 192 {
adambakerwa 50:9fc8edf722a8 193
adambakerwa 50:9fc8edf722a8 194 if (_jump <= 4 && _ani.pixelsUp(_x,_y,lcd) == false) { //if nothing above, and jump counter is below 4
adambakerwa 50:9fc8edf722a8 195 if (_jump == 1) { //four pixels per refresh for first two jump increments
adambakerwa 50:9fc8edf722a8 196 _jump++;
adambakerwa 50:9fc8edf722a8 197 move_up(lcd, 4);
adambakerwa 50:9fc8edf722a8 198 } else if (_jump == 2) { // two pixels per refresh for next jump incrmements
adambakerwa 50:9fc8edf722a8 199 _jump++;
adambakerwa 50:9fc8edf722a8 200 move_up(lcd, 2);
adambakerwa 50:9fc8edf722a8 201 } else if (_jump > 2 && _jump <= 4) { // one pixel per refresh for final jump increments
adambakerwa 50:9fc8edf722a8 202 move_up(lcd, 1);
adambakerwa 50:9fc8edf722a8 203 _jump++;
adambakerwa 50:9fc8edf722a8 204 }
adambakerwa 50:9fc8edf722a8 205 } else {
adambakerwa 50:9fc8edf722a8 206 _jump = 0; //jump counter reset to 0 once jump cycle finished or interupted
adambakerwa 50:9fc8edf722a8 207 }
adambakerwa 50:9fc8edf722a8 208
adambakerwa 50:9fc8edf722a8 209 //printf("_jump = %d, _x = %d, _y = d%", _jump, _x, _y); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 210
adambakerwa 50:9fc8edf722a8 211 }
adambakerwa 50:9fc8edf722a8 212
adambakerwa 50:9fc8edf722a8 213
adambakerwa 50:9fc8edf722a8 214 //peforms wall jump right sequence when _wjr = 1
adambakerwa 50:9fc8edf722a8 215 void Blockhead::wall_jump_right(N5110 &lcd, float speed)
adambakerwa 50:9fc8edf722a8 216 {
adambakerwa 50:9fc8edf722a8 217 if (_wjr == 1 && _ani.pixelsUp(_x,_y,lcd) == false) { //if wjr counter == 1 and nothing above
adambakerwa 50:9fc8edf722a8 218 _wjr++;
adambakerwa 50:9fc8edf722a8 219 _wjl = 0; //set wjl counter to 0, so can jump from opposite wall
adambakerwa 50:9fc8edf722a8 220 move_up(lcd, 4); //move four pixels up
adambakerwa 50:9fc8edf722a8 221 if (speed < 0.5f) { //and two pixels right, unless joy stick is driving right anyway
adambakerwa 50:9fc8edf722a8 222 move_right(lcd, 2);
adambakerwa 50:9fc8edf722a8 223 }
adambakerwa 50:9fc8edf722a8 224 } else if (_wjr == 2 && _ani.pixelsUp(_x,_y,lcd) == false) {
adambakerwa 50:9fc8edf722a8 225 _wjr++;
adambakerwa 50:9fc8edf722a8 226 move_up(lcd,2); //move two pixels up
adambakerwa 50:9fc8edf722a8 227 if (speed < 0.5f) { //and a pixel right, unless joy stick is driving right anyway
adambakerwa 50:9fc8edf722a8 228 move_right(lcd, 1);
adambakerwa 50:9fc8edf722a8 229 }
adambakerwa 50:9fc8edf722a8 230 } else if (_wjr > 2 && _wjr <= 4 && _ani.pixelsUp(_x,_y,lcd) == false) {
adambakerwa 50:9fc8edf722a8 231 _wjr++;
adambakerwa 50:9fc8edf722a8 232 move_up(lcd, 1); //move one pixel up
adambakerwa 50:9fc8edf722a8 233 if (speed < 0.5f) { //and a pixel right, unless joy stick is driving right anyway
adambakerwa 50:9fc8edf722a8 234 move_right(lcd, 1);
adambakerwa 50:9fc8edf722a8 235 }
adambakerwa 50:9fc8edf722a8 236 } else if (_ani.pixelsDown(_x,_y,lcd)) {
adambakerwa 50:9fc8edf722a8 237 _wjr = 0; //only reset wall jump count when on ground, or when
adambakerwa 50:9fc8edf722a8 238 } else if (_ani.pixelsUp(_x,_y,lcd)) { //left wall jump activated, so you cant wall jump continuously up one wall.
adambakerwa 50:9fc8edf722a8 239 _wjr = 0; //or when ceiling hit to avoid blockhead sticking
adambakerwa 50:9fc8edf722a8 240 }
adambakerwa 50:9fc8edf722a8 241
adambakerwa 50:9fc8edf722a8 242 //printf("_wjr = %d, _x = %d, _y = d%", _wjr, _x, _y); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 243
adambakerwa 50:9fc8edf722a8 244
adambakerwa 50:9fc8edf722a8 245 }
adambakerwa 50:9fc8edf722a8 246
adambakerwa 50:9fc8edf722a8 247
adambakerwa 50:9fc8edf722a8 248 //peforms wall jump left sequence when _wjl = 1
adambakerwa 50:9fc8edf722a8 249 void Blockhead::wall_jump_left(N5110 &lcd, float speed)
adambakerwa 50:9fc8edf722a8 250 {
adambakerwa 50:9fc8edf722a8 251
adambakerwa 50:9fc8edf722a8 252 if (_wjl == 1 && _ani.pixelsUp(_x,_y,lcd) == false) { //if wjl counter == 1 and nothing above
adambakerwa 50:9fc8edf722a8 253 _wjl++;
adambakerwa 50:9fc8edf722a8 254 _wjr = 0; //set wjr counter to 0, so can jump from opposite wall
adambakerwa 50:9fc8edf722a8 255 move_up(lcd, 4); //move four pixels up
adambakerwa 50:9fc8edf722a8 256 if (speed > -0.5f) { //and two pixels left, unless joy stick is driving left anyway
adambakerwa 50:9fc8edf722a8 257 move_left(lcd, 2);
adambakerwa 50:9fc8edf722a8 258 }
adambakerwa 50:9fc8edf722a8 259 } else if (_wjl == 2 && _ani.pixelsUp(_x,_y,lcd) == false) {
adambakerwa 50:9fc8edf722a8 260 _wjl++;
adambakerwa 50:9fc8edf722a8 261 move_up(lcd, 2); //move two pixels up
adambakerwa 50:9fc8edf722a8 262 if (speed > -0.5f) { //and a pixel left, unless joy stick is driving left anyway
adambakerwa 50:9fc8edf722a8 263 move_left(lcd, 1);
adambakerwa 50:9fc8edf722a8 264 }
adambakerwa 50:9fc8edf722a8 265 } else if (_wjl > 2 && _wjl <= 4 && _ani.pixelsUp(_x,_y,lcd) == false) {
adambakerwa 50:9fc8edf722a8 266 _wjl++;
adambakerwa 50:9fc8edf722a8 267 move_up(lcd, 1); // move one pixel up
adambakerwa 50:9fc8edf722a8 268 if (speed > -0.5f) { //and a pixel left, unless joy stick is driving left anyway
adambakerwa 50:9fc8edf722a8 269 move_left(lcd, 1);
adambakerwa 50:9fc8edf722a8 270 }
adambakerwa 50:9fc8edf722a8 271 } else if (_ani.pixelsDown(_x,_y,lcd)) {
adambakerwa 50:9fc8edf722a8 272 _wjl = 0; //only reset wall jump count when on ground, or when
adambakerwa 50:9fc8edf722a8 273 } else if (_ani.pixelsUp(_x,_y,lcd)) { //right wall jump activated, so you cant wall jump continuously up one wall.
adambakerwa 50:9fc8edf722a8 274 _wjl = 0;
adambakerwa 50:9fc8edf722a8 275 }
adambakerwa 50:9fc8edf722a8 276
adambakerwa 50:9fc8edf722a8 277 //printf("_wjl = %d, _x = %d, _y = d%", _wjl, _x, _y); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 278
adambakerwa 50:9fc8edf722a8 279 }
adambakerwa 50:9fc8edf722a8 280
adambakerwa 50:9fc8edf722a8 281
adambakerwa 50:9fc8edf722a8 282 //peforms fall when NOT in a jump cycle, wall jump cycle, and no ground below.
adambakerwa 50:9fc8edf722a8 283 void Blockhead::fall(N5110 &lcd)
adambakerwa 50:9fc8edf722a8 284 {
adambakerwa 50:9fc8edf722a8 285 if (_jump == 0 && (_wjr == 0 || _wjr == 5) && (_wjl == 0 || _wjl == 5) && _ani.pixelsDown(_x,_y,lcd) == false) {
adambakerwa 50:9fc8edf722a8 286 if (_fall == 0) {
adambakerwa 50:9fc8edf722a8 287 move_down(lcd, 1); //one pixel down per refresh to start
adambakerwa 50:9fc8edf722a8 288 _fall++;
adambakerwa 50:9fc8edf722a8 289 } else if (_fall == 1) {
adambakerwa 50:9fc8edf722a8 290 _fall++;
adambakerwa 50:9fc8edf722a8 291 move_down(lcd, 2); //then two pixels down per refresh
adambakerwa 50:9fc8edf722a8 292 } else if (_fall == 2) {
adambakerwa 50:9fc8edf722a8 293 _fall++;
adambakerwa 50:9fc8edf722a8 294 move_down(lcd, 3); //then three..
adambakerwa 50:9fc8edf722a8 295 } else if (_fall >= 3) {
adambakerwa 50:9fc8edf722a8 296 _fall++;
adambakerwa 50:9fc8edf722a8 297 move_down(lcd, 4); //then four pixels per fresh (Maximum velocity!)
adambakerwa 50:9fc8edf722a8 298 }
adambakerwa 50:9fc8edf722a8 299 } else {
adambakerwa 50:9fc8edf722a8 300 _fall = 0; //rest fall counter when no longer falling
adambakerwa 50:9fc8edf722a8 301
adambakerwa 50:9fc8edf722a8 302 }
adambakerwa 50:9fc8edf722a8 303
adambakerwa 50:9fc8edf722a8 304 //printf("_fall = %d, _x = %d, _y = d%", _fall, _x, _y); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 305
adambakerwa 50:9fc8edf722a8 306 }
adambakerwa 50:9fc8edf722a8 307
adambakerwa 50:9fc8edf722a8 308
adambakerwa 50:9fc8edf722a8 309 //gets direction from joystick, and returns as speed
adambakerwa 50:9fc8edf722a8 310 float Blockhead::get_speed(Gamepad &pad)
adambakerwa 50:9fc8edf722a8 311 {
adambakerwa 50:9fc8edf722a8 312
adambakerwa 50:9fc8edf722a8 313 Vector2D coord = pad.get_coord();
adambakerwa 50:9fc8edf722a8 314 float speed = coord.x; //set speed to the cordinates of the joystick's x value
adambakerwa 50:9fc8edf722a8 315
adambakerwa 50:9fc8edf722a8 316 return speed;
adambakerwa 50:9fc8edf722a8 317
adambakerwa 50:9fc8edf722a8 318 //printf("speed = %d, _x = %d, _y = d%", speed); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 319 }
adambakerwa 50:9fc8edf722a8 320
adambakerwa 50:9fc8edf722a8 321
adambakerwa 50:9fc8edf722a8 322 //moves blockhead right according to speed
adambakerwa 50:9fc8edf722a8 323 void Blockhead::run_right(N5110 &lcd, float speed)
adambakerwa 50:9fc8edf722a8 324 {
adambakerwa 50:9fc8edf722a8 325 if (_ani.pixelsRight(_x,_y,lcd) == false && (_wjl == 0 || _wjl == 5)) { //run right if no obstical
adambakerwa 50:9fc8edf722a8 326 if (speed > 0.1f && speed <= 0.25f) { //depending on speed, move...
adambakerwa 50:9fc8edf722a8 327 move_right(lcd, 1); //1 pixel right
adambakerwa 50:9fc8edf722a8 328 } else if (speed > 0.25f && speed <= 0.5f) {
adambakerwa 50:9fc8edf722a8 329 move_right(lcd, 2); //2 pixels right
adambakerwa 50:9fc8edf722a8 330 } else if (speed > 0.5f && speed <= 0.75f) {
adambakerwa 50:9fc8edf722a8 331 move_right(lcd, 3); //3 pixels right
adambakerwa 50:9fc8edf722a8 332 } else if (speed > 0.75f) {
adambakerwa 50:9fc8edf722a8 333 move_right(lcd, 4); //4 pixels right
adambakerwa 50:9fc8edf722a8 334 _sprintright++;
adambakerwa 50:9fc8edf722a8 335 if (_sprintright > 20) { //if at top speed for more than 20 cycles, sprint! (6 pix per refresh);
adambakerwa 50:9fc8edf722a8 336 move_right(lcd, 2);
adambakerwa 50:9fc8edf722a8 337 }
adambakerwa 50:9fc8edf722a8 338 }
adambakerwa 50:9fc8edf722a8 339 }
adambakerwa 50:9fc8edf722a8 340
adambakerwa 50:9fc8edf722a8 341 //printf("speed = %d, _x = %d, _y = d%", speed, _x, _y); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 342
adambakerwa 50:9fc8edf722a8 343 }
adambakerwa 50:9fc8edf722a8 344
adambakerwa 50:9fc8edf722a8 345
adambakerwa 50:9fc8edf722a8 346 //moves blockhead left according to speed
adambakerwa 50:9fc8edf722a8 347 void Blockhead::run_left(N5110 &lcd, float speed)
adambakerwa 50:9fc8edf722a8 348 {
adambakerwa 50:9fc8edf722a8 349
adambakerwa 50:9fc8edf722a8 350
adambakerwa 50:9fc8edf722a8 351 if (_ani.pixelsLeft(_x,_y,lcd) == false && (_wjr == 0 || _wjr == 5)) { //run left if no obstical
adambakerwa 50:9fc8edf722a8 352 if (speed < -0.1f && speed >= -0.25f) { //depending on speed move..
adambakerwa 50:9fc8edf722a8 353 move_left(lcd, 1); //1 pixel left
adambakerwa 50:9fc8edf722a8 354 } else if (speed < -0.25f && speed >= -0.5f) {
adambakerwa 50:9fc8edf722a8 355 move_left(lcd, 2); //2 pixels right
adambakerwa 50:9fc8edf722a8 356 } else if (speed < -0.5f && speed >= -0.75f) {
adambakerwa 50:9fc8edf722a8 357 move_left(lcd, 3); //3 pixels right
adambakerwa 50:9fc8edf722a8 358 } else if (speed < -0.75f) {
adambakerwa 50:9fc8edf722a8 359 move_left(lcd, 4); //4 pixels right
adambakerwa 50:9fc8edf722a8 360 _sprintleft++;
adambakerwa 50:9fc8edf722a8 361 if (_sprintleft > 20) { //if at top speed for more than 20 cycles, sprint!
adambakerwa 50:9fc8edf722a8 362 move_left(lcd, 2);
adambakerwa 50:9fc8edf722a8 363 }
adambakerwa 50:9fc8edf722a8 364
adambakerwa 50:9fc8edf722a8 365 }
adambakerwa 50:9fc8edf722a8 366 }
adambakerwa 50:9fc8edf722a8 367
adambakerwa 50:9fc8edf722a8 368 //printf("speed = %d, _x = %d, _y = d%", speed, _x, _y); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 369
adambakerwa 50:9fc8edf722a8 370 }
adambakerwa 50:9fc8edf722a8 371
adambakerwa 50:9fc8edf722a8 372
adambakerwa 50:9fc8edf722a8 373 //restets sprint incrment if collision or joystick idle
adambakerwa 50:9fc8edf722a8 374 void Blockhead::cancel_sprint(N5110 &lcd, float speed)
adambakerwa 50:9fc8edf722a8 375 {
adambakerwa 50:9fc8edf722a8 376
adambakerwa 50:9fc8edf722a8 377 if (speed < 0.5f || _ani.pixelsRight(_x,_y,lcd) ) {
adambakerwa 50:9fc8edf722a8 378 _sprintright = 0; //if collision or speed drops below 0.5 cancell sprint
adambakerwa 50:9fc8edf722a8 379 }
adambakerwa 50:9fc8edf722a8 380
adambakerwa 50:9fc8edf722a8 381 if (speed > -0.5f || _ani.pixelsLeft(_x,_y,lcd) ) {
adambakerwa 50:9fc8edf722a8 382 _sprintleft = 0; //if collision or speed drops below 0.5 cancell sprint
adambakerwa 50:9fc8edf722a8 383 }
adambakerwa 50:9fc8edf722a8 384
adambakerwa 50:9fc8edf722a8 385 //printf("_sprintleft = %d, _sprintright = %d", _jump; //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 386
adambakerwa 50:9fc8edf722a8 387 }
adambakerwa 50:9fc8edf722a8 388
adambakerwa 50:9fc8edf722a8 389 //runs blockhead's alive sequnce untill _death flag turns to one (as a result of death)
adambakerwa 50:9fc8edf722a8 390 void Blockhead::runner_state(N5110 &lcd, Gamepad &pad, float speed)
adambakerwa 50:9fc8edf722a8 391 {
adambakerwa 50:9fc8edf722a8 392
adambakerwa 50:9fc8edf722a8 393 if (_death == 0) {
adambakerwa 50:9fc8edf722a8 394 alive_sequence(lcd, speed); //whilst game over flag is 0, runs alive sequence animation
adambakerwa 50:9fc8edf722a8 395 } else {
adambakerwa 50:9fc8edf722a8 396 death_sequence(lcd, pad); //when game over flag turns 1, run death sequence animation)
adambakerwa 50:9fc8edf722a8 397 }
adambakerwa 50:9fc8edf722a8 398
adambakerwa 50:9fc8edf722a8 399
adambakerwa 50:9fc8edf722a8 400
adambakerwa 50:9fc8edf722a8 401 }
adambakerwa 50:9fc8edf722a8 402
adambakerwa 50:9fc8edf722a8 403
adambakerwa 50:9fc8edf722a8 404 //displays the correct animation depending on runner state (for example when moving slowly walking animation is displayed)
adambakerwa 50:9fc8edf722a8 405 void Blockhead::alive_sequence(N5110 &lcd, float _speed)
adambakerwa 50:9fc8edf722a8 406 {
adambakerwa 50:9fc8edf722a8 407 if (_ani.pixelsRight(_x, _y, lcd) && (_fall > 0 || _jump > 0 ) && (_d3 != 3 && _d4 !=3)) { //if by right wall in air,
adambakerwa 50:9fc8edf722a8 408 _ani.wallclingRight(_x, _y, lcd); //display wall cling right spite
adambakerwa 50:9fc8edf722a8 409 } else if (_ani.pixelsLeft(_x, _y, lcd) && (_fall > 0 || _jump > 0 ) && (_d3 != 3 && _d4 !=3)) { //if by left wall in air,
adambakerwa 50:9fc8edf722a8 410 _ani.wallclingLeft(_x, _y, lcd); //display wall cling left sprite
adambakerwa 50:9fc8edf722a8 411 } else if ( ( (_wjr > 0 && _wjr < 5) || (_speed >= 0.1f && (_fall > 0 || _jump > 0)) ) && (_d3 != 3 && _d4 != 3) ) { //if falling right,
adambakerwa 50:9fc8edf722a8 412 _ani.fallingRight(_x, _y, lcd); //display falling left sprite
adambakerwa 50:9fc8edf722a8 413 } else if ( ( (_wjl > 0 && _wjl < 5) || (_speed < -0.1f && (_fall > 0 || _jump > 0 )) ) && (_d3 != 3 && _d4 != 3) ) { //if fallig left,
adambakerwa 50:9fc8edf722a8 414 _ani.fallingLeft(_x, _y, lcd); //display falling left sprite
adambakerwa 50:9fc8edf722a8 415 } else if ( (_wjr ==9 || _fall > 0 || _jump > 0 ) && (_d3 != 3 && _d4 !=3) ) { //if falling,
adambakerwa 50:9fc8edf722a8 416 _ani.falling(_x, _y, lcd); //display falling sprite
adambakerwa 50:9fc8edf722a8 417 } else if (_speed > 0.5f) { //if speed is more than 0.5
adambakerwa 50:9fc8edf722a8 418 run_sequence_right(lcd); //peform run right animation
adambakerwa 50:9fc8edf722a8 419 } else if (_speed > 0.1f) { //if only more than 0
adambakerwa 50:9fc8edf722a8 420 walk_sequence_right(lcd); //peform walk right animation
adambakerwa 50:9fc8edf722a8 421 } else if (_speed < -0.5f) { //if speed less than -0.5
adambakerwa 50:9fc8edf722a8 422 run_sequence_left(lcd); //peform run left animation
adambakerwa 50:9fc8edf722a8 423 } else if (_speed < -0.1f) { //if only less than 0
adambakerwa 50:9fc8edf722a8 424 walk_sequence_left(lcd); //peform walk left animation
adambakerwa 50:9fc8edf722a8 425 } else { //if none of the above
adambakerwa 50:9fc8edf722a8 426 _ani.standing(_x, _y, lcd); //display standing sprite!
adambakerwa 50:9fc8edf722a8 427 }
adambakerwa 50:9fc8edf722a8 428
adambakerwa 50:9fc8edf722a8 429
adambakerwa 50:9fc8edf722a8 430 }
adambakerwa 50:9fc8edf722a8 431
adambakerwa 50:9fc8edf722a8 432
adambakerwa 50:9fc8edf722a8 433 //displays running animation (right)
adambakerwa 50:9fc8edf722a8 434 void Blockhead::run_sequence_right(N5110 &lcd)
adambakerwa 50:9fc8edf722a8 435 {
adambakerwa 50:9fc8edf722a8 436 _runani++;
adambakerwa 50:9fc8edf722a8 437 if (_runani == 1) { //when running right, cr alterntes between 1 and 2,
adambakerwa 50:9fc8edf722a8 438 _ani.runRightOne(_x, _y, lcd); //displaying the run right sprites consecutively thus creating a running animation
adambakerwa 50:9fc8edf722a8 439 } else if (_runani == 2) {
adambakerwa 50:9fc8edf722a8 440 _ani.runRightTwo(_x, _y, lcd);
adambakerwa 50:9fc8edf722a8 441 _runani = 0;
adambakerwa 50:9fc8edf722a8 442 }
adambakerwa 50:9fc8edf722a8 443
adambakerwa 50:9fc8edf722a8 444
adambakerwa 50:9fc8edf722a8 445
adambakerwa 50:9fc8edf722a8 446 }
adambakerwa 50:9fc8edf722a8 447
adambakerwa 50:9fc8edf722a8 448
adambakerwa 50:9fc8edf722a8 449 //displays running animation (left)
adambakerwa 50:9fc8edf722a8 450 void Blockhead::run_sequence_left(N5110 &lcd)
adambakerwa 50:9fc8edf722a8 451 {
adambakerwa 50:9fc8edf722a8 452 _runani++;
adambakerwa 50:9fc8edf722a8 453 if (_runani == 1) { //when running left, cr alterntes between 1 and 2,
adambakerwa 50:9fc8edf722a8 454 _ani.runLeftOne(_x, _y, lcd); //displaying the run left sprites consecutively thus creating a running animation
adambakerwa 50:9fc8edf722a8 455 } else if (_runani == 2) {
adambakerwa 50:9fc8edf722a8 456 _ani.runLeftTwo(_x, _y, lcd);
adambakerwa 50:9fc8edf722a8 457 _runani = 0;
adambakerwa 50:9fc8edf722a8 458 }
adambakerwa 50:9fc8edf722a8 459
adambakerwa 50:9fc8edf722a8 460
adambakerwa 50:9fc8edf722a8 461
adambakerwa 50:9fc8edf722a8 462 }
adambakerwa 50:9fc8edf722a8 463
adambakerwa 50:9fc8edf722a8 464
adambakerwa 50:9fc8edf722a8 465 //displays walking animation (right)
adambakerwa 50:9fc8edf722a8 466 void Blockhead::walk_sequence_right(N5110 &lcd)
adambakerwa 50:9fc8edf722a8 467 {
adambakerwa 50:9fc8edf722a8 468 _walkani++;
adambakerwa 50:9fc8edf722a8 469 if (_walkani == 1) {
adambakerwa 50:9fc8edf722a8 470 _ani.walkRightOne(_x, _y, lcd); //when walking right, cw runs between 1 2 3 4,
adambakerwa 50:9fc8edf722a8 471 } else if (_walkani == 2) { //displaying the walk right sprites consecutively thus creating a walking animation
adambakerwa 50:9fc8edf722a8 472 _ani.walkRightTwo(_x, _y, lcd);
adambakerwa 50:9fc8edf722a8 473 } else if (_walkani == 3) {
adambakerwa 50:9fc8edf722a8 474 _ani.walkRightThree(_x, _y, lcd);
adambakerwa 50:9fc8edf722a8 475 } else if (_walkani == 4) {
adambakerwa 50:9fc8edf722a8 476 _ani.walkRightFour(_x, _y, lcd);
adambakerwa 50:9fc8edf722a8 477 _walkani = 0;
adambakerwa 50:9fc8edf722a8 478 }
adambakerwa 50:9fc8edf722a8 479
adambakerwa 50:9fc8edf722a8 480
adambakerwa 50:9fc8edf722a8 481 }
adambakerwa 50:9fc8edf722a8 482
adambakerwa 50:9fc8edf722a8 483
adambakerwa 50:9fc8edf722a8 484 //displays walking animation (left)
adambakerwa 50:9fc8edf722a8 485 void Blockhead::walk_sequence_left(N5110 &lcd)
adambakerwa 50:9fc8edf722a8 486 {
adambakerwa 50:9fc8edf722a8 487 _walkani++;
adambakerwa 50:9fc8edf722a8 488 if (_walkani == 1) { //when walking left, cw runs between 1 2 3 4,
adambakerwa 50:9fc8edf722a8 489 _ani.walkLeftOne(_x, _y, lcd); //displaying the walk right sprites consecutively thus creating a walking animation
adambakerwa 50:9fc8edf722a8 490 } else if (_walkani == 2) {
adambakerwa 50:9fc8edf722a8 491 _ani.walkLeftTwo(_x, _y, lcd);
adambakerwa 50:9fc8edf722a8 492 } else if (_walkani == 3) {
adambakerwa 50:9fc8edf722a8 493 _ani.walkLeftThree(_x, _y, lcd);
adambakerwa 50:9fc8edf722a8 494 } else if (_walkani == 4) {
adambakerwa 50:9fc8edf722a8 495 _ani.walkLeftFour(_x, _y, lcd);
adambakerwa 50:9fc8edf722a8 496 _walkani = 0;
adambakerwa 50:9fc8edf722a8 497 }
adambakerwa 50:9fc8edf722a8 498
adambakerwa 50:9fc8edf722a8 499
adambakerwa 50:9fc8edf722a8 500 }
adambakerwa 50:9fc8edf722a8 501
adambakerwa 50:9fc8edf722a8 502
adambakerwa 50:9fc8edf722a8 503 //displays death animation
adambakerwa 50:9fc8edf722a8 504 void Blockhead::death_sequence(N5110 &lcd, Gamepad &pad)
adambakerwa 50:9fc8edf722a8 505 {
adambakerwa 50:9fc8edf722a8 506
adambakerwa 50:9fc8edf722a8 507 if (_death == 1) {
adambakerwa 50:9fc8edf722a8 508 _ani.deathOne(_x,_y,lcd); //when cd activated by gameover, run death sequence animation
adambakerwa 50:9fc8edf722a8 509 pad.tone(261.62, 0.1); //c3 //a tone is played each fram, creating a disonant tune along with the animation
adambakerwa 50:9fc8edf722a8 510 } else if (_death == 2) {
adambakerwa 50:9fc8edf722a8 511 _ani.deathTwo(_x,_y,lcd);
adambakerwa 50:9fc8edf722a8 512 pad.tone(97.999, 0.1); //g2
adambakerwa 50:9fc8edf722a8 513 } else if (_death == 3) {
adambakerwa 50:9fc8edf722a8 514 _ani.deathThree(_x,_y,lcd);
adambakerwa 50:9fc8edf722a8 515 pad.tone(207.652, 0.1); //g1#
adambakerwa 50:9fc8edf722a8 516 } else if (_death == 4) {
adambakerwa 50:9fc8edf722a8 517 _ani.deathFour(_x,_y,lcd);
adambakerwa 50:9fc8edf722a8 518 pad.tone(155.563, 0.1); //d1#
adambakerwa 50:9fc8edf722a8 519 }
adambakerwa 50:9fc8edf722a8 520 _death++;
adambakerwa 50:9fc8edf722a8 521
adambakerwa 50:9fc8edf722a8 522
adambakerwa 50:9fc8edf722a8 523 }
adambakerwa 50:9fc8edf722a8 524
adambakerwa 50:9fc8edf722a8 525
adambakerwa 50:9fc8edf722a8 526 //changes level when either side of screen
adambakerwa 50:9fc8edf722a8 527 int Blockhead::next_level()
adambakerwa 50:9fc8edf722a8 528 {
adambakerwa 50:9fc8edf722a8 529 if (_x > 76) {
adambakerwa 50:9fc8edf722a8 530 _x = -1; //when blockhead goes off right side of screen,
adambakerwa 50:9fc8edf722a8 531 _level++; //level increments, and blockhead appears at left side
adambakerwa 50:9fc8edf722a8 532 } else if (_x < -1) {
adambakerwa 50:9fc8edf722a8 533 _x = 76; //when blockhead goes off left side of screen,
adambakerwa 50:9fc8edf722a8 534 _level--; //level deccrements, and block head appears at right side
adambakerwa 50:9fc8edf722a8 535 }
adambakerwa 50:9fc8edf722a8 536
adambakerwa 50:9fc8edf722a8 537 //printf("_level = %d", _level); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 538
adambakerwa 50:9fc8edf722a8 539 return _level;
adambakerwa 50:9fc8edf722a8 540
adambakerwa 50:9fc8edf722a8 541 }
adambakerwa 50:9fc8edf722a8 542
adambakerwa 50:9fc8edf722a8 543
adambakerwa 50:9fc8edf722a8 544 //checks if blockhead is on horizontal platform
adambakerwa 50:9fc8edf722a8 545 int Blockhead::on_hoz_check(Pos pos)
adambakerwa 50:9fc8edf722a8 546 {
adambakerwa 50:9fc8edf722a8 547 int d;
adambakerwa 50:9fc8edf722a8 548 int c = 0;
adambakerwa 50:9fc8edf722a8 549
adambakerwa 50:9fc8edf722a8 550 for (int i = 0; i < pos.l; i++) { //for the entire lenth of moving platform one
adambakerwa 50:9fc8edf722a8 551 if (((_x+2 == pos.x+i) || (_x+6 == pos.x+i)) &&(_y+12 == pos.y)) { //checks if cordinates of horizontal moving platform one,
adambakerwa 50:9fc8edf722a8 552 c++; //are the same as blockheads's underside cordinates, if so c++
adambakerwa 50:9fc8edf722a8 553 }
adambakerwa 50:9fc8edf722a8 554 }
adambakerwa 50:9fc8edf722a8 555 if (c > 0) { //if c > 0 blockhead is on the moving platform,
adambakerwa 50:9fc8edf722a8 556 d = pos.d; //then d = direction of moving platform (0 = right, 1 - left)
adambakerwa 50:9fc8edf722a8 557 } else { //if not then d = 2 (insignificant number)
adambakerwa 50:9fc8edf722a8 558 d = 2;
adambakerwa 50:9fc8edf722a8 559 }
adambakerwa 50:9fc8edf722a8 560
adambakerwa 50:9fc8edf722a8 561 //printf("d = %d", d); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 562
adambakerwa 50:9fc8edf722a8 563 return d; //d is then used to move blcokhead in the direction of the platform he is on
adambakerwa 50:9fc8edf722a8 564 }
adambakerwa 50:9fc8edf722a8 565
adambakerwa 50:9fc8edf722a8 566
adambakerwa 50:9fc8edf722a8 567 //checks if blockhead is by right of horizontal platform
adambakerwa 50:9fc8edf722a8 568 int Blockhead::by_hoz_check_right(Pos pos)
adambakerwa 50:9fc8edf722a8 569 {
adambakerwa 50:9fc8edf722a8 570 int c = 0;
adambakerwa 50:9fc8edf722a8 571 int d;
adambakerwa 50:9fc8edf722a8 572
adambakerwa 50:9fc8edf722a8 573 for (int i = 0; i < 12; i ++) { //for 12 (height of blockhead)
adambakerwa 50:9fc8edf722a8 574 if ((_x-1 == pos.x + pos.l) && ((_y + i == pos.y) || (_y + i == pos.y+1) || (_y + i == pos.y+2))) { //check if cordinates of right side horizontal moving platform one
adambakerwa 50:9fc8edf722a8 575 c++; //are the same as blockhead's left side
adambakerwa 50:9fc8edf722a8 576 }
adambakerwa 50:9fc8edf722a8 577 }
adambakerwa 50:9fc8edf722a8 578
adambakerwa 50:9fc8edf722a8 579 if (c > 0 && pos.d == 0) { // if c > 0 and the platform is moving right
adambakerwa 50:9fc8edf722a8 580 d = 1; // then d = 1,
adambakerwa 50:9fc8edf722a8 581 } else { // otherwise d = 0 (insignificant number)
adambakerwa 50:9fc8edf722a8 582 d = 0;
adambakerwa 50:9fc8edf722a8 583 }
adambakerwa 50:9fc8edf722a8 584
adambakerwa 50:9fc8edf722a8 585 //printf("d = %d", d); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 586
adambakerwa 50:9fc8edf722a8 587 return d; //d is then used to move blockhead in the direction the platform is pushing against him
adambakerwa 50:9fc8edf722a8 588 }
adambakerwa 50:9fc8edf722a8 589
adambakerwa 50:9fc8edf722a8 590
adambakerwa 50:9fc8edf722a8 591 //checks if blockhead is by left of horizontal platform
adambakerwa 50:9fc8edf722a8 592 int Blockhead::by_hoz_check_left(Pos pos)
adambakerwa 50:9fc8edf722a8 593 {
adambakerwa 50:9fc8edf722a8 594 int c = 0;
adambakerwa 50:9fc8edf722a8 595 int d;
adambakerwa 50:9fc8edf722a8 596
adambakerwa 50:9fc8edf722a8 597 for (int i = 0; i < 12; i ++) { //for 12 (height of blockhead)
adambakerwa 50:9fc8edf722a8 598 if ((_x+9 == pos.x) && ((_y + i == pos.y) || (_y + i == pos.y+1) || (_y + i == pos.y+2))) { //check if cordinates of left side horizontal moving platform one
adambakerwa 50:9fc8edf722a8 599 c++; //are the same as blockhead's right side
adambakerwa 50:9fc8edf722a8 600 }
adambakerwa 50:9fc8edf722a8 601 }
adambakerwa 50:9fc8edf722a8 602
adambakerwa 50:9fc8edf722a8 603 if (c > 0 && pos.d == 1) { //if c > 0 and the platform is moving right
adambakerwa 50:9fc8edf722a8 604 d = 1; //then d = 1,
adambakerwa 50:9fc8edf722a8 605 } else { //otherwise d = 0 (insignificant number)
adambakerwa 50:9fc8edf722a8 606 d = 0;
adambakerwa 50:9fc8edf722a8 607 }
adambakerwa 50:9fc8edf722a8 608
adambakerwa 50:9fc8edf722a8 609 //printf("d = %d", d); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 610
adambakerwa 50:9fc8edf722a8 611 return d; //d is then used to move blockhead in the dicrection the platform is pushing against him
adambakerwa 50:9fc8edf722a8 612 }
adambakerwa 50:9fc8edf722a8 613
adambakerwa 50:9fc8edf722a8 614
adambakerwa 50:9fc8edf722a8 615 //checks if blockhead is on horizontal platform (2)
adambakerwa 50:9fc8edf722a8 616 int Blockhead::on_hoz_2_check(Pos pos)
adambakerwa 50:9fc8edf722a8 617 {
adambakerwa 50:9fc8edf722a8 618 int d;
adambakerwa 50:9fc8edf722a8 619 int c = 0;
adambakerwa 50:9fc8edf722a8 620
adambakerwa 50:9fc8edf722a8 621 for (int i = 0; i < pos.l2; i++) {
adambakerwa 50:9fc8edf722a8 622 if (((_x+2 == pos.x2+i) || (_x+6 == pos.x2+i)) &&(_y+12 == pos.y2)) { //for the entire lenth of moving platform one
adambakerwa 50:9fc8edf722a8 623 c++; //checks if cordinates of horizontal moving platform one,
adambakerwa 50:9fc8edf722a8 624 } //are the same as blockheads's underside cordinates, if so c++
adambakerwa 50:9fc8edf722a8 625 }
adambakerwa 50:9fc8edf722a8 626 if (c > 0) {
adambakerwa 50:9fc8edf722a8 627 d = pos.d2; //if c > 0 blockhead is on the moving platform,
adambakerwa 50:9fc8edf722a8 628 } else { //then d = direction of moving platform (0 = right, 1 - left)
adambakerwa 50:9fc8edf722a8 629 d = 2; //if not then d = 2 (insignificant number)
adambakerwa 50:9fc8edf722a8 630 }
adambakerwa 50:9fc8edf722a8 631
adambakerwa 50:9fc8edf722a8 632 //printf("d = %d", d); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 633
adambakerwa 50:9fc8edf722a8 634 return d; //d is then used to move blcokhead in the direction of the platform he is on
adambakerwa 50:9fc8edf722a8 635 }
adambakerwa 50:9fc8edf722a8 636
adambakerwa 50:9fc8edf722a8 637
adambakerwa 50:9fc8edf722a8 638 //checks if blockhead is by right of horizontal platform (2)
adambakerwa 50:9fc8edf722a8 639 int Blockhead::by_hoz_2_check_right(Pos pos)
adambakerwa 50:9fc8edf722a8 640 {
adambakerwa 50:9fc8edf722a8 641 int c = 0;
adambakerwa 50:9fc8edf722a8 642 int d;
adambakerwa 50:9fc8edf722a8 643
adambakerwa 50:9fc8edf722a8 644 for (int i = 0; i < 12; i ++) { //for 12 (height of blockhead)
adambakerwa 50:9fc8edf722a8 645 if ((_x-1 == pos.x2 + pos.l2) && ((_y+i == pos.y2) || (_y+i == pos.y2+1) || (_y + i == pos.y2+2))) { //check if cordinates of right side horizontal moving platform one
adambakerwa 50:9fc8edf722a8 646 c++; //are the same as blockhead's left side
adambakerwa 50:9fc8edf722a8 647 }
adambakerwa 50:9fc8edf722a8 648 }
adambakerwa 50:9fc8edf722a8 649 //if c > 0 and the platform is moving right
adambakerwa 50:9fc8edf722a8 650 if (c > 0 && pos.d2 == 0) { //then d = 1,
adambakerwa 50:9fc8edf722a8 651 d = 1; //otherwise d = 0 (insignificant number)
adambakerwa 50:9fc8edf722a8 652 } else {
adambakerwa 50:9fc8edf722a8 653 d = 0;
adambakerwa 50:9fc8edf722a8 654 }
adambakerwa 50:9fc8edf722a8 655
adambakerwa 50:9fc8edf722a8 656 //printf("d = %d", d); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 657
adambakerwa 50:9fc8edf722a8 658 return d; //d is then used to move blockhead in the direction the platform is pushing against him
adambakerwa 50:9fc8edf722a8 659 }
adambakerwa 50:9fc8edf722a8 660
adambakerwa 50:9fc8edf722a8 661
adambakerwa 50:9fc8edf722a8 662 //checks if blockhead is by left of horizontal platform (2)
adambakerwa 50:9fc8edf722a8 663 int Blockhead::by_hoz_2_check_left(Pos pos)
adambakerwa 50:9fc8edf722a8 664 {
adambakerwa 50:9fc8edf722a8 665 int c = 0;
adambakerwa 50:9fc8edf722a8 666 int d;
adambakerwa 50:9fc8edf722a8 667
adambakerwa 50:9fc8edf722a8 668 for (int i = 0; i < 12; i ++) { //for 12 (height of blockhead)
adambakerwa 50:9fc8edf722a8 669 if ((_x+9 == pos.x2) && ((_y + i == pos.y2) || (_y + i == pos.y2+1) || (_y + i == pos.y2+2))) { //check if cordinates of left side horizontal moving platform one
adambakerwa 50:9fc8edf722a8 670 c++; //are the same as blockhead's right side
adambakerwa 50:9fc8edf722a8 671 }
adambakerwa 50:9fc8edf722a8 672 }
adambakerwa 50:9fc8edf722a8 673
adambakerwa 50:9fc8edf722a8 674 if (c > 0 && pos.d2 == 1) { //if c > 0 and the platform is moving right
adambakerwa 50:9fc8edf722a8 675 d = 1; //then d = 1,
adambakerwa 50:9fc8edf722a8 676 } else { //otherwise d = 0 (insignificant number)
adambakerwa 50:9fc8edf722a8 677 d = 0;
adambakerwa 50:9fc8edf722a8 678 }
adambakerwa 50:9fc8edf722a8 679
adambakerwa 50:9fc8edf722a8 680 //printf("d = %d", d); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 681
adambakerwa 50:9fc8edf722a8 682 return d; //d is then used to move blockhead in the dicrection the platform is pushing against him
adambakerwa 50:9fc8edf722a8 683 }
adambakerwa 50:9fc8edf722a8 684
adambakerwa 50:9fc8edf722a8 685
adambakerwa 50:9fc8edf722a8 686 //check is blockhead is on vertical moving platform
adambakerwa 50:9fc8edf722a8 687 int Blockhead::on_ver_check(Pos pos) // add the _x part..
adambakerwa 50:9fc8edf722a8 688 {
adambakerwa 50:9fc8edf722a8 689 int d;
adambakerwa 50:9fc8edf722a8 690 int c = 0;
adambakerwa 50:9fc8edf722a8 691
adambakerwa 50:9fc8edf722a8 692 for (int i = 0; i < pos.vl+1; i++) { //for width of vertical moving platform
adambakerwa 50:9fc8edf722a8 693 if ((_y+11 == pos.vy-1) && ((_x == pos.vx+i) || (_x+1 == pos.vx+i) || (_x+2 == pos.vx+i) || (_x+6 == pos.vx+i) || (_x+7 == pos.vx+i) || (_x+8 == pos.vx+i))) { //check if cordinates of top of vertical moving platform,
adambakerwa 50:9fc8edf722a8 694 c++; //are the same as blockheads underside
adambakerwa 50:9fc8edf722a8 695 }
adambakerwa 50:9fc8edf722a8 696 }
adambakerwa 50:9fc8edf722a8 697
adambakerwa 50:9fc8edf722a8 698 if (c > 0) { //if c > 0 blockhead is on the moving platform,
adambakerwa 50:9fc8edf722a8 699 d = pos.vd+3; //3 = down 4 = up //then d = direction of moving platform (3 = down, 4 = up)
adambakerwa 50:9fc8edf722a8 700 } else { //if not then d = 2 (insignificant number)
adambakerwa 50:9fc8edf722a8 701 d = 2; //not moving
adambakerwa 50:9fc8edf722a8 702 }
adambakerwa 50:9fc8edf722a8 703
adambakerwa 50:9fc8edf722a8 704 //printf("d = %d", d); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 705
adambakerwa 50:9fc8edf722a8 706 return d;
adambakerwa 50:9fc8edf722a8 707 }
adambakerwa 50:9fc8edf722a8 708
adambakerwa 50:9fc8edf722a8 709
adambakerwa 50:9fc8edf722a8 710 //check is blockhead is on vertical moving platform (2)
adambakerwa 50:9fc8edf722a8 711 int Blockhead::on_ver_2_check(Pos pos)
adambakerwa 50:9fc8edf722a8 712 {
adambakerwa 50:9fc8edf722a8 713 int d;
adambakerwa 50:9fc8edf722a8 714 int c = 0;
adambakerwa 50:9fc8edf722a8 715
adambakerwa 50:9fc8edf722a8 716 for (int i = 0; i < pos.vl2+1; i++) { //for width of vertical moving platform
adambakerwa 50:9fc8edf722a8 717 if ((_y+11 == pos.vy2-1) && ((_x == pos.vx2+i) || (_x+1 == pos.vx2+i) || (_x+2 == pos.vx2+i) || (_x+6 == pos.vx2+i) || (_x+7 == pos.vx2+i) || (_x+8 == pos.vx2+i)) ) { //check if cordinates of top of vertical moving platform
adambakerwa 50:9fc8edf722a8 718 c++; //are the same as blockheads underside
adambakerwa 50:9fc8edf722a8 719 }
adambakerwa 50:9fc8edf722a8 720 }
adambakerwa 50:9fc8edf722a8 721
adambakerwa 50:9fc8edf722a8 722 if (c > 0) { //if c > 0 blockhead is on the moving platform,
adambakerwa 50:9fc8edf722a8 723 d = pos.vd2+3; //3 = down 4 = up //then d = direction of moving platform (3 = down, 4 = up)
adambakerwa 50:9fc8edf722a8 724 } else { //if not then d = 2 (insignificant number)
adambakerwa 50:9fc8edf722a8 725 d = 2; //not moving
adambakerwa 50:9fc8edf722a8 726 }
adambakerwa 50:9fc8edf722a8 727
adambakerwa 50:9fc8edf722a8 728 //printf("d = %d", d); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 729
adambakerwa 50:9fc8edf722a8 730 return d;
adambakerwa 50:9fc8edf722a8 731 }
adambakerwa 50:9fc8edf722a8 732
adambakerwa 50:9fc8edf722a8 733
adambakerwa 50:9fc8edf722a8 734 //checks if blockhead is being crushed by vertical moving platform
adambakerwa 50:9fc8edf722a8 735 int Blockhead::crushed_by_ver(Pos pos)
adambakerwa 50:9fc8edf722a8 736 {
adambakerwa 50:9fc8edf722a8 737 int c = 0;
adambakerwa 50:9fc8edf722a8 738 int g = 0;
adambakerwa 50:9fc8edf722a8 739
adambakerwa 50:9fc8edf722a8 740 for (int a = 0; a < 9; a++) { //for the height of blockhead,
adambakerwa 50:9fc8edf722a8 741 for (int i = 0; i < pos.vl+1; i++) { //and the width of the vertical moving platform,
adambakerwa 50:9fc8edf722a8 742 if ((_y+10-a == pos.vy-1) && ((_x+2 == pos.vx + i) || (_x+6 == pos.vx + i)) ) { //check if the cordinates of width of vertical moving platform
adambakerwa 50:9fc8edf722a8 743 c++; //are the same as blockehads, starting from bottom -1 and up.
adambakerwa 50:9fc8edf722a8 744 }
adambakerwa 50:9fc8edf722a8 745 }
adambakerwa 50:9fc8edf722a8 746 }
adambakerwa 50:9fc8edf722a8 747
adambakerwa 50:9fc8edf722a8 748 for (int a = 0; a < 9; a++) { //for the height of blockhead
adambakerwa 50:9fc8edf722a8 749 for (int i = 0; i < pos.vl+1; i++) { //and the width of the vertical moving platform
adambakerwa 50:9fc8edf722a8 750 if ((_y+a == pos.vy+pos.vh) && ((_x+2 == pos.vx + i) || (_x+6 == pos.vx + i)) ) { //check if the cordinates of width of vertical moving platform
adambakerwa 50:9fc8edf722a8 751 c++; //are the same as blockhead's, starting from top -1, and down.
adambakerwa 50:9fc8edf722a8 752 }
adambakerwa 50:9fc8edf722a8 753 }
adambakerwa 50:9fc8edf722a8 754 }
adambakerwa 50:9fc8edf722a8 755
adambakerwa 50:9fc8edf722a8 756 if (c > 0) { //if so, g = 1 .. this means that blockhead his being crushed
adambakerwa 50:9fc8edf722a8 757 g = 1;
adambakerwa 50:9fc8edf722a8 758 } else {
adambakerwa 50:9fc8edf722a8 759 g = 0;
adambakerwa 50:9fc8edf722a8 760 }
adambakerwa 50:9fc8edf722a8 761
adambakerwa 50:9fc8edf722a8 762 //printf("g = %d", g); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 763
adambakerwa 50:9fc8edf722a8 764 return g;
adambakerwa 50:9fc8edf722a8 765 }
adambakerwa 50:9fc8edf722a8 766
adambakerwa 50:9fc8edf722a8 767
adambakerwa 50:9fc8edf722a8 768 //checks if blockhead is being crushed by vertical moving platform (2)
adambakerwa 50:9fc8edf722a8 769 int Blockhead::crushed_by_ver_2(Pos pos)
adambakerwa 50:9fc8edf722a8 770 {
adambakerwa 50:9fc8edf722a8 771 int c = 0;
adambakerwa 50:9fc8edf722a8 772 int g = 0;
adambakerwa 50:9fc8edf722a8 773
adambakerwa 50:9fc8edf722a8 774 for (int a = 0; a < 9; a++) { //for the height of blockhead,
adambakerwa 50:9fc8edf722a8 775 for (int i = 0; i < pos.vl2+1; i++) { //and the width of the vertical moving platform two,
adambakerwa 50:9fc8edf722a8 776 if ((_y+10-a == pos.vy2-1) && ((_x+2 == pos.vx2 + i) || (_x+6 == pos.vx2 + i)) ) { //check if the cordinates of width of vertical moving platform
adambakerwa 50:9fc8edf722a8 777 c++; //are the same as blockehads, starting from bottom -1 and up.
adambakerwa 50:9fc8edf722a8 778 }
adambakerwa 50:9fc8edf722a8 779 }
adambakerwa 50:9fc8edf722a8 780 }
adambakerwa 50:9fc8edf722a8 781
adambakerwa 50:9fc8edf722a8 782 for (int a = 0; a < 9; a++) { //for the height of blockhead
adambakerwa 50:9fc8edf722a8 783 for (int i = 0; i < pos.vl2+1; i++) { //and the width of the vertical moving platform two
adambakerwa 50:9fc8edf722a8 784 if ((_y+a == pos.vy2+pos.vh2) && ((_x+2 == pos.vx2 + i) || (_x+6 == pos.vx2 + i)) ) { //check if the cordinates of width of vertical moving platform
adambakerwa 50:9fc8edf722a8 785 c++; //are the same as blockhead's, starting from top -1, and down.
adambakerwa 50:9fc8edf722a8 786 }
adambakerwa 50:9fc8edf722a8 787 }
adambakerwa 50:9fc8edf722a8 788 }
adambakerwa 50:9fc8edf722a8 789
adambakerwa 50:9fc8edf722a8 790 if (c > 0) {
adambakerwa 50:9fc8edf722a8 791 g = 1; //if so, g = 1 .. this means that blockhead is being crushed
adambakerwa 50:9fc8edf722a8 792 } else {
adambakerwa 50:9fc8edf722a8 793 g = 0;
adambakerwa 50:9fc8edf722a8 794 }
adambakerwa 50:9fc8edf722a8 795
adambakerwa 50:9fc8edf722a8 796 //printf("g = %d", g); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 797
adambakerwa 50:9fc8edf722a8 798 return g;
adambakerwa 50:9fc8edf722a8 799 }
adambakerwa 50:9fc8edf722a8 800
adambakerwa 50:9fc8edf722a8 801
adambakerwa 50:9fc8edf722a8 802 //checks if blockhead has hit spikes
adambakerwa 50:9fc8edf722a8 803 int Blockhead::spike_hit(N5110 &lcd, Pos pos)
adambakerwa 50:9fc8edf722a8 804 {
adambakerwa 50:9fc8edf722a8 805 int c = 0;
adambakerwa 50:9fc8edf722a8 806 int g;
adambakerwa 50:9fc8edf722a8 807
adambakerwa 50:9fc8edf722a8 808 for (int i = 0; i < pos.sl; i++) { //for length of spikes,
adambakerwa 50:9fc8edf722a8 809 if (lcd.getPixel(pos.sx+i, pos.sy-3)) { //check if pixels above,
adambakerwa 50:9fc8edf722a8 810 c++; //if plus c
adambakerwa 50:9fc8edf722a8 811 }
adambakerwa 50:9fc8edf722a8 812 }
adambakerwa 50:9fc8edf722a8 813 if (lcd.getPixel(pos.sx-1, pos.sy) || lcd.getPixel(pos.sx, pos.sy-1) || lcd.getPixel(pos.sx, pos.sy-2)) { //check if pixels to left side of spikes
adambakerwa 50:9fc8edf722a8 814 c++; //if so plus c
adambakerwa 50:9fc8edf722a8 815 }
adambakerwa 50:9fc8edf722a8 816
adambakerwa 50:9fc8edf722a8 817 if (lcd.getPixel(pos.sx+pos.sl+1, pos.sy) || lcd.getPixel(pos.sx+pos.sl, pos.sy-1) || lcd.getPixel(pos.sx+pos.sl, pos.sy-2)) { //checl if pixels to right side of spikes
adambakerwa 50:9fc8edf722a8 818 c++; //if so plus c
adambakerwa 50:9fc8edf722a8 819 }
adambakerwa 50:9fc8edf722a8 820
adambakerwa 50:9fc8edf722a8 821
adambakerwa 50:9fc8edf722a8 822 if (c > 0) { //if c > 0, g = 1.. this meand that blockhead has hit the spikes!
adambakerwa 50:9fc8edf722a8 823 g = 1;
adambakerwa 50:9fc8edf722a8 824 } else {
adambakerwa 50:9fc8edf722a8 825 g = 0;
adambakerwa 50:9fc8edf722a8 826 }
adambakerwa 50:9fc8edf722a8 827
adambakerwa 50:9fc8edf722a8 828 //printf("g = %d", g); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 829
adambakerwa 50:9fc8edf722a8 830 return g;
adambakerwa 50:9fc8edf722a8 831 }
adambakerwa 50:9fc8edf722a8 832
adambakerwa 50:9fc8edf722a8 833
adambakerwa 50:9fc8edf722a8 834 //returns 1 if blockhead falls of screen
adambakerwa 50:9fc8edf722a8 835 int Blockhead::fallen(Gamepad &pad)
adambakerwa 50:9fc8edf722a8 836 {
adambakerwa 50:9fc8edf722a8 837 int g;
adambakerwa 50:9fc8edf722a8 838
adambakerwa 50:9fc8edf722a8 839 if (_y > 51) { //if blockhead falls of screen,
adambakerwa 50:9fc8edf722a8 840 g = 1; //g = 1
adambakerwa 50:9fc8edf722a8 841 fall_tune(pad);
adambakerwa 50:9fc8edf722a8 842 } else {
adambakerwa 50:9fc8edf722a8 843 g = 0;
adambakerwa 50:9fc8edf722a8 844 }
adambakerwa 50:9fc8edf722a8 845
adambakerwa 50:9fc8edf722a8 846 //printf("g = %d", g); //uncoment to print for testing
adambakerwa 50:9fc8edf722a8 847
adambakerwa 50:9fc8edf722a8 848 return g;
adambakerwa 50:9fc8edf722a8 849
adambakerwa 50:9fc8edf722a8 850 }
adambakerwa 50:9fc8edf722a8 851
adambakerwa 50:9fc8edf722a8 852
adambakerwa 50:9fc8edf722a8 853 //plays desending tune to play once blockhead falls off screen.
adambakerwa 50:9fc8edf722a8 854 void Blockhead::fall_tune(Gamepad &pad)
adambakerwa 50:9fc8edf722a8 855 {
adambakerwa 50:9fc8edf722a8 856
adambakerwa 50:9fc8edf722a8 857 pad.tone(1046.502, 0.1); //desending tune to play once blockhead falls off screen.
adambakerwa 50:9fc8edf722a8 858 wait(0.1);
adambakerwa 50:9fc8edf722a8 859 pad.tone(932.328, 0.1);
adambakerwa 50:9fc8edf722a8 860 wait(0.1);
adambakerwa 50:9fc8edf722a8 861 pad.tone(622.254, 0.1);
adambakerwa 50:9fc8edf722a8 862 wait(0.1);
adambakerwa 50:9fc8edf722a8 863 pad.tone(523.251, 0.1);
adambakerwa 50:9fc8edf722a8 864 wait(0.1);
adambakerwa 50:9fc8edf722a8 865 pad.tone(466.164, 0.1);
adambakerwa 50:9fc8edf722a8 866 wait(0.1);
adambakerwa 50:9fc8edf722a8 867 pad.tone(369.994, 0.1);
adambakerwa 50:9fc8edf722a8 868 wait(0.1);
adambakerwa 50:9fc8edf722a8 869 pad.tone(293.665, 0.1);
adambakerwa 50:9fc8edf722a8 870 wait(0.1);
adambakerwa 50:9fc8edf722a8 871 pad.tone(261.626, 0.1);
adambakerwa 50:9fc8edf722a8 872 wait(0.1);
adambakerwa 50:9fc8edf722a8 873 }
adambakerwa 50:9fc8edf722a8 874
adambakerwa 50:9fc8edf722a8 875
adambakerwa 50:9fc8edf722a8 876 //checks if blcokhead is on or by any of the platforms
adambakerwa 50:9fc8edf722a8 877 void Blockhead::platform_check(Pos pos)
adambakerwa 50:9fc8edf722a8 878 {
adambakerwa 50:9fc8edf722a8 879 _d = on_hoz_check(pos); //checks if blochead on horizontal (hoz) moving platform
adambakerwa 50:9fc8edf722a8 880 _r = by_hoz_check_right(pos); //checks if blockhead by hoz moving platform
adambakerwa 50:9fc8edf722a8 881 _l = by_hoz_check_left(pos);
adambakerwa 50:9fc8edf722a8 882 _d2 = on_hoz_2_check(pos); //checks if blockhead on second horizontal moving platform
adambakerwa 50:9fc8edf722a8 883 _r2 = by_hoz_2_check_right(pos);
adambakerwa 50:9fc8edf722a8 884 _l2 = by_hoz_2_check_left(pos);
adambakerwa 50:9fc8edf722a8 885 _d3 = on_ver_check(pos); //checks if blockhead on vertical moving platform
adambakerwa 50:9fc8edf722a8 886 _d4 = on_ver_2_check(pos); //checks if blockhead on second vertical moving platform
adambakerwa 50:9fc8edf722a8 887 }
adambakerwa 50:9fc8edf722a8 888
adambakerwa 50:9fc8edf722a8 889
adambakerwa 50:9fc8edf722a8 890 //moves blockhead according to what platform he is on
adambakerwa 50:9fc8edf722a8 891 void Blockhead::on_platform(N5110 &lcd) //if on platform, move blockhead in the direction the platform is moving
adambakerwa 50:9fc8edf722a8 892 {
adambakerwa 50:9fc8edf722a8 893
adambakerwa 50:9fc8edf722a8 894 if (_d == 0 || _r == 1 || _d2 == 0 || _r2 == 1) { //move blockhead right if on/by a horizontal platform moving right
adambakerwa 50:9fc8edf722a8 895 move_right(lcd, 1);
adambakerwa 50:9fc8edf722a8 896 } else if (_d == 1 || _l == 1 || _d2 == 1 || _l2 == 1) { //move blockhead left if on/by a horizontal platform moving left
adambakerwa 50:9fc8edf722a8 897 move_left(lcd, 1);
adambakerwa 50:9fc8edf722a8 898 } else if (_d3 == 4 || _d4 == 4) { //move blockhead up if on a vertical moving platform
adambakerwa 50:9fc8edf722a8 899 move_up(lcd, 1);
adambakerwa 50:9fc8edf722a8 900 }
adambakerwa 50:9fc8edf722a8 901
adambakerwa 50:9fc8edf722a8 902 }
adambakerwa 50:9fc8edf722a8 903
adambakerwa 50:9fc8edf722a8 904