demo

Dependencies:   mbed Gamepad N5110

Revision:
0:ba32cfe0051e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/foods/foods.cpp	Thu May 14 12:57:32 2020 +0000
@@ -0,0 +1,38 @@
+#include "foods.h"
+
+foods::foods()
+{
+
+}
+
+foods::~foods()
+{
+
+}
+
+void foods::init(int x,int size,int velocity) {
+    _x = x; // foods x beginning postion and updating position
+    _size = size; // the food's size
+    int uncertainty = rand() % (48 - _size * 2);
+    _y = _size + uncertainty; //  the starting vertical position 
+    _velocity = velocity; // sliding velocity
+}
+
+void foods::draw(N5110 &lcd) {
+    lcd.drawCircle(_x,_y,_size,FILL_TRANSPARENT); // draw foods on lcd
+}
+
+void foods::update() {
+    _x -= _velocity; // the foods is moving leftward from the right screen
+}
+
+void foods::replace() {
+    _x = 149; // replace to the right side when the stone exits to the left side of the screen
+    int uncertainty = rand() % (45 - (_size * 2));
+    _y = 1 + _size + uncertainty; // regenerate the vertical position for the stone
+}
+
+Vector2D foods::get_pos() { // get position for collision logic function
+    Vector2D p = {_x,_y};
+    return p;
+}
\ No newline at end of file