Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: main.cpp
- Revision:
- 69:55e309da7efd
- Parent:
- 68:b9cfd27987ac
- Child:
- 70:7caab8069b9b
--- a/main.cpp Sat May 04 16:56:04 2019 +0000 +++ b/main.cpp Sat May 04 17:18:44 2019 +0000 @@ -17,7 +17,7 @@ #include "SnakevsBlock.h" #include "SDFileSystem.h" -#ifdef WITH_TESTING +#ifdef TEST_SNAKE # include "tests.h" #endif @@ -36,8 +36,10 @@ ///////////// prototypes ////////////// void init(); void refresh_game(); +void menu(); void read_write_stats(); void _set_mode_speed(); +void gameLoop(); //void deinit(); //Constants// @@ -48,7 +50,7 @@ ///////////// MAIN //////////////// int main() { -#ifdef WITH_TESTING +#ifdef TEST_SNAKE int number_of_failures = run_all_tests(); if(number_of_failures > 0) return number_of_failures; @@ -57,31 +59,14 @@ init(); _start.titleScreen(lcd, pad); while(1) { //This loop is created for Play/Continue configuration - read_write_stats(); - _start.menu(lcd, pad); // this takes us to main menu inside startscreen, and connects automatically to all other menu functions. - _set_mode_speed(); + menu(); // start the game _start.credits(lcd); // this is after the menu to allow us to hide credits if we want to play the game without wasting any time. refresh_game(); 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. - _game.update(lcd, pad); //updates the game screen and checks for any collisions. - refresh_game(); - - //the int back stores the value 1 if back is pressed inside the update function of snakevsblock, - //This function also handles level progression and level failure operations by using the class WinLoose. - back = _game.CheckGameProgression(lcd, pad, sd); //and also sends relevant data to the sd card to implement stats functionality. - - if(back) { - break; //and this allows us to return to main menu by using the keyword break. - } - - wait(1.0f/fps); - } + // snakeVSblock game loop - detect input respect to the menu options, and update data and refresh screen + gameLoop(); } } @@ -96,6 +81,13 @@ srand(100000*noisy.read_u16()); //seeds the random number generator with a random noise from the K64F. } +void menu() +{ + read_write_stats(); //inside menu because used in a menu function for displaying the highest level saved. + _start.menu(lcd, pad); // this takes us to main menu inside startscreen, and connects automatically to all other menu functions. + _set_mode_speed(); //takes all the data collected from the menu to configure the game. +} + void refresh_game() { lcd.clear(); //clears the N5110 screen for the next frame @@ -119,6 +111,26 @@ _start.motionControlInstructions(lcd); //this only comes up on the screen is the user selects motion control from menu options. } } + +void gameLoop() +{ + 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. + _game.update(lcd, pad); //updates the game screen and checks for any collisions. + refresh_game(); + + //the int back stores the value 1 if back is pressed inside the update function of snakevsblock, + //This function also handles level progression and level failure operations by using the class WinLoose. + back = _game.CheckGameProgression(lcd, pad, sd); //and also sends relevant data to the sd card to implement stats functionality. + + if(back) { + break; //and this allows us to return to main menu by using the keyword break. + } + + wait(1.0f/fps); + } +} + /* void deinit() {