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: Food/Food.cpp
- Revision:
- 9:f3259d652208
- Parent:
- 7:24a3f13ce36d
--- a/Food/Food.cpp Sun May 31 16:06:31 2020 +0000
+++ b/Food/Food.cpp Thu Jun 04 18:47:58 2020 +0000
@@ -1,26 +1,35 @@
#include "Food.h"
+// Constructor
+Food::Food()
+{
+// Desturctor
+}
+Food::~Food()
+{
+
+}
-Food::Food() {
- }
- Food::~Food() {
- }
void Food::init(){
srand(time(NULL));
-
-_foodx = (rand() % (WIDTH-3)+1);
-_foody = (rand() % (HEIGHT-3)+1);
+ // Spawns food in a random position, making sure it appears inside my map
+ _foodx = (rand() % (WIDTH-3)+1);
+ _foody = (rand() % (HEIGHT-3)+1);
+ /*printf("food(x)=%d",_foodx);
+ printf("food(y)=%d",_foody);
+ */
}
- void Food::draw(N5110 &lcd){
- lcd.drawRect(_foodx, _foody, 2, 2, FILL_BLACK);
- }
+void Food::draw(N5110 &lcd)
+{
+ lcd.drawRect(_foodx, _foody, 2, 2, FILL_BLACK); // Draws food as a rectangle
+}
- Vector2D Food::get_pos()
+Vector2D Food::get_pos()
{
- Vector2D f = {_foodx,_foody};
+ Vector2D f = {_foodx,_foody}; // Getting the position of the food
return f;}
- void Food::set_pos(Vector2D fp){
+void Food::set_pos(Vector2D fp){
_foodx = fp.x;
_foody = fp.y;
}
\ No newline at end of file