Wang Lin 201090174

Dependencies:   mbed Gamepad N5110 FXOS8700Q

main.cpp

Committer:
a1115921303
Date:
2019-05-03
Revision:
12:121ba031343a
Parent:
10:167d0aa1c9b3
Child:
13:febf9fbb502f

File content as of revision 12:121ba031343a:

#include "main.h"
#define SNAKE_LENGTH 100
#define SNAKE_SIZE 2
void init();
void welcome();
void render();
void initsnake();
 
int main()
{
 
    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();
    
    
    }
}
 
void init()
{
    // need to initialise LCD and Gamepad 
    lcd.init();
    pad.init();
     
}
 
void welcome() {
        
    lcd.clear();    
    lcd.printString(" SNAKE!  ",0,1);  
    lcd.printString(" Press Start ",0,2);
    
    lcd.refresh();
     
    // wait flashing LEDs until start button is pressed 
    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(waittime);
        lcd.printString("LETS START!",0,2);
    }
}
 
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;
  
    
}