ELEC2645 (2017/18) / Mbed 2 deprecated ll14zs

Dependencies:   mbed

Fork of ll14zs by Zeshaan Saeed

Car/Car.cpp

Committer:
ll14zs
Date:
2018-05-24
Revision:
3:1231a3961984
Parent:
2:5d3aac7fd3df

File content as of revision 3:1231a3961984:

#include "Car.h"

Car::Car()
{


}

Car::~Car()
{


}

void Car::init(int x,int y,int width, int height)
{
    _x = WIDTH/2;    _width = 3;          // initial start coordinate (x)
    _y = HEIGHT/3;   _height = 5;         // initial start coordinate (y)
    

    int direction = 0;
    if (direction == 0) {
        _velocity.y = (1);// car is moving in the y direction, hence, down the screen
    }
}

void Car::draw(N5110 &lcd)
{
    // the pixels in the screen are filled in black to form a rectangle 
    
   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_pos()
{
    Vector2D p = {_x,_y};
    return p;
}

void Car::set_pos(Vector2D p)
{
    _x = p.x;
    _y = p.y;
}



void Car::add_score()
{
    _score++;
}
int Car::get_score()
{
    return _score;
}