![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
Diff: main.cpp
- Revision:
- 70:7caab8069b9b
- Parent:
- 69:55e309da7efd
- Child:
- 72:4d49d2544cef
diff -r 55e309da7efd -r 7caab8069b9b main.cpp --- a/main.cpp Sat May 04 17:18:44 2019 +0000 +++ b/main.cpp Sat May 04 20:48:10 2019 +0000 @@ -59,17 +59,19 @@ init(); _start.titleScreen(lcd, pad); while(1) { //This loop is created for Play/Continue configuration - menu(); + menu(); //pops up the menu by calling the StartScreen Classes. + // 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 game loop - detect input respect to the menu options, and update data and refresh screen gameLoop(); } } +//MAIN_FUNCTIONS + +//INIT void init() { // need to initialise LCD and Gamepad @@ -81,6 +83,7 @@ srand(100000*noisy.read_u16()); //seeds the random number generator with a random noise from the K64F. } +//MENU void menu() { read_write_stats(); //inside menu because used in a menu function for displaying the highest level saved. @@ -88,6 +91,7 @@ _set_mode_speed(); //takes all the data collected from the menu to configure the game. } +//REFRESH GAME. void refresh_game() { lcd.clear(); //clears the N5110 screen for the next frame @@ -96,12 +100,14 @@ lcd.refresh(); //refreshes the N5110 screen to display the frame. } +//READ AND WRITE STATS. void read_write_stats() { _start.read_stats(sd); //this is to save the current highest level in the stats class that can be used in menu. _stats.write(1, sd); //this tells the stats class that the game has started from level 1; } +//SET MODE AND SPEED. void _set_mode_speed() { fps = _start.fps; // sets the frames per second required, selected from the game speed menu. @@ -112,12 +118,13 @@ } } +//GAME LOOP. void gameLoop() { while (1) { + refresh_game(); _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.