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.
main.cpp@2:006a2ddfabb6, 2019-03-20 (annotated)
- Committer:
- kocemax
- Date:
- Wed Mar 20 20:58:36 2019 +0000
- Revision:
- 2:006a2ddfabb6
- Parent:
- 1:b82c4c2de9a8
- Child:
- 3:fe856d0890ee
Added a ball, which is confined inside the screen. If the ball reaches the y level of the pad, the game is over. Have not added collision detection yet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kocemax | 0:2f0362fef062 | 1 | /* |
kocemax | 0:2f0362fef062 | 2 | ELEC2645 Embedded Systems Project |
kocemax | 0:2f0362fef062 | 3 | School of Electronic & Electrical Engineering University of Leeds |
kocemax | 0:2f0362fef062 | 4 | Name: Kostadin Chakarov |
kocemax | 0:2f0362fef062 | 5 | Username: el17kec |
kocemax | 0:2f0362fef062 | 6 | Student ID Number:201171978 Date:11/03/2019 |
kocemax | 0:2f0362fef062 | 7 | */ |
kocemax | 2:006a2ddfabb6 | 8 | // Breakout++ logo sprite |
kocemax | 1:b82c4c2de9a8 | 9 | const int breakout[10][75] = { |
kocemax | 1:b82c4c2de9a8 | 10 | { 1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0 }, |
kocemax | 1:b82c4c2de9a8 | 11 | { 1,0,1,0,0,1,0,0,1,0,1,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1 }, |
kocemax | 1:b82c4c2de9a8 | 12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0,0,0,1,0,0,0,0,0,0,1,0,0,0,0 }, |
kocemax | 1:b82c4c2de9a8 | 18 | { 1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0 }, |
kocemax | 1:b82c4c2de9a8 | 19 | { 1,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0 }, |
kocemax | 1:b82c4c2de9a8 | 20 | }; |
kocemax | 0:2f0362fef062 | 21 | |
kocemax | 1:b82c4c2de9a8 | 22 | ///////// pre-processor directives //////// |
kocemax | 0:2f0362fef062 | 23 | #include "mbed.h" |
kocemax | 1:b82c4c2de9a8 | 24 | #include "N5110.h" |
kocemax | 1:b82c4c2de9a8 | 25 | #include "Gamepad.h" |
kocemax | 2:006a2ddfabb6 | 26 | #include "PlayerControl.h" |
kocemax | 2:006a2ddfabb6 | 27 | #include "Ball.h" |
kocemax | 1:b82c4c2de9a8 | 28 | |
kocemax | 1:b82c4c2de9a8 | 29 | /////////////// objects /////////////// |
kocemax | 1:b82c4c2de9a8 | 30 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // K64F - pwr from 3V3 |
kocemax | 1:b82c4c2de9a8 | 31 | Gamepad pad; // Gamepad buttons |
kocemax | 1:b82c4c2de9a8 | 32 | PlayerControl cont; // Object for player |
kocemax | 2:006a2ddfabb6 | 33 | Ball ball; |
kocemax | 1:b82c4c2de9a8 | 34 | |
kocemax | 1:b82c4c2de9a8 | 35 | ///////////// function prototypes /////////////// |
kocemax | 1:b82c4c2de9a8 | 36 | void init(); |
kocemax | 1:b82c4c2de9a8 | 37 | void welcome(); |
kocemax | 1:b82c4c2de9a8 | 38 | void render(); |
kocemax | 0:2f0362fef062 | 39 | |
kocemax | 1:b82c4c2de9a8 | 40 | ///////////// functions //////////////// |
kocemax | 1:b82c4c2de9a8 | 41 | int main() |
kocemax | 1:b82c4c2de9a8 | 42 | { |
kocemax | 1:b82c4c2de9a8 | 43 | int fps = 10; |
kocemax | 1:b82c4c2de9a8 | 44 | init(); |
kocemax | 1:b82c4c2de9a8 | 45 | welcome(); // waiting for the user to start |
kocemax | 1:b82c4c2de9a8 | 46 | while(1) |
kocemax | 1:b82c4c2de9a8 | 47 | { |
kocemax | 1:b82c4c2de9a8 | 48 | render(); |
kocemax | 1:b82c4c2de9a8 | 49 | wait(1.0f/fps); |
kocemax | 2:006a2ddfabb6 | 50 | if (ball.endCondition(pad)){ |
kocemax | 2:006a2ddfabb6 | 51 | break; |
kocemax | 2:006a2ddfabb6 | 52 | } |
kocemax | 1:b82c4c2de9a8 | 53 | } |
kocemax | 2:006a2ddfabb6 | 54 | lcd.clear(); |
kocemax | 2:006a2ddfabb6 | 55 | lcd.printString("You Lose",20,3); |
kocemax | 2:006a2ddfabb6 | 56 | lcd.refresh(); |
kocemax | 1:b82c4c2de9a8 | 57 | } |
kocemax | 1:b82c4c2de9a8 | 58 | |
kocemax | 1:b82c4c2de9a8 | 59 | void init() |
kocemax | 1:b82c4c2de9a8 | 60 | { |
kocemax | 1:b82c4c2de9a8 | 61 | // need to initialise LCD and Gamepad |
kocemax | 1:b82c4c2de9a8 | 62 | lcd.init(); |
kocemax | 1:b82c4c2de9a8 | 63 | pad.init(); |
kocemax | 1:b82c4c2de9a8 | 64 | lcd.setContrast(0.55); // setting contrast to 55% seems good |
kocemax | 1:b82c4c2de9a8 | 65 | lcd.normalMode(); // normal colour mode |
kocemax | 1:b82c4c2de9a8 | 66 | lcd.setBrightness(0.5); // put LED backlight on 50% |
kocemax | 1:b82c4c2de9a8 | 67 | } |
kocemax | 1:b82c4c2de9a8 | 68 | |
kocemax | 1:b82c4c2de9a8 | 69 | void welcome() |
kocemax | 0:2f0362fef062 | 70 | { |
kocemax | 1:b82c4c2de9a8 | 71 | lcd.printString("Welcome to",12,0); |
kocemax | 1:b82c4c2de9a8 | 72 | // x origin, y origin, rows, cols, sprite |
kocemax | 1:b82c4c2de9a8 | 73 | lcd.drawSprite(5,15,10,75,(int *)breakout); |
kocemax | 1:b82c4c2de9a8 | 74 | lcd.printString("Press Start",9,4); |
kocemax | 1:b82c4c2de9a8 | 75 | lcd.refresh(); |
kocemax | 1:b82c4c2de9a8 | 76 | |
kocemax | 1:b82c4c2de9a8 | 77 | // flash the LEDs until start button is pressed |
kocemax | 1:b82c4c2de9a8 | 78 | while (pad.check_event(Gamepad::START_PRESSED) == false) |
kocemax | 1:b82c4c2de9a8 | 79 | { |
kocemax | 1:b82c4c2de9a8 | 80 | for (int i = 1; i < 7; i++) |
kocemax | 1:b82c4c2de9a8 | 81 | { |
kocemax | 1:b82c4c2de9a8 | 82 | pad.led(i,1); |
kocemax | 1:b82c4c2de9a8 | 83 | wait(0.1); |
kocemax | 1:b82c4c2de9a8 | 84 | pad.led(i,0); |
kocemax | 1:b82c4c2de9a8 | 85 | } |
kocemax | 1:b82c4c2de9a8 | 86 | } |
kocemax | 1:b82c4c2de9a8 | 87 | } |
kocemax | 0:2f0362fef062 | 88 | |
kocemax | 1:b82c4c2de9a8 | 89 | void render() { |
kocemax | 1:b82c4c2de9a8 | 90 | lcd.clear(); // initialise the LCD |
kocemax | 2:006a2ddfabb6 | 91 | cont.drawPlayer(lcd); |
kocemax | 2:006a2ddfabb6 | 92 | cont.controlPlayer(pad); |
kocemax | 2:006a2ddfabb6 | 93 | ball.drawBall(lcd); |
kocemax | 2:006a2ddfabb6 | 94 | ball.moveBall(); |
kocemax | 1:b82c4c2de9a8 | 95 | lcd.refresh(); |
kocemax | 0:2f0362fef062 | 96 | } |