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.
Diff: GameEngine/SnakevsBlock/SnakevsBlock.cpp
- Revision:
- 87:871d9fecb593
- Parent:
- 85:d50ba0994676
- Child:
- 92:693a6ae0ff8e
--- a/GameEngine/SnakevsBlock/SnakevsBlock.cpp Tue May 07 00:02:11 2019 +0000
+++ b/GameEngine/SnakevsBlock/SnakevsBlock.cpp Wed May 08 16:39:24 2019 +0000
@@ -36,7 +36,7 @@
//To make default motion of the snake free.
for(int i=0; i<=9; i++) {
- b[i] = 1;
+ immobile_bead_n[i] = 1;
}
}
@@ -50,7 +50,7 @@
}
//To make default motion of the snake free.
for(int i=0; i<=9; i++) {
- b[i] = 1;
+ immobile_bead_n[i] = 1;
}
}
@@ -76,7 +76,7 @@
_d = _pad->get_direction(); //Obtains Direction pushed towards on Joystick.
break;
case 2:
- if (_tiltAngle >= 5) {
+ if (_tiltAngle >= 5) { //obtains tilt angle using SnakevsBlock::calculateTilt(device).
_d = E;
} else if (_tiltAngle <= -5) {
_d = W;
@@ -99,7 +99,7 @@
if (_pad->check_event(Gamepad::A_PRESSED) == true) {
garbage = _tiltAngle;
}
- _tiltAngle = -device.get_roll_angle() - garbage;
+ _tiltAngle = -device.get_roll_angle() - garbage; // makes sure that the tilt angle used for calculations is the one subtracted from reference.
//device.get_values();
//printf("%f",_tiltAngle);
@@ -109,15 +109,15 @@
void SnakevsBlock::lightTheLEDS() //This function ligths the LEDS dependent on the direction of travel.
{
if (_d == E) {
- for(int led = 4; led <= 6; led++) {
+ for(int led = 4; led <= 6; led++) { //Lights 3 LEDs on, on the gamepad from the Right.
_pad->led(led,1);
}
} else if (_d == W) {
- for(int led = 1; led <= 3; led++) {
+ for(int led = 1; led <= 3; led++) { //Lights 3 LEDs on, on the gamepad from the Left.
_pad->led(led,1);
}
} else {
- for(int led = 1; led <= 6; led++) {
+ for(int led = 1; led <= 6; led++) { //Lights all LEDs off, on the gamepad.
_pad->led(led,0);
}
}
@@ -169,7 +169,7 @@
SnakevsBlock::CheckSnakeBarrierCollision(0); //Function checks for when the snake collides with barrier A.
SnakevsBlock::CheckSnakeBarrierCollision(1); //Function checks for when the snake collides with barrier B.
- _s.update(_d, b); //_d is the direction of joystick and b controls the motion of a section of the snake relative to obstruction
+ _s.update(_d, immobile_bead_n); //_d is the direction of joystick and immobile_bead_n controls the motion of a section of the snake relative to obstruction
_f.update();
_ff.update();
_fff.update();
@@ -319,6 +319,7 @@
} else { //is 10.
velocity = 1;
}
+ //Send velocities set to related classes.
_b.velocity.y = velocity;
_f.velocity.y = velocity;
_ff.velocity.y = velocity;
@@ -329,6 +330,8 @@
int SnakevsBlock::CheckBlock(int block)
{
+//This gets the value of int block from the loop in SnakevsBlock::CheckSnakeBlockCollision() and compares it to some preset ranges, and sees which sr num
+//should be allocated to it concidering there are 5 blocks numbered 0-4 from right to left, and this identifies the relevant block due to its x axis positions.
int srn;
if((block>=0)&&(block<=18)) {
srn = 0;
@@ -354,7 +357,7 @@
if(blocknum > 0) { // to make sure that snake doesn't decrease in _length if number on the block is less than 1;
_l.MinusLength(); //instructs the length manager class to subtract the length by 1.
_pad->tone(432.0,0.1);
- wait(0.04);
+ wait(0.07); //The wait here makes the player feel that they have enough time to slide away and avoid collision.
}
blocknum-=1;
}
@@ -373,7 +376,7 @@
void SnakevsBlock::MakeDefaultMotionFree() //this makes the default motion of the snake freemoving before a collision is checked for, to forget the previous collision.
{
for(int i=0; i<=9; i++) {
- b[i] = 1;
+ immobile_bead_n[i] = 1;
}
}
@@ -485,7 +488,7 @@
//code makes sure that the colliding part doesn't move in x axis.
for(int snake_beed_num=0; snake_beed_num<=10; snake_beed_num++) {
if(_virtualLength == snake_beed_num + i) {
- b[snake_beed_num - 1] = 0;
+ immobile_bead_n[snake_beed_num - 1] = 0;
}
}
}
\ No newline at end of file