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@16:8a65cccd9685, 2020-05-13 (annotated)
- Committer:
- el19tb
- Date:
- Wed May 13 23:07:05 2020 +0000
- Revision:
- 16:8a65cccd9685
- Parent:
- 15:b15bf9357cd9
- Child:
- 17:67dbdfcdcec2
created safety lanes for frog to stay on to avoid obstacles
Who changed what in which revision?
User | Revision | Line number | New 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 | 16:8a65cccd9685 | 40 | void GraphicEngine::drawFirstSafetyBackground(int x, int row) |
el19tb | 16:8a65cccd9685 | 41 | { |
el19tb | 16:8a65cccd9685 | 42 | lcd.drawSprite(x, 48 - 4*row, 4, 4, (int *)safety_lanes_one); |
el19tb | 16:8a65cccd9685 | 43 | } |
el19tb | 16:8a65cccd9685 | 44 | |
el19tb | 16:8a65cccd9685 | 45 | void GraphicEngine::drawSecondSafetyBackground(int x, int row) |
el19tb | 16:8a65cccd9685 | 46 | { |
el19tb | 16:8a65cccd9685 | 47 | lcd.drawSprite(x, 48 - 4*row, 4, 4, (int *)safety_lane_two); |
el19tb | 16:8a65cccd9685 | 48 | ) |
el19tb | 16:8a65cccd9685 | 49 | |
el19tb | 15:b15bf9357cd9 | 50 | // this is just going to be white blocks |
el19tb | 15:b15bf9357cd9 | 51 | // road == '.' |
el19tb | 15:b15bf9357cd9 | 52 | void GraphhicEngine::drawRoads(int row) |
el19tb | 15:b15bf9357cd9 | 53 | { |
el19tb | 15:b15bf9357cd9 | 54 | // draw across the screen width |
el19tb | 15:b15bf9357cd9 | 55 | for(int a = 0; a < 22; a++){ |
el19tb | 15:b15bf9357cd9 | 56 | showEachRoad(a, row); // x pos is the value of a |
el19tb | 15:b15bf9357cd9 | 57 | } |
el19tb | 15:b15bf9357cd9 | 58 | } |
el19tb | 15:b15bf9357cd9 | 59 | |
el19tb | 15:b15bf9357cd9 | 60 | void GraphicEngine::showEachRoad(int x, int row) |
el19tb | 15:b15bf9357cd9 | 61 | { |
el19tb | 15:b15bf9357cd9 | 62 | lcd.drawSprite(x, 48 - 4*row,4, 4, (int *)road); |
el19tb | 15:b15bf9357cd9 | 63 | } |
el19tb | 15:b15bf9357cd9 | 64 | |
el19tb | 4:aae7f8d4ab78 | 65 | void GraphicEngine::showCar(Car *car){ |
el19tb | 5:6e3afee7eac3 | 66 | // safety lane |
el19tb | 5:6e3afee7eac3 | 67 | lcd.drawRect(0, 48 - 4, 84, 4, FILL_TRANSPARENT); |
el19tb | 5:6e3afee7eac3 | 68 | lcd.drawRect(0, 48 - 4*6, 84, 4, FILL_TRANSPARENT); |
el19tb | 5:6e3afee7eac3 | 69 | |
el19tb | 15:b15bf9357cd9 | 70 | // draw to screen0 |
el19tb | 5:6e3afee7eac3 | 71 | // create an enum to determine the vehicle type |
el19tb | 7:1dce07fd0867 | 72 | for(int y = 0; y < 4; y++){ |
el19tb | 5:6e3afee7eac3 | 73 | showIndividualCar(&car[y]); |
el19tb | 5:6e3afee7eac3 | 74 | } |
el19tb | 5:6e3afee7eac3 | 75 | } |
el19tb | 5:6e3afee7eac3 | 76 | |
el19tb | 5:6e3afee7eac3 | 77 | void GraphicEngine::showIndividualCar(Car *car){ |
el19tb | 5:6e3afee7eac3 | 78 | DrawCar temp_car; |
el19tb | 5:6e3afee7eac3 | 79 | |
el19tb | 5:6e3afee7eac3 | 80 | temp_car.x = car->vehicle.x; |
el19tb | 5:6e3afee7eac3 | 81 | temp_car.y = car->vehicle.y; |
el19tb | 5:6e3afee7eac3 | 82 | temp_car.width = car->vehicle.width; |
el19tb | 5:6e3afee7eac3 | 83 | temp_car.height = car->vehicle.height; |
el19tb | 5:6e3afee7eac3 | 84 | |
el19tb | 5:6e3afee7eac3 | 85 | displayCar(temp_car); |
el19tb | 5:6e3afee7eac3 | 86 | } |
el19tb | 5:6e3afee7eac3 | 87 | |
el19tb | 13:cd6d2f999057 | 88 | |
el19tb | 14:6fe667ec957e | 89 | void GraphicEngine::drawVehicleSprites(char obj, int x, int y, int rows, int cols) |
el19tb | 13:cd6d2f999057 | 90 | { |
el19tb | 13:cd6d2f999057 | 91 | switch(obj) |
el19tb | 13:cd6d2f999057 | 92 | { |
el19tb | 13:cd6d2f999057 | 93 | case 'L': |
el19tb | 13:cd6d2f999057 | 94 | lcd.drawSprite(x, y, rows, cols, (int *)left_racer); |
el19tb | 13:cd6d2f999057 | 95 | |
el19tb | 13:cd6d2f999057 | 96 | case 'R' : |
el19tb | 13:cd6d2f999057 | 97 | lcd.drawSprite(x, y, rows, cols, (int *)right_racer); |
el19tb | 13:cd6d2f999057 | 98 | |
el19tb | 13:cd6d2f999057 | 99 | case 'B': |
el19tb | 13:cd6d2f999057 | 100 | lcd.drawSprite(x, y, rows, cols, (int *)bus); |
el19tb | 13:cd6d2f999057 | 101 | |
el19tb | 13:cd6d2f999057 | 102 | case 'N': |
el19tb | 13:cd6d2f999057 | 103 | lcd.drawSprite(x, y, rows, cols, (int *)right_normal); |
el19tb | 13:cd6d2f999057 | 104 | |
el19tb | 13:cd6d2f999057 | 105 | case 'X': |
el19tb | 13:cd6d2f999057 | 106 | lcd.drawSprite(x, y, rows, cols, (int *)left_normal); |
el19tb | 13:cd6d2f999057 | 107 | } |
el19tb | 13:cd6d2f999057 | 108 | } |
el19tb | 13:cd6d2f999057 | 109 | |
el19tb | 14:6fe667ec957e | 110 | |
el19tb | 14:6fe667ec957e | 111 | // water = ',' |
el19tb | 14:6fe667ec957e | 112 | void GraphicEngine::drawWater(char water, int x, int y, int row, in col) |
el19tb | 14:6fe667ec957e | 113 | { |
el19tb | 14:6fe667ec957e | 114 | int rand_water = 0; |
el19tb | 14:6fe667ec957e | 115 | rand_water = (rand() % 3) + 1; |
el19tb | 14:6fe667ec957e | 116 | |
el19tb | 15:b15bf9357cd9 | 117 | // for design purposes the water will have different sprites |
el19tb | 14:6fe667ec957e | 118 | switch(rand_water) |
el19tb | 14:6fe667ec957e | 119 | { |
el19tb | 15:b15bf9357cd9 | 120 | case 1: |
el19tb | 15:b15bf9357cd9 | 121 | lcd.drawSprite(x, y, rows, cols, (int *)first_water); |
el19tb | 15:b15bf9357cd9 | 122 | |
el19tb | 15:b15bf9357cd9 | 123 | case 2: |
el19tb | 15:b15bf9357cd9 | 124 | lcd.drawSprite(x, y, rows, cols, (int *)second_water); |
el19tb | 15:b15bf9357cd9 | 125 | |
el19tb | 15:b15bf9357cd9 | 126 | case 3: |
el19tb | 15:b15bf9357cd9 | 127 | lcd.drawSprite(x, y, rows, cols, (int *)third_water); |
el19tb | 15:b15bf9357cd9 | 128 | } |
el19tb | 14:6fe667ec957e | 129 | } |
el19tb | 13:cd6d2f999057 | 130 | |
el19tb | 15:b15bf9357cd9 | 131 | void GraphicEngine::displayCar(DrawCar &size) |
el19tb | 15:b15bf9357cd9 | 132 | { |
el19tb | 8:52794de935b2 | 133 | lcd.drawRect(size.x, size.y, size.width, size.height, FILL_TRANSPARENT); |
el19tb | 5:6e3afee7eac3 | 134 | } |
el19tb | 5:6e3afee7eac3 | 135 | |
el19tb | 5:6e3afee7eac3 | 136 | void GraphicEngine::printTest(){ |
el19tb | 8:52794de935b2 | 137 | lcd.printString("SQUISHED", 1, 1); |
el19tb | 8:52794de935b2 | 138 | } |
el19tb | 8:52794de935b2 | 139 | |
el19tb | 8:52794de935b2 | 140 | void GraphicEngine::print(){ |
el19tb | 8:52794de935b2 | 141 | lcd.printString("DROWNED",1,1); |
el19tb | 3:648c9d5001be | 142 | } |
el19tb | 3:648c9d5001be | 143 | |
el19tb | 3:648c9d5001be | 144 | void GraphicEngine::contrast(){ |
el19tb | 3:648c9d5001be | 145 | lcd.setContrast(0.4); |
el19tb | 3:648c9d5001be | 146 | } |
el19tb | 3:648c9d5001be | 147 | |
el19tb | 3:648c9d5001be | 148 | void GraphicEngine::clear(){ |
el19tb | 3:648c9d5001be | 149 | lcd.clear(); |
el19tb | 3:648c9d5001be | 150 | } |
el19tb | 3:648c9d5001be | 151 | |
el19tb | 3:648c9d5001be | 152 | void GraphicEngine::refresh(){ |
el19tb | 3:648c9d5001be | 153 | lcd.refresh(); |
el19tb | 3:648c9d5001be | 154 | } |
el19tb | 3:648c9d5001be | 155 | |
el19tb | 3:648c9d5001be | 156 | void GraphicEngine::backLightOn(){ |
el19tb | 3:648c9d5001be | 157 | lcd.backLightOn(); |
el19tb | 3:648c9d5001be | 158 | } |