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
GraphicEngine/GraphicEngine.cpp
- Committer:
- el19tb
- Date:
- 2020-05-13
- Revision:
- 15:b15bf9357cd9
- Parent:
- 14:6fe667ec957e
- Child:
- 16:8a65cccd9685
File content as of revision 15:b15bf9357cd9:
#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);
}
// this is just going to be white blocks
// road == '.'
void GraphhicEngine::drawRoads(int row)
{
// draw across the screen width
for(int a = 0; a < 22; a++){
showEachRoad(a, row); // x pos is the value of a
}
}
void GraphicEngine::showEachRoad(int x, int row)
{
lcd.drawSprite(x, 48 - 4*row,4, 4, (int *)road);
}
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 screen0
// 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);
}
}
// 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 different sprites
switch(rand_water)
{
case 1:
lcd.drawSprite(x, y, rows, cols, (int *)first_water);
case 2:
lcd.drawSprite(x, y, rows, cols, (int *)second_water);
case 3:
lcd.drawSprite(x, y, rows, cols, (int *)third_water);
}
}
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();
}