ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18lg

Dependencies:   mbed

Committer:
el18lg
Date:
Sun May 31 14:12:45 2020 +0000
Revision:
7:24a3f13ce36d
Parent:
6:266fb8fc17f4
Child:
9:f3259d652208
When snake eats food, food now relocates in a different position and snake body increase by one;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18lg 6:266fb8fc17f4 1 #include "Food.h"
el18lg 6:266fb8fc17f4 2
el18lg 6:266fb8fc17f4 3 Food::Food() {
el18lg 6:266fb8fc17f4 4 }
el18lg 6:266fb8fc17f4 5 Food::~Food() {
el18lg 6:266fb8fc17f4 6 }
el18lg 6:266fb8fc17f4 7 void Food::init(){
el18lg 6:266fb8fc17f4 8 srand(time(NULL));
el18lg 6:266fb8fc17f4 9
el18lg 7:24a3f13ce36d 10 _foodx = (rand() % (WIDTH-3)+1);
el18lg 7:24a3f13ce36d 11 _foody = (rand() % (HEIGHT-3)+1);
el18lg 6:266fb8fc17f4 12 }
el18lg 6:266fb8fc17f4 13
el18lg 6:266fb8fc17f4 14 void Food::draw(N5110 &lcd){
el18lg 6:266fb8fc17f4 15 lcd.drawRect(_foodx, _foody, 2, 2, FILL_BLACK);
el18lg 6:266fb8fc17f4 16 }
el18lg 6:266fb8fc17f4 17
el18lg 7:24a3f13ce36d 18 Vector2D Food::get_pos()
el18lg 6:266fb8fc17f4 19 {
el18lg 6:266fb8fc17f4 20 Vector2D f = {_foodx,_foody};
el18lg 7:24a3f13ce36d 21 return f;}
el18lg 7:24a3f13ce36d 22
el18lg 7:24a3f13ce36d 23 void Food::set_pos(Vector2D fp){
el18lg 7:24a3f13ce36d 24 _foodx = fp.x;
el18lg 7:24a3f13ce36d 25 _foody = fp.y;
el18lg 7:24a3f13ce36d 26 }