ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19tb

Dependencies:   mbed

Frog/Car.cpp

Committer:
el19tb
Date:
2020-05-07
Revision:
5:6e3afee7eac3
Child:
7:1dce07fd0867

File content as of revision 5:6e3afee7eac3:

#include "Car.h"
#include "CrossyChicken.h"


Car::Car(){  
    //different speeds of vehicles
    slow = 0.4;
    medium = 1.0;
    fast = 1.5;
    grid = 4;
    seperation = 0;
    
    screenHeight = 48;
    screenWidth = 84;
    size = 2; 
    
    // width of all vehicles
    vehicle.width = grid * size;
}

void Car::setRow(int row){
    this->row = row;
    
    // y position of all vehicles
    vehicle.y = screenHeight - grid * row;
    
    // height of all vehicles
    vehicle.height = grid;
}

void Car::setSeperation(int seperate){
    this->seperation = seperate;
    
    // intialize the vehicle size and position in lcd
    // x position of all vehicles
    vehicle.x = 8 + seperation;
}

void Car::speedSlow(){
    speed = slow;
    
    vehicle.x += slow;
}

void Car::speedMedium(int dir, int speed){     
    speed = medium;  
    
    //vehicle.x += speed;
    
    switch(dir)
    {
        case 1:
            vehicle.x += medium;
            break;
        case 2:
            vehicle.x -= medium;
            break;
    }
}

void Car::speedFast(){
    speed = fast;
    
    vehicle.x += fast;
}