ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19tb

Dependencies:   mbed

GraphicEngine/GraphicEngine.cpp

Committer:
el19tb
Date:
2020-05-13
Revision:
14:6fe667ec957e
Parent:
13:cd6d2f999057
Child:
15:b15bf9357cd9

File content as of revision 14:6fe667ec957e:

#include "GraphicEngine.h"

N5110 lcd;

// TO DO:
// -> make multiple lanes of cars (first manually then automatically)
// -> make one lane go other direction
// -> make a safety lane
// -> make a logs
// -> make turtles
// -> make the ocean (if collision with ocean then dead)
// -> make multiple lives
// -> point system
// -> make the sprite images
// -> make background object (sprite of entire screen)
// -> make menu screen
// -> collision
// -> make sprite of safety lanes
// -> make snake object
// -> make turtles disappear after a certain time
// BONUS:
// --> make multiple levels
// --> time constraint
// -> crocodile (level 3) only (jump on body)
// -> snake on log (level 3)

GraphicEngine::GraphicEngine(Chicken *chicken){
    this->chick = chicken;
}

void GraphicEngine::init(){
    lcd.init();
}

void GraphicEngine::showChicken(){
    //fill the chicken with black color
    lcd.drawRect(chick->x, chick->y, chick->width, chick->width, FILL_BLACK);
}

void GraphicEngine::showCar(Car *car){        
    // safety lane
    lcd.drawRect(0, 48 - 4, 84, 4, FILL_TRANSPARENT);
    lcd.drawRect(0, 48 - 4*6, 84, 4, FILL_TRANSPARENT);
        
    // draw to screen
    // create an enum to determine the vehicle type
    for(int y = 0; y < 4; y++){
        showIndividualCar(&car[y]);
    }
}

void GraphicEngine::showIndividualCar(Car *car){
    DrawCar temp_car;
    
    temp_car.x = car->vehicle.x;
    temp_car.y = car->vehicle.y;
    temp_car.width = car->vehicle.width;
    temp_car.height = car->vehicle.height;
    
    displayCar(temp_car);
}


void GraphicEngine::drawVehicleSprites(char obj, int x, int y, int rows, int cols)
{
    switch(obj)
    {
        case 'L':
            lcd.drawSprite(x, y, rows, cols, (int *)left_racer);
            
        case 'R' :
            lcd.drawSprite(x, y, rows, cols, (int *)right_racer);
        
        case 'B':
            lcd.drawSprite(x, y, rows, cols, (int *)bus);

        case 'N':
            lcd.drawSprite(x, y, rows, cols, (int *)right_normal);

        case 'X':
            lcd.drawSprite(x, y, rows, cols, (int *)left_normal);
    }
}

// this is just going to be white blocks
// road == '.'
void GraphhicEngine::drawRoads(char obj, int x, int y, int width, int height)
{
    if(obj == '.'){
        lcd.drawRect(x, y, width, height, FILL_WHITE);
    }
}

// water = ','
void GraphicEngine::drawWater(char water, int x, int y, int row, in col)
{
    int rand_water = 0;
    rand_water = (rand() % 3) + 1;
    
    // for design purposes the water will have differnet designs
    switch(rand_water)
    {
        case 0:
            lcd.drawSprite  
    
}

void GraphicEngine::displayCar(DrawCar &size){
     lcd.drawRect(size.x, size.y, size.width, size.height, FILL_TRANSPARENT);                                                         
}

void GraphicEngine::printTest(){
    lcd.printString("SQUISHED", 1, 1);   
}

void GraphicEngine::print(){
    lcd.printString("DROWNED",1,1);   
}

void GraphicEngine::contrast(){
    lcd.setContrast(0.4);   
}

void GraphicEngine::clear(){
    lcd.clear();
}

void GraphicEngine::refresh(){
    lcd.refresh();
}

void GraphicEngine::backLightOn(){
    lcd.backLightOn();
}