Wang Lin 201090174
Dependencies: mbed Gamepad N5110 FXOS8700Q
Diff: main.cpp
- Revision:
- 12:121ba031343a
- Parent:
- 10:167d0aa1c9b3
- Child:
- 13:febf9fbb502f
diff -r 1447cb7dce3c -r 121ba031343a main.cpp --- a/main.cpp Tue Apr 17 08:00:08 2018 +0000 +++ b/main.cpp Fri May 03 17:12:37 2019 +0000 @@ -1,87 +1,49 @@ -///////// pre-processor directives //////// -#include "mbed.h" -#include "Gamepad.h" -#include "N5110.h" -#include "PongEngine.h" - -#ifdef WITH_TESTING -# include "tests.h" -#endif - -#define PADDLE_WIDTH 2 -#define PADDLE_HEIGHT 8 -#define BALL_SIZE 2 -#define BALL_SPEED 3 - -/////////////// structs ///////////////// -struct UserInput { - Direction d; - float mag; -}; -/////////////// objects /////////////// -N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); -Gamepad pad; -PongEngine pong; - -///////////// prototypes /////////////// +#include "main.h" +#define SNAKE_LENGTH 100 +#define SNAKE_SIZE 2 void init(); -void update_game(UserInput input); +void welcome(); void render(); -void welcome(); - -///////////// functions //////////////// +void initsnake(); + int main() { -#ifdef WITH_TESTING - int number_of_failures = run_all_tests(); - - if(number_of_failures > 0) return number_of_failures; -#endif - - int fps = 8; // frames per second - + init(); // initialise and then display welcome screen... welcome(); // waiting for the user to start + // first draw the initial frame + initsnake();//intilize the variables + initSnake(); + SpwanFood(); + + while(1) { + lcd.clear(); + render(); + drawFood(); + DrawSnake(); + MoveSnake(); + EatFood(); + lcd.refresh(); + Speed(); - render(); // first draw the initial frame - wait(1.0f/fps); // and wait for one frame period - - - // game loop - read input, update the game state and render the display - while (1) { - pong.read_input(pad); - pong.update(pad); - render(); - wait(1.0f/fps); + } } - -// initialies all classes and libraries + void init() { // need to initialise LCD and Gamepad lcd.init(); pad.init(); - // initialise the game with correct ball and paddle sizes - pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED); - } - -// this function draws each frame on the LCD -void render() -{ - // clear screen, re-draw and refresh - lcd.clear(); - pong.draw(lcd); - lcd.refresh(); -} - -// simple splash screen displayed on start-up + void welcome() { + + lcd.clear(); + lcd.printString(" SNAKE! ",0,1); + lcd.printString(" Press Start ",0,2); - lcd.printString(" Pong! ",0,1); - lcd.printString(" Press Start ",0,4); lcd.refresh(); // wait flashing LEDs until start button is pressed @@ -89,7 +51,23 @@ pad.leds_on(); wait(0.1); pad.leds_off(); - wait(0.1); + wait(waittime); + lcd.printString("LETS START!",0,2); } +} -} \ No newline at end of file +void render() { + + lcd.drawRect(0,0,83,47,FILL_TRANSPARENT); + +} + +void initsnake() { + SNAKE.snakezb[0].x = 30; + SNAKE.snakezb[0].y = 20; + SNAKE.n = 3; //inital length of snake + Dir = 3; + + +} + \ No newline at end of file