ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19tb

Dependencies:   mbed

Committer:
el19tb
Date:
Wed May 13 03:59:27 2020 +0000
Revision:
13:cd6d2f999057
Parent:
8:52794de935b2
Child:
14:6fe667ec957e
the sprites appear to the screen, updated GraphicEngine

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el19tb 3:648c9d5001be 1 #include "GraphicEngine.h"
el19tb 3:648c9d5001be 2
el19tb 3:648c9d5001be 3 N5110 lcd;
el19tb 3:648c9d5001be 4
el19tb 4:aae7f8d4ab78 5 // TO DO:
el19tb 4:aae7f8d4ab78 6 // -> make multiple lanes of cars (first manually then automatically)
el19tb 4:aae7f8d4ab78 7 // -> make one lane go other direction
el19tb 4:aae7f8d4ab78 8 // -> make a safety lane
el19tb 4:aae7f8d4ab78 9 // -> make a logs
el19tb 4:aae7f8d4ab78 10 // -> make turtles
el19tb 4:aae7f8d4ab78 11 // -> make the ocean (if collision with ocean then dead)
el19tb 4:aae7f8d4ab78 12 // -> make multiple lives
el19tb 4:aae7f8d4ab78 13 // -> point system
el19tb 4:aae7f8d4ab78 14 // -> make the sprite images
el19tb 4:aae7f8d4ab78 15 // -> make background object (sprite of entire screen)
el19tb 4:aae7f8d4ab78 16 // -> make menu screen
el19tb 4:aae7f8d4ab78 17 // -> collision
el19tb 4:aae7f8d4ab78 18 // -> make sprite of safety lanes
el19tb 4:aae7f8d4ab78 19 // -> make snake object
el19tb 5:6e3afee7eac3 20 // -> make turtles disappear after a certain time
el19tb 4:aae7f8d4ab78 21 // BONUS:
el19tb 4:aae7f8d4ab78 22 // --> make multiple levels
el19tb 4:aae7f8d4ab78 23 // --> time constraint
el19tb 5:6e3afee7eac3 24 // -> crocodile (level 3) only (jump on body)
el19tb 5:6e3afee7eac3 25 // -> snake on log (level 3)
el19tb 5:6e3afee7eac3 26
el19tb 5:6e3afee7eac3 27 GraphicEngine::GraphicEngine(Chicken *chicken){
el19tb 5:6e3afee7eac3 28 this->chick = chicken;
el19tb 5:6e3afee7eac3 29 }
el19tb 5:6e3afee7eac3 30
el19tb 5:6e3afee7eac3 31 void GraphicEngine::init(){
el19tb 5:6e3afee7eac3 32 lcd.init();
el19tb 5:6e3afee7eac3 33 }
el19tb 5:6e3afee7eac3 34
el19tb 5:6e3afee7eac3 35 void GraphicEngine::showChicken(){
el19tb 5:6e3afee7eac3 36 //fill the chicken with black color
el19tb 5:6e3afee7eac3 37 lcd.drawRect(chick->x, chick->y, chick->width, chick->width, FILL_BLACK);
el19tb 5:6e3afee7eac3 38 }
el19tb 4:aae7f8d4ab78 39
el19tb 4:aae7f8d4ab78 40 void GraphicEngine::showCar(Car *car){
el19tb 5:6e3afee7eac3 41 // safety lane
el19tb 5:6e3afee7eac3 42 lcd.drawRect(0, 48 - 4, 84, 4, FILL_TRANSPARENT);
el19tb 5:6e3afee7eac3 43 lcd.drawRect(0, 48 - 4*6, 84, 4, FILL_TRANSPARENT);
el19tb 5:6e3afee7eac3 44
el19tb 5:6e3afee7eac3 45 // draw to screen
el19tb 5:6e3afee7eac3 46 // create an enum to determine the vehicle type
el19tb 7:1dce07fd0867 47 for(int y = 0; y < 4; y++){
el19tb 5:6e3afee7eac3 48 showIndividualCar(&car[y]);
el19tb 5:6e3afee7eac3 49 }
el19tb 5:6e3afee7eac3 50 }
el19tb 5:6e3afee7eac3 51
el19tb 5:6e3afee7eac3 52 void GraphicEngine::showIndividualCar(Car *car){
el19tb 5:6e3afee7eac3 53 DrawCar temp_car;
el19tb 5:6e3afee7eac3 54
el19tb 5:6e3afee7eac3 55 temp_car.x = car->vehicle.x;
el19tb 5:6e3afee7eac3 56 temp_car.y = car->vehicle.y;
el19tb 5:6e3afee7eac3 57 temp_car.width = car->vehicle.width;
el19tb 5:6e3afee7eac3 58 temp_car.height = car->vehicle.height;
el19tb 5:6e3afee7eac3 59
el19tb 5:6e3afee7eac3 60 displayCar(temp_car);
el19tb 5:6e3afee7eac3 61 }
el19tb 5:6e3afee7eac3 62
el19tb 13:cd6d2f999057 63
el19tb 13:cd6d2f999057 64 void CrossyChicken::drawSprites(char obj, int x, int y, int rows, int cols)
el19tb 13:cd6d2f999057 65 {
el19tb 13:cd6d2f999057 66 switch(obj)
el19tb 13:cd6d2f999057 67 {
el19tb 13:cd6d2f999057 68 case 'L':
el19tb 13:cd6d2f999057 69 lcd.drawSprite(x, y, rows, cols, (int *)left_racer);
el19tb 13:cd6d2f999057 70
el19tb 13:cd6d2f999057 71 case 'R' :
el19tb 13:cd6d2f999057 72 lcd.drawSprite(x, y, rows, cols, (int *)right_racer);
el19tb 13:cd6d2f999057 73
el19tb 13:cd6d2f999057 74 case 'B':
el19tb 13:cd6d2f999057 75 lcd.drawSprite(x, y, rows, cols, (int *)bus);
el19tb 13:cd6d2f999057 76
el19tb 13:cd6d2f999057 77 case 'N':
el19tb 13:cd6d2f999057 78 lcd.drawSprite(x, y, rows, cols, (int *)right_normal);
el19tb 13:cd6d2f999057 79
el19tb 13:cd6d2f999057 80 case 'X':
el19tb 13:cd6d2f999057 81 lcd.drawSprite(x, y, rows, cols, (int *)left_normal);
el19tb 13:cd6d2f999057 82 }
el19tb 13:cd6d2f999057 83 }
el19tb 13:cd6d2f999057 84
el19tb 13:cd6d2f999057 85
el19tb 5:6e3afee7eac3 86 void GraphicEngine::displayCar(DrawCar &size){
el19tb 8:52794de935b2 87 lcd.drawRect(size.x, size.y, size.width, size.height, FILL_TRANSPARENT);
el19tb 5:6e3afee7eac3 88 }
el19tb 5:6e3afee7eac3 89
el19tb 5:6e3afee7eac3 90 void GraphicEngine::printTest(){
el19tb 8:52794de935b2 91 lcd.printString("SQUISHED", 1, 1);
el19tb 8:52794de935b2 92 }
el19tb 8:52794de935b2 93
el19tb 8:52794de935b2 94 void GraphicEngine::print(){
el19tb 8:52794de935b2 95 lcd.printString("DROWNED",1,1);
el19tb 3:648c9d5001be 96 }
el19tb 3:648c9d5001be 97
el19tb 3:648c9d5001be 98 void GraphicEngine::contrast(){
el19tb 3:648c9d5001be 99 lcd.setContrast(0.4);
el19tb 3:648c9d5001be 100 }
el19tb 3:648c9d5001be 101
el19tb 3:648c9d5001be 102 void GraphicEngine::clear(){
el19tb 3:648c9d5001be 103 lcd.clear();
el19tb 3:648c9d5001be 104 }
el19tb 3:648c9d5001be 105
el19tb 3:648c9d5001be 106 void GraphicEngine::refresh(){
el19tb 3:648c9d5001be 107 lcd.refresh();
el19tb 3:648c9d5001be 108 }
el19tb 3:648c9d5001be 109
el19tb 3:648c9d5001be 110 void GraphicEngine::backLightOn(){
el19tb 3:648c9d5001be 111 lcd.backLightOn();
el19tb 3:648c9d5001be 112 }