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.
Revision 62:ebf6ecf8a6d5, committed 2019-04-30
- Comitter:
- AhmedPlaymaker
- Date:
- Tue Apr 30 14:53:38 2019 +0000
- Parent:
- 61:f3c402bc2ad0
- Child:
- 63:205f0ca48473
- Commit message:
- Cleaned the code style of the Block Side Collision
Changed in this revision
--- a/GameEngine/LengthCalc/LengthCalc.h Tue Apr 30 08:32:30 2019 +0000
+++ b/GameEngine/LengthCalc/LengthCalc.h Tue Apr 30 14:53:38 2019 +0000
@@ -7,51 +7,49 @@
class LengthCalc
{
- public:
-
+public:
+
LengthCalc();
~LengthCalc();
-
+
/** Initialise LengthCalc
*
* This function sets the initial length parameters.
*/
void init();
-
+
/** Minus Length
*
* This function decrements the length value by 1;.
*/
void MinusLength();
-
+
/** Plus Length
*
* This function increments the length by one.
*/
void PlusLength();
-
+
/** Draw
*
* This function draws the length on the screen.
*/
void print_length_on_screen(N5110 &lcd);
-
+
/** get the length
*
* This sends the current length value when called.
*/
int _getLength();
-
+
/** Set the Length
*
* This function obtains the length value to be altered.
*/
void _setLength(int length);
- private:
+private:
int _length;
-
-
};
#endif
\ No newline at end of file
--- a/GameEngine/SnakevsBlock/SnakevsBlock.cpp Tue Apr 30 08:32:30 2019 +0000
+++ b/GameEngine/SnakevsBlock/SnakevsBlock.cpp Tue Apr 30 14:53:38 2019 +0000
@@ -19,7 +19,9 @@
foodbuff = 0; //this makes the food fall at diffrent times when a particular level starts.
send_block_number = 0; //this is 0 when there is no collision, thus block number isn't remembered for next set (which would lead to empty blocks).
blockgap = 300; //this is the number of itterations the block will reccur after in the first level.
- for(int i=0; i<=14; i++) {b[i] = 1;} //makes all the snake beads move by default.
+ for(int i=0; i<=14; i++) {
+ b[i] = 1; //makes all the snake beads move by default.
+ }
SnakevsBlock::object_initialisations();
}
@@ -27,7 +29,9 @@
{
//This prepares the game for the next level by reseting certain variables.
foodbuff = 0;
- if(blockgap >= 50) {blockgap -= 10;} //to make progressive levels harder by making the blocks drop more frequently.
+ if(blockgap >= 50) {
+ blockgap -= 10; //to make progressive levels harder by making the blocks drop more frequently.
+ }
/*
//to clear all the memory buffer of the game object positions from the previous level.
for(int i = 0; i <=2 ; i++) {
@@ -60,32 +64,37 @@
}
device.get_values();
switch (g_mode) {
- case 1:
- _d = pad.get_direction(); //Obtains Direction pushed towards on Joystick.
- _mag = pad.get_mag(); //Obtains Magnitude of Joystick. REMOVE THIS LATER.
- break;
- case 2:
- angle = -device.get_roll_angle() - garbage;
- if (angle >= 6) {
- _d = E;
- for(int led = 4; led <= 6; led++) { pad.led(led,1); }
- }
- else if (angle <= -6) {
- _d = W;
- for(int led = 1; led <= 3; led++) { pad.led(led,1); }
- }
- else {
- _d = CENTRE;
- for(int led = 1; led <= 6; led++) { pad.led(led,0); }
- }
- break;
+ case 1:
+ _d = pad.get_direction(); //Obtains Direction pushed towards on Joystick.
+ _mag = pad.get_mag(); //Obtains Magnitude of Joystick. REMOVE THIS LATER.
+ break;
+ case 2:
+ angle = -device.get_roll_angle() - garbage;
+ if (angle >= 6) {
+ _d = E;
+ for(int led = 4; led <= 6; led++) {
+ pad.led(led,1);
+ }
+ } else if (angle <= -6) {
+ _d = W;
+ for(int led = 1; led <= 3; led++) {
+ pad.led(led,1);
+ }
+ } else {
+ _d = CENTRE;
+ for(int led = 1; led <= 6; led++) {
+ pad.led(led,0);
+ }
+ }
+ break;
}
//printf("%d",gm);
//printf("%f",angle);
//printf("%f",device.get_roll_angle());
}
-void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad) {
+void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad)
+{
_length = _l._getLength(); //saves the snake length into a private variable.
_s.draw(lcd, _length, level); //Draws the Snake. //Make these snake buffs relative to the snake drops which in turn relate to the game speed
if(foodbuff >= 0) {
@@ -103,29 +112,28 @@
}
//Code to print length on game screen.
_l.print_length_on_screen(lcd);
-}
+}
int SnakevsBlock::update(N5110 &lcd, Gamepad &pad, SDFileSystem &sd) //Updates objects on screen.
{
send_block_number = 0; //this is for the game to decide wether to remember the number on the block for the current itteration.
- //we dont need to remember if it has already gone past the screen.
+ //we dont need to remember if it has already gone past the screen.
CheckSnakeFoodCollision(pad); //Function checks for when the snake collides with it's food.
CheckSnakeBlockCollision(pad); //Function checks for when the snake collides with any of the blocks.
CheckSnakeBlockSidesCollision(pad); //Function checks for when the snake collides with any of the blocks' sides.
_s.update(_d, b); //_d is the direction of joystick and b controls the motion of a section of the snake relative to obstruction
_f.update();
_ff.update();
- _fff.update();
+ _fff.update();
_b.update(blocknum, blockgap, srn, send_block_number);
//_statset.read(sd); //to read the currently stored value.
if(_length == 0) {
_wl.GameOver(lcd,pad);
}
- if((pad.check_event(Gamepad::BACK_PRESSED))||(_length == 0)){ //Waits for Back button to be pressed.
+ if((pad.check_event(Gamepad::BACK_PRESSED))||(_length == 0)) { //Waits for Back button to be pressed.
back = 1;
SnakevsBlock::init();
- }
- else {
+ } else {
back = 0;
}
//printf("%d\n",_length);
@@ -144,7 +152,7 @@
// 81.000000 0.000000 top right
// 0.000000 0.000000 is top left
// 81.000000 45.000000 bottom right
- snakex = _s.get_pos().x; //this could be snake_pos[0].x or simply snake_pos[0] to represent both x&y but as it is used the most, it improves readability.
+ snakex = _s.get_pos().x; //this could be snake_pos[0].x or simply snake_pos[0] to represent both x&y but as it is used the most, it improves readability.
snakey = _s.get_pos().y; //this could be snake_pos[0].y or simply snake_pos[0] to represent both x&y but as it is used the most, it improves readability.
//printf("snakexy in GAME = %d %d \n", snakex, snakey);
//Obtains all required coordinates.
@@ -164,10 +172,11 @@
snake_pos[7] = _s.get_pos_before7(); //gets the position of the eight beed and saves in array.
snake_pos[8] = _s.get_pos_before8(); //gets the position of the ninth beed and saves in array.
snake_pos[9] = _s.get_pos_before9(); //gets the position of the last beed and saves in array.
-}
-
+}
+
-void SnakevsBlock::CheckSnakeFoodCollision(Gamepad &pad) {
+void SnakevsBlock::CheckSnakeFoodCollision(Gamepad &pad)
+{
//If statements check if the snake sprite has collided with any
//of the three food sprites, if so then the food location is reset and
//length of the snake is increased using the length variable.
@@ -176,11 +185,11 @@
for(int food_sr=0; food_sr<=2; food_sr++) { //this loop automatically detects which food we are interacting with.
if (
((snakey + y == food_pos[food_sr].y) ||
- (snakey + y == food_pos[food_sr].y + 1) ||
- (snakey + y == food_pos[food_sr].y + 2)) &&
+ (snakey + y == food_pos[food_sr].y + 1) ||
+ (snakey + y == food_pos[food_sr].y + 2)) &&
((snakex + x == food_pos[food_sr].x) ||
- (snakex + x == food_pos[food_sr].x + 1) ||
- (snakex + x == food_pos[food_sr].x + 2))
+ (snakex + x == food_pos[food_sr].x + 1) ||
+ (snakex + x == food_pos[food_sr].x + 2))
) {
//printf("snake feast working \n");
//audio feedback
@@ -196,8 +205,9 @@
_ff.set_pos(food_pos[1]);
_fff.set_pos(food_pos[2]);
}
-
-void SnakevsBlock::CheckSnakeBlockCollision(Gamepad &pad) {
+
+void SnakevsBlock::CheckSnakeBlockCollision(Gamepad &pad)
+{
//Obtains the numbers inside the block.
b_number = _b.get_number();
//If statements check if the snake sprite has collided with any
@@ -205,20 +215,21 @@
//the block has to move slower and come down after every 2/3 iterations(dependent on the snake size.(think about this)
for(int block=0; block<=83; block+=1) { //this loop automatically detects for each section of block and each combination of collision
if (((snakey == b_pos.y + 11)||
- (snakey == b_pos.y + 10)||
- (snakey == b_pos.y + 9)||
- (snakey == b_pos.y + 8))&&
- (snakex + 1 == b_pos.x + block)) {
+ (snakey == b_pos.y + 10)||
+ (snakey == b_pos.y + 9)||
+ (snakey == b_pos.y + 8))&&
+ (snakex + 1 == b_pos.x + block)) {
//the or for the block's y position is due to the fact the exact y co-ordinate might not be collided if the snake's length has increased in the same itteration.
//printf("snake collision working \n");
//audio feedback
- if(blocknum > 0) {b_pos.y = 0;} //change this to speed y = 0 when length = 10.
+ if(blocknum > 0) {
+ b_pos.y = 0; //change this to speed y = 0 when length = 10.
+ }
srn = CheckBlock(block); //this tells us which of the 5 blocks we are colliding with
blocknum = b_number[srn];
if((_length>=10)&&(b_number[srn]>0)) { //this makes the block stop moving down if it's length is more than 10 and still collides.
velocity = 0;
- }
- else {
+ } else {
velocity = 1;
}
ImplementCollision(pad);
@@ -226,25 +237,38 @@
}
}
}
-
-void SnakevsBlock::_set_velocity() {
+
+void SnakevsBlock::_set_velocity()
+{
_b.velocity.y = velocity;
_f.velocity.y = velocity;
_ff.velocity.y = velocity;
_fff.velocity.y = velocity;
}
-
-int SnakevsBlock::CheckBlock(int block) {
+
+int SnakevsBlock::CheckBlock(int block)
+{
int srn;
- if((block>=0)&&(block<=18)) {srn = 0;}
- if((block>=19)&&(block<=34)) {srn = 1;}
- if((block>=35)&&(block<=50)) {srn = 2;}
- if((block>=51)&&(block<=66)) {srn = 3;}
- if((block>=67)&&(block<=83)) {srn = 4;}
+ if((block>=0)&&(block<=18)) {
+ srn = 0;
+ }
+ if((block>=19)&&(block<=34)) {
+ srn = 1;
+ }
+ if((block>=35)&&(block<=50)) {
+ srn = 2;
+ }
+ if((block>=51)&&(block<=66)) {
+ srn = 3;
+ }
+ if((block>=67)&&(block<=83)) {
+ srn = 4;
+ }
return srn;
}
-
-void SnakevsBlock::ImplementCollision(Gamepad &pad) {
+
+void SnakevsBlock::ImplementCollision(Gamepad &pad)
+{
send_block_number = 1;
if(blocknum > 0) { // to make sure that snake doesn't decrease in _length if number on the block is less than 1;
_l.MinusLength();
@@ -258,45 +282,68 @@
{
//If statements check if the snake sprite has collided with any
//of the blocks' sides and then stop the snake moving in x axis
- int length = _length;
- if(_length>=10) {length = 10;} //to stop the snake length virtually at 10 when it goes past it.
-
for(int i=0; i<=9; i++) {
b[i] = 1;
}
for(int i=0; i<=9; i++) { //i checks for all possible collisions with the snake respective to it's length.
- for(int b_y_combination=0; b_y_combination<=10; b_y_combination++) {
- if (
- (snake_pos[i].y == b_pos.y + b_y_combination) ||
- (snake_pos[i].y + 1 == b_pos.y + b_y_combination) ||
- (snake_pos[i].y + 2 == b_pos.y + b_y_combination)) {
- for(int b_x_combination=2; b_x_combination<=82; b_x_combination+=16) {
- //For West side of walls
- if(
- ((snake_pos[i].x == b_pos.x + b_x_combination+2) || //W
- (snake_pos[i].x + 1 == b_x_combination+2))&&(_d != E)&&(length > i) //W
- ) {
- //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(length == snake_beed_num + i) {
- b[snake_beed_num - 1] = 0;
- }
- }
- }
- //for East side of walls
- else if (
- ((snake_pos[i].x + 1 == b_x_combination) || //E
- (snake_pos[i].x + 2 == b_x_combination))&&(_d != W)&&(length > i) //E
- ) {
- //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(length == snake_beed_num + i) {
- b[snake_beed_num - 1] = 0;
- }
- }
- }
- }
- }
+ SnakevsBlock::check_Collision_Y_axis(i); //checks if the snake and the block are at the same position in y axis.
+ }
+}
+
+void SnakevsBlock::check_Collision_Y_axis(int i) //i is the index of the snake beed and checks for all possible collisions with the snake respective to it's length.
+{
+ //This code checks if the snake and the block overlap in the Y axis.
+ for(int b_y_combination=0; b_y_combination<=10; b_y_combination++) {
+ if (
+ (snake_pos[i].y == b_pos.y + b_y_combination) ||
+ (snake_pos[i].y + 1 == b_pos.y + b_y_combination) ||
+ (snake_pos[i].y + 2 == b_pos.y + b_y_combination)) {
+
+ SnakevsBlock::check_Collision_X_axis(i); //checks if the snake and the block are at the same position in x axis.
+
+ }
+ }
+}
+
+void SnakevsBlock::check_Collision_X_axis(int i) //i is the index of the snake beed and checks for all possible collisions with the snake respective to it's length.
+{
+ for(int b_x_combination=2; b_x_combination<=82; b_x_combination+=16) {
+
+ SnakevsBlock::checkCollision_EastorWest(b_x_combination, i); //checks if the colliding wall is on east side or west side.
+ }
+}
+
+void SnakevsBlock::checkCollision_EastorWest(int b_x_combination, int i) //i checks for all possible collisions with the snake respective to it's length.
+{
+ //this makes the virtual length -> 10 for the side collision implementation because if the length is fifteen and the last beed collides, it still is the 10th beed
+ //on screen.
+ int length = _length;
+ if(_length>=10) {
+ length = 10; //to stop the snake length virtually at 10 when it goes past it.
+ }
+
+//For West side of walls
+ if(
+ ((snake_pos[i].x == b_pos.x + b_x_combination+2) || //W
+ (snake_pos[i].x + 1 == b_x_combination+2))&&(_d != E)&&(length > i) //W
+ ) {
+ SnakevsBlock::StopX_AxisMotion(length, i);
+ }
+ //for East side of walls
+ else if (
+ ((snake_pos[i].x + 1 == b_x_combination) || //E
+ (snake_pos[i].x + 2 == b_x_combination))&&(_d != W)&&(length > i) //E
+ ) {
+ SnakevsBlock::StopX_AxisMotion(length, i);
+ }
+}
+
+void SnakevsBlock::StopX_AxisMotion(int length, int i) //i is the index of the snake beed and checks for all possible collisions with the snake respective to it's length.
+{
+ //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(length == snake_beed_num + i) {
+ b[snake_beed_num - 1] = 0;
}
}
}
\ No newline at end of file
--- a/GameEngine/SnakevsBlock/SnakevsBlock.h Tue Apr 30 08:32:30 2019 +0000
+++ b/GameEngine/SnakevsBlock/SnakevsBlock.h Tue Apr 30 14:53:38 2019 +0000
@@ -16,64 +16,64 @@
class SnakevsBlock
{
- public:
+public:
SnakevsBlock();
~SnakevsBlock();
-
+
/** Initialise Game Machine
*
* This function initialises the game machine.
*/
void init();
-
+
/** Reset Game Machine
*
* This function prepares the game machine for the next level.
*/
void reset( );
-
+
/** Initialise objects
*
* This function initialises the objects that are used to functionalise the game.
*/
void object_initialisations();
-
+
/** Read Input
*
* This function obtains numeric data from the gamepads joystick.
*/
void read_input(Gamepad &pad, FXOS8700CQ &device, int gm);
-
- /** Draw
+
+ /** Draw
*
* This function contains the draw functions of the other libraries used in the game.
*/
void draw(N5110 &lcd, Gamepad &pad);
-
+
/** Update
*
* This function contains the update functions of the other libraries used in the game.
*/
int update(N5110 &lcd, Gamepad &pad, SDFileSystem &sd);
-
+
/** Get Position
*
* This function contains the Get Position functions of the otehr libraries used in the game.
*/
void get_pos();
-
+
/** Check Block
*
* This function returns the srn of the block we are colliding with;
*/
int CheckBlock(int Block);
-
+
/** Implement Collision
*
* This function allows the appropriate maths to take place after every collision.
*/
void ImplementCollision(Gamepad &pad);
-
+
int snakex; //x position of top beed
int snakey; //y position of top beed
int length; //saves the length of the snake, for collision detection relative to it's length and calculations.
@@ -93,8 +93,10 @@
Vector2D snake_pos[15]; //saves the position of all the snake beeds in an array for ease of collision processing.
Vector2D food_pos[3]; //saves the position of all 3 snake food on the screen in a single array for ease of collision processing.
Vector2D b_pos; //saves the origin of the blocks on the screen (this is the top left corner of the block row).
-
- private:
+
+ //Gamepad @enginePad
+
+private:
Snake _s;
LengthCalc _l;
WinLoose _wl;
@@ -110,29 +112,53 @@
float _mag;
int _detect_slowly; //this makes sure that when the length is more than 10, the colliding block doesnt decrease the all the length in a single itteration.
int n;
-
+
/** Check for Snake and Food collision
*
* This function checks if the Snake has come into contact with it's food.
*/
void CheckSnakeFoodCollision(Gamepad &pad);
-
+
/** Check for Snake and Block collision
*
* This function checks if the Snake has come into contact with any Block.
*/
void CheckSnakeBlockCollision(Gamepad &pad);
-
+
/** Implement velocity alteration.
*
* this is to stop/move the background (food and blocks), when collision occurs at a length greater than 10.lock.
*/
void _set_velocity();
-
+
/** Check for Snake and Block Sides collision
*
* This function checks if the Snake has come into contact with any the sides of the block and stops it moving.
*/
void CheckSnakeBlockSidesCollision(Gamepad &pad);
+
+ /** Check Collision in Y axis
+ *
+ * This function checks if the Snake and blocks collide anywhere in the Y axis.
+ */
+ void check_Collision_Y_axis(int i);
+
+ /** Check Collision in X axis
+ *
+ * This function checks if the Snake and blocks collide anywhere in the X axis.
+ */
+ void check_Collision_X_axis(int i);
+
+ /** Check Collision East or West
+ *
+ * checks if the colliding wall is on east side or west side and then calls StopX_AxisMotion(length,i) to carry out the required task.
+ */
+ void checkCollision_EastorWest(int b_x_combination, int i);
+
+ /** Stop X Axis Motion
+ *
+ * This function implements the sides collision by making the x axis speed of the particular snake beed 0.
+ */
+ void StopX_AxisMotion(int length, int i);
};
#endif
\ No newline at end of file
--- a/GameEngine/WinLoose/WinLoose.cpp Tue Apr 30 08:32:30 2019 +0000
+++ b/GameEngine/WinLoose/WinLoose.cpp Tue Apr 30 14:53:38 2019 +0000
@@ -18,7 +18,7 @@
lcd.printString("Press Start",10,3);
lcd.printString("to Proceed",12,4);
lcd.refresh();
- wait(0.1);
+ wait(0.05);
while (pad.check_event(Gamepad::START_PRESSED) == false) {
pad.leds_on();
pad.tone(rand()%1001,0.1); //helps to set max freq for random sound
--- a/K64F_PAD_LCDConfiguration/Gamepad/Gamepad.cpp Tue Apr 30 08:32:30 2019 +0000
+++ b/K64F_PAD_LCDConfiguration/Gamepad/Gamepad.cpp Tue Apr 30 14:53:38 2019 +0000
@@ -99,9 +99,9 @@
if (val > 1.0f) {
val = 1.0f;
}
-
+
switch (n) {
-
+
// check for valid LED number and set value
case 1:
--- a/MenuClasses/StartScreen/StartScreen.cpp Tue Apr 30 08:32:30 2019 +0000
+++ b/MenuClasses/StartScreen/StartScreen.cpp Tue Apr 30 14:53:38 2019 +0000
@@ -51,7 +51,7 @@
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
-
+
int arrow[7][9] = {
{0,0,0,0,1,0,0,0,0},
{0,0,0,1,1,0,0,0,0},
@@ -61,7 +61,7 @@
{0,0,0,1,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
};
-
+
int motionControl[12][21] = {
{0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
@@ -127,22 +127,23 @@
StartScreen::StartScreen()
{
-
+
}
StartScreen::~StartScreen()
{
-
+
}
void StartScreen::init()
{
+ fps = 40; //sets the default frames per second to a certain value.
i = 16; //main menu selection arrow position
g_mode = 1; //game mode selection (joystick/motion control).
gs = 2; //game speed page selection.
st = 1; //this is the sr num of settings pages.
sc = 1; //this helps in wether ot not to show credits to the user.
- cs = 4; //sensitivity of control speed of menu options.
+ cs = 5; //sensitivity of control speed of menu options.
}
void StartScreen::screen_saver(N5110 &lcd, Gamepad &pad)
@@ -150,7 +151,7 @@
//this saves the Theme song I want to play at the start.
int song[18] = {441,494,439,372,392,370,330,246,329,331,370,555,555,495,440,392,392,370};
pad.leds_on();
-
+
for(int ani = -51; ani <= 0; ani+=3) {
lcd.clear();
lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
@@ -163,10 +164,12 @@
}
wait(0.2);
}
- if (Start_Pressed == 0) { wait(0.3); } //dont wait anymore if start is pressed.
+ if (Start_Pressed == 0) {
+ wait(0.3); //dont wait anymore if start is pressed.
+ }
pad.leds_off();
lcd.clear();
-
+
StartScreen::instruct(lcd,pad); //after the screen_saver is displayed we need to send in instructions of how to preoceed to menu.
}
@@ -187,9 +190,9 @@
lcd.clear();
pad.leds_off();
}
-
+
void StartScreen::credits(N5110 &lcd)
-{
+{
lcd.clear();
if(sc) {
lcd.printString("Created BY",8,1);
@@ -221,7 +224,7 @@
}
void StartScreen::ImplementMenu(N5110 &lcd, Gamepad &pad)
-{
+{
lcd.printString("SnakeVSBlock",5,0);
lcd.printString("Play",0,2);
lcd.printString("Settings",0,3);
@@ -229,10 +232,10 @@
lcd.printString("Tutorial",0,5);
Direction d = pad.get_direction();
if(((d==N)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(i>16)) {
- i=i-8;
+ i=i-8;
}
if(((d==S)||(pad.check_event(Gamepad::R_PRESSED) == true))&&(i<40)) {
- i=i+8;
+ i=i+8;
}
lcd.drawSprite(50,i,7,9,(int *)arrow); //Function used to draw the sprite.
lcd.refresh();
@@ -243,24 +246,24 @@
void StartScreen::NextMenu(N5110 &lcd, Gamepad &pad)
{
switch (i) {
- case 16:
- game_mode(lcd, pad);
- break;
- case 24:
- float *cs_sc;
- cs_sc = _settings.Implement(lcd, pad, cs);
- cs = cs_sc[0]; //saves the number in cs which controls the control speed of the menu oftions (basically the wait time of between reading joystick input).
- sc = cs_sc[1]; //saves the number in sc which decides weather or not to show credits when game starts.
- main_menu(lcd, pad); //to return to main_menu if back is pressed
- break;
- case 32:
- _stats.StatsDisplay(lcd, pad);
- main_menu(lcd, pad); //to return to main_menu if back is pressed
- break;
- case 40:
- _tutorial.Implement(lcd, pad);
- main_menu(lcd, pad); //to return to main_menu if back is pressed
- break;
+ case 16:
+ game_mode(lcd, pad);
+ break;
+ case 24:
+ float *cs_sc;
+ cs_sc = _settings.Implement(lcd, pad, cs);
+ cs = cs_sc[0]; //saves the number in cs which controls the control speed of the menu oftions (basically the wait time of between reading joystick input).
+ sc = cs_sc[1]; //saves the number in sc which decides weather or not to show credits when game starts.
+ main_menu(lcd, pad); //to return to main_menu if back is pressed
+ break;
+ case 32:
+ _stats.StatsDisplay(lcd, pad);
+ main_menu(lcd, pad); //to return to main_menu if back is pressed
+ break;
+ case 40:
+ _tutorial.Implement(lcd, pad);
+ main_menu(lcd, pad); //to return to main_menu if back is pressed
+ break;
}
}
@@ -276,14 +279,19 @@
pad.tone(1000.0,0.1);
back_pressed = 1;
break;
+ } else {
+ back_pressed = 0;
}
- else {back_pressed = 0;}
}
pad.tone(1000.0,0.1);
- if(back_pressed) { main_menu(lcd, pad); }
- else {
- if (g_mode == 2) { StartScreen::motionControlInstructions(lcd); }
- else { pad.tone(1000.0,0.1); }
+ if(back_pressed) {
+ main_menu(lcd, pad);
+ } else {
+ if (g_mode == 2) {
+ StartScreen::motionControlInstructions(lcd);
+ } else {
+ pad.tone(1000.0,0.1);
+ }
lcd.clear();
game_speed(lcd, pad);
}
@@ -293,37 +301,37 @@
{
lcd.clear();
switch (g_mode) {
- case 1:
- lcd.printString("Joystick",18,1);
- lcd.drawSprite(17,22,13,48,(int *)joystick); //Function used to draw the sprite.
- lcd.refresh();
- break;
- case 2:
- lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
- lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
- lcd.printString("Motion Control",1,1);
- lcd.drawSprite(32,22,12,21,(int *)motionControl); //Function used to draw the sprite.
- break;
+ case 1:
+ lcd.printString("Joystick",18,1);
+ lcd.drawSprite(17,22,13,48,(int *)joystick); //Function used to draw the sprite.
+ lcd.refresh();
+ break;
+ case 2:
+ lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
+ lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
+ lcd.printString("Motion Control",1,1);
+ lcd.drawSprite(32,22,12,21,(int *)motionControl); //Function used to draw the sprite.
+ break;
}
-
+
lcd.refresh();
}
void StartScreen::SelectMode(Gamepad &pad)
-{
+{
Direction d = pad.get_direction();
wait(1/cs);
if(((d==E)||(d==W)||(pad.check_event(Gamepad::R_PRESSED) == true)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(g_mode==1)) {
g_mode=2;
}
-
+
else if(((d==E)||(d==W)||(pad.check_event(Gamepad::R_PRESSED) == true)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(g_mode==2)) {
g_mode=1;
}
}
void StartScreen::motionControlInstructions(N5110 &lcd)
-{
+{
lcd.clear();
lcd.printString("While playing the",5,0); //Function used to promt the user to start.
lcd.printString("game, press",9,1);
@@ -346,11 +354,13 @@
pad.tone(1000.0,0.1);
back_pressed = 1;
break;
+ } else {
+ back_pressed = 0;
}
- else {back_pressed = 0;}
}
- if(back_pressed) { game_mode(lcd, pad); }
- else {
+ if(back_pressed) {
+ game_mode(lcd, pad);
+ } else {
pad.tone(1000.0,0.1);
lcd.clear();
wait(1/cs);
@@ -358,46 +368,43 @@
}
void StartScreen::selectSpeedPage(Gamepad &pad)
-{
+{
Direction d = pad.get_direction();
wait(1/cs);
if(((d==E)||(pad.check_event(Gamepad::R_PRESSED) == true))&&(gs==4)) {
gs=1;
- }
- else if(((d==W)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(gs==1)) {
+ } else if(((d==W)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(gs==1)) {
gs=4;
- }
- else if(((d==E)||(pad.check_event(Gamepad::R_PRESSED) == true))&&(1<=gs<=3)) {
+ } else if(((d==E)||(pad.check_event(Gamepad::R_PRESSED) == true))&&(1<=gs<=3)) {
gs=gs+1;
- }
- else if(((d==W)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(2<=gs<=4)) {
+ } else if(((d==W)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(2<=gs<=4)) {
gs=gs-1;
}
}
void StartScreen::showSpeedOptions(N5110 &lcd) //decrease code size.
-{
+{
lcd.clear();
lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
lcd.printString("Game Speed",10,1);
switch (gs) {
- case 1:
- lcd.printString("SNAKE",28,3);
- fps = 12;
- break;
- case 2:
- lcd.printString("HUMAN",28,3);
- fps = 18;
- break;
- case 3:
- lcd.printString("HORSE",28,3);
- fps = 22;
- break;
- case 4:
- lcd.printString("CHEETHA",21,3);
- fps = 27;
+ case 1:
+ lcd.printString("SNAKE",28,3);
+ fps = 12;
+ break;
+ case 2:
+ lcd.printString("HUMAN",28,3);
+ fps = 18;
+ break;
+ case 3:
+ lcd.printString("HORSE",28,3);
+ fps = 22;
+ break;
+ case 4:
+ lcd.printString("CHEETHA",21,3);
+ fps = 27;
}
-
+
lcd.refresh();
}
\ No newline at end of file
--- a/MenuClasses/Stats/Stats.cpp Tue Apr 30 08:32:30 2019 +0000
+++ b/MenuClasses/Stats/Stats.cpp Tue Apr 30 14:53:38 2019 +0000
@@ -2,18 +2,18 @@
Stats::Stats()
{
-
+
}
Stats::~Stats()
{
-
+
}
FILE *fp; // this is the file pointer
//serial.baud(115200); // full-speed!
-
-
+
+
void Stats::StatsDisplay(N5110 &lcd, Gamepad &pad)
{
lcd.clear();
@@ -51,7 +51,7 @@
else {
_top_level = _stored_top_level;
}
-
+
if (fp == NULL) { // if it can't open the file then print error message
//serial.printf("Error! Unable to open file!\n");
} else { // opened file so can write
--- a/MenuClasses/Tutorial/Tutorial.cpp Tue Apr 30 08:32:30 2019 +0000
+++ b/MenuClasses/Tutorial/Tutorial.cpp Tue Apr 30 14:53:38 2019 +0000
@@ -2,12 +2,12 @@
Tutorial::Tutorial()
{
-
+
}
Tutorial::~Tutorial()
{
-
+
}
int g_pad[27][44] = {
@@ -204,8 +204,8 @@
}
void Tutorial::gamePad(N5110 &lcd, Gamepad &pad)
-{
- while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed.
+{
+ while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed.
lcd.drawSprite(20,0,27,44,(int *)g_pad); //Function used to draw the sprite.
lcd.printString("This is your",7,4);
lcd.printString("GamePad",22,5);
--- a/main.cpp Tue Apr 30 08:32:30 2019 +0000
+++ b/main.cpp Tue Apr 30 14:53:38 2019 +0000
@@ -50,17 +50,19 @@
_start.credits(lcd); // this is after the menu to allow us to hide credits if we want to play the game fast.
fps = _start.fps; // sets the frames per second required, selected from the game speed menu.
g_mode = _start.g_mode;// allows us to pass this information on to the snakevsblock class, to set the controls to either joystick or motion control.
- // start the game
+ // start the game
refresh_game();
- wait(1.0f/fps);
-
+ wait(1.0f/fps);
+
// snakeVSblock - detect input respect to the menu options, and update data and refresh screen
while (1) {
-
+
game.read_input(pad, device, g_mode); //this reads the angle or joystick direction, on the condition of either of them being selected.
- back = game.update(lcd, pad, sd); //the int back stores the value 1 if back is pressed inside the update function of snakevsblock
- if(back) { break; } //and this allows us to return to main menu by using the keyword break.
-
+ back = game.update(lcd, pad, sd); //the int back stores the value 1 if back is pressed inside the update function of snakevsblock
+ if(back) {
+ break; //and this allows us to return to main menu by using the keyword break.
+ }
+
refresh_game();
wait(1.0f/fps);
}
@@ -69,7 +71,7 @@
void init()
{
- // need to initialise LCD and Gamepad
+ // need to initialise LCD and Gamepad
lcd.init(); //init for the N5110 Library.
device.init(); //init for the FXOS8700CQ Library.
pad.init(); //init for the Gamepad Library.