Yang Hongxiao 201199678
Dependencies: mbed
Diff: Platform.cpp
- Revision:
- 1:a6ead8050c23
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Platform.cpp Thu May 14 17:00:34 2020 +0000 @@ -0,0 +1,60 @@ +#include "Platform.h" + +Platform::Platform() +{ + +} +Platform::~Platform() +{ + +} + +void Platform::init(int y,int h,int w) +{ + + _x=WIDTH/2 - w/2; + _y=y; + _h = h; + _w = w; + _vv = 2; // default speed + _score = 0; + +} + + +void Platform::draw(N5110 &lcd) +{ + lcd.drawRect(_x,_y,_w,_h,FILL_BLACK); +} + +void Platform::update(Direction d,float mag) +{ + + _vv = int(mag*10.0f); + if (d == W) { //West + _x-=_vv; + } else if (d == E) { //East + _x+=_vv; + } + if (_x < 1) { + _x = 1; + } + if (_x > WIDTH - _w - 1) { + _x = WIDTH - _w - 1; + } +} + + +Vector2D Platform::get_pos() { + Vector2D p = {_x,_y}; + return p; +} +void Platform::add_score() +{ + _score++; +} +int Platform::get_score() +{ + return _score; +} +