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
Fork of ll14zs by
Diff: Car/Car.cpp
- Revision:
- 2:5d3aac7fd3df
- Child:
- 3:1231a3961984
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Car/Car.cpp Tue May 08 11:15:58 2018 +0000 @@ -0,0 +1,102 @@ +#include "Car.h" + +Car::Car() +{ + +} + +Car::~Car() +{ + +} + +void Car::init(int x,int y,int width, int height) +{ + _x = WIDTH/2; _width = 3; // x initial start coordinate + _y = HEIGHT/3; _height = 5; // y initial start coordinate + + + int direction = 0; + if (direction == 0) { + _velocity.y = (1);// car is always moving + } +} + +void Car::draw(N5110 &lcd) +{ + // draw in screen buffer. + lcd.drawRect(_x,_y,_width,_height,FILL_BLACK); +} + +void Car::update(Direction d) +{ + _speed = 2; + + // update the x value depending on the direction of movement + + if (d == -i) { + _x+=_speed; + } + if (d == +i) { + _x-=_speed; + } + + + + // ensure that the car does not go off screen + + if (_x < 1) { + _x = 1; + } + if (_x > 82) { + _x = 82; + } + if (_y < 1) { + _y = 1; + } + if (_y > 42) { + _y = 42; + } + + _y += _velocity.y; + +} + + + + +void Car::set_velocity(Vector2D v) +{ + _velocity.x = v.x; + _velocity.y = v.y; +} + +Vector2D Car::get_velocity() +{ + Vector2D v = {_velocity.x,_velocity.y}; + return v; +} + + +Vector2D Car::get_position() +{ + Vector2D p = {_x,_y}; + return p; +} + +void Car::set_position(Vector2D p) +{ + _x = p.x; + _y = p.y; +} + + + +void Car::add_score() +{ + _score++; +} +int Car::get_score() +{ + return _score; +}