demo
Dependencies: mbed Gamepad N5110
foods/foods.cpp
- Committer:
- Ting12138
- Date:
- 2020-05-14
- Revision:
- 1:7b5a843acc05
- Parent:
- 0:ba32cfe0051e
File content as of revision 1:7b5a843acc05:
#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; }