Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: main.cpp
- Revision:
- 56:142e9fdb77a8
- Parent:
- 54:20abd16c7d74
- Child:
- 62:ebf6ecf8a6d5
diff -r df0825049171 -r 142e9fdb77a8 main.cpp --- a/main.cpp Sat Apr 27 18:56:30 2019 +0000 +++ b/main.cpp Sun Apr 28 16:56:08 2019 +0000 @@ -3,7 +3,7 @@ School of Electronic & Electrical Engineering University of Leeds Name: Ahmed Nomaan Adamjee -Username: AhmedPlaymaker +Username: el17ana Student ID Number: 201161436 Date: */ @@ -17,12 +17,6 @@ #include "SnakevsBlock.h" #include "SDFileSystem.h" -/////////////// structs ///////////////// -struct UserInput { - Direction d; - float mag; -}; - /////////////// objects /////////////// N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; @@ -37,7 +31,6 @@ ///////////// prototypes ////////////// void init(); -void update_game(UserInput input); void refresh_game(); //Constants// @@ -50,31 +43,26 @@ { init(); _start.screen_saver(lcd, pad); - _start.instruct(lcd, pad); while(1) { //This loop is created for Play/Continue configuration _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; - _start.main_menu(lcd, pad); + _start.main_menu(lcd, pad); // this takes us to main menu inside startscreen, and connects automatically to all other menu functions. _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; - g_mode = _start.g_mode; + 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 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); - back = game.update(lcd, pad, sd); + 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. + refresh_game(); - wait(1.0f/fps); - if(back) { - break; - } - } } } @@ -82,19 +70,18 @@ void init() { // need to initialise LCD and Gamepad - lcd.init(); - device.init(); - pad.init(); - pad.tone(1000.0,0.1); - game.init(); - _start.init(); - srand(100000*noisy.read_u16()); + lcd.init(); //init for the N5110 Library. + device.init(); //init for the FXOS8700CQ Library. + pad.init(); //init for the Gamepad Library. + game.init(); //init for the SnakeVSBlock Class. + _start.init(); //init for the Menu Class --> StartScreen. + srand(100000*noisy.read_u16()); //seeds the random number generator with a random noise from the K64F. } void refresh_game() { - lcd.clear(); - game.draw(lcd, pad); - game.get_pos(); - lcd.refresh(); + lcd.clear(); //clears the N5110 screen for the next frame + game.draw(lcd, pad); //draws the next game frame + game.get_pos(); //takes the game object coordinates and saves it privately to use later for implementing collisions. + lcd.refresh(); //refreshes the N5110 screen to display the frame. } \ No newline at end of file