Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Fruit/Fruit.cpp
- Revision:
- 0:d557f30e3a95
- Child:
- 13:4026781772cb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Fruit/Fruit.cpp Mon Apr 30 14:10:48 2018 +0000
@@ -0,0 +1,47 @@
+#include "Fruit.h"
+
+Fruit::Fruit(){
+
+
+
+ }
+
+Fruit::~Fruit(){
+
+
+ }
+
+void Fruit::init(int size){
+ //position of the fruit at Y axis and X axis in the LCD screen which are 84 and 48 , initial position of fruit
+
+ _size = size;
+ _posx = WIDTH/2 - _size/2;
+ _posy = HEIGHT/2 - _size/2;
+
+}
+
+void Fruit::reborn(){//randomise the location of the fruit after it is ate by the sanke
+ srand(time(NULL));
+ _posx = rand() % 80;
+ _posy = rand() % 40;
+
+}
+
+void Fruit::draw(N5110 &lcd){//the map
+ lcd.drawRect(_posx ,_posy ,_size ,_size ,FILL_BLACK);
+
+}
+
+Vector2D Fruit::get_pos(){//get the similar from Pong
+ Vector2D p = {_posx, _posy};
+ return p;
+
+}
+
+
+void Fruit::set_pos(Vector2D p){//set position of the fruit
+ _posx = p.x;
+ _posy = p.y;
+}
+
+