Snake

Dependencies:   mbed

Fork of el17x2l by LI Xiang

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Food.cpp Source File

Food.cpp

00001 #include "Food.h"
00002 
00003 Food::Food() {
00004     
00005     }
00006     
00007 Food:: ~Food(){
00008     
00009     }
00010     
00011 void Food::creat(N5110 &lcd)
00012 {
00013     _size = 2;
00014     srand(time(NULL));
00015     _x = 5+4*(rand()%18);
00016     _y = 10+4*(rand()%9);
00017     lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
00018     while (lcd.getPixel(_x-1,_y-1)==true)
00019     {
00020         lcd.setPixel(_x,_y,false);
00021         lcd.setPixel(_x+1,_y,false);
00022         lcd.setPixel(_x,_y+1,false);
00023         lcd.setPixel(_x+1,_y+1,false);
00024         srand(time(NULL));
00025         _x = 5+4*(rand()%18);
00026         _y = 10+4*(rand()%9);
00027        lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
00028     }
00029 }
00030     
00031 Vector2D  Food::get_pos(){
00032     Vector2D p = {_x, _y};
00033     return p;
00034     }
00035 
00036     
00037 
00038     
00039