Kostadin Chakarov / Mbed 2 deprecated el17kec

Dependencies:   mbed

Committer:
kocemax
Date:
Tue Mar 26 09:16:35 2019 +0000
Revision:
5:12c179da4788
Parent:
4:0e01cbb95434
Child:
6:39bda45efeed
Made a struct to store centerpoints, from which I can generate the map by storing the x and y in a struct within a vector. Now need to introduce collision between bricks and ball.

Who changed what in which revision?

UserRevisionLine numberNew 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 { 1,1,0,0,0,0,1,0,0,1,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0 },
kocemax 1:b82c4c2de9a8 13 { 1,1,0,1,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4c2de9a8 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 5:12c179da4788 27 #include "Ball.h"
kocemax 5:12c179da4788 28 #include "Map.h"
kocemax 1:b82c4c2de9a8 29
kocemax 4:0e01cbb95434 30 const int fps = 10; //sets the fps of the game doesn't change
kocemax 4:0e01cbb95434 31
kocemax 1:b82c4c2de9a8 32 /////////////// objects ///////////////
kocemax 1:b82c4c2de9a8 33 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // K64F - pwr from 3V3
kocemax 1:b82c4c2de9a8 34 Gamepad pad; // Gamepad buttons
kocemax 1:b82c4c2de9a8 35 PlayerControl cont; // Object for player
kocemax 2:006a2ddfabb6 36 Ball ball;
kocemax 5:12c179da4788 37 Map map;
kocemax 1:b82c4c2de9a8 38
kocemax 1:b82c4c2de9a8 39 ///////////// function prototypes ///////////////
kocemax 1:b82c4c2de9a8 40 void init();
kocemax 1:b82c4c2de9a8 41 void welcome();
kocemax 1:b82c4c2de9a8 42 void render();
kocemax 0:2f0362fef062 43
kocemax 1:b82c4c2de9a8 44 ///////////// functions ////////////////
kocemax 1:b82c4c2de9a8 45 int main()
kocemax 1:b82c4c2de9a8 46 {
kocemax 1:b82c4c2de9a8 47 init();
kocemax 1:b82c4c2de9a8 48 welcome(); // waiting for the user to start
kocemax 5:12c179da4788 49
kocemax 4:0e01cbb95434 50 render();
kocemax 1:b82c4c2de9a8 51 }
kocemax 1:b82c4c2de9a8 52
kocemax 1:b82c4c2de9a8 53 void init()
kocemax 1:b82c4c2de9a8 54 {
kocemax 1:b82c4c2de9a8 55 // need to initialise LCD and Gamepad
kocemax 1:b82c4c2de9a8 56 lcd.init();
kocemax 1:b82c4c2de9a8 57 pad.init();
kocemax 1:b82c4c2de9a8 58 lcd.setContrast(0.55); // setting contrast to 55% seems good
kocemax 1:b82c4c2de9a8 59 lcd.normalMode(); // normal colour mode
kocemax 1:b82c4c2de9a8 60 lcd.setBrightness(0.5); // put LED backlight on 50%
kocemax 1:b82c4c2de9a8 61 }
kocemax 1:b82c4c2de9a8 62
kocemax 1:b82c4c2de9a8 63 void welcome()
kocemax 0:2f0362fef062 64 {
kocemax 1:b82c4c2de9a8 65 lcd.printString("Welcome to",12,0);
kocemax 1:b82c4c2de9a8 66 // x origin, y origin, rows, cols, sprite
kocemax 1:b82c4c2de9a8 67 lcd.drawSprite(5,15,10,75,(int *)breakout);
kocemax 1:b82c4c2de9a8 68 lcd.printString("Press Start",9,4);
kocemax 1:b82c4c2de9a8 69 lcd.refresh();
kocemax 1:b82c4c2de9a8 70
kocemax 1:b82c4c2de9a8 71 // flash the LEDs until start button is pressed
kocemax 1:b82c4c2de9a8 72 while (pad.check_event(Gamepad::START_PRESSED) == false)
kocemax 1:b82c4c2de9a8 73 {
kocemax 1:b82c4c2de9a8 74 for (int i = 1; i < 7; i++)
kocemax 1:b82c4c2de9a8 75 {
kocemax 5:12c179da4788 76 pad.led(i,1);
kocemax 5:12c179da4788 77 wait(0.1);
kocemax 5:12c179da4788 78 pad.led(i,0);
kocemax 1:b82c4c2de9a8 79 }
kocemax 1:b82c4c2de9a8 80 }
kocemax 1:b82c4c2de9a8 81 }
kocemax 0:2f0362fef062 82
kocemax 1:b82c4c2de9a8 83 void render() {
kocemax 5:12c179da4788 84 map.setCenterpoints();
kocemax 4:0e01cbb95434 85 while(1)
kocemax 4:0e01cbb95434 86 {
kocemax 4:0e01cbb95434 87 lcd.clear(); // initialise the LCD
kocemax 5:12c179da4788 88 map.drawMap(lcd);
kocemax 4:0e01cbb95434 89 cont.drawPlayer(lcd);
kocemax 4:0e01cbb95434 90 cont.controlPlayer(pad);
kocemax 4:0e01cbb95434 91 cont.get_padPos(pad);
kocemax 4:0e01cbb95434 92 ball.drawBall(lcd);
kocemax 4:0e01cbb95434 93 ball.get_ballPos(pad);
kocemax 4:0e01cbb95434 94 ball.moveBall();
kocemax 4:0e01cbb95434 95 ball.hitPad(pad);
kocemax 4:0e01cbb95434 96 lcd.refresh();
kocemax 4:0e01cbb95434 97 ball.endCondition(pad, lcd);
kocemax 4:0e01cbb95434 98 wait(1.0f/fps);
kocemax 4:0e01cbb95434 99 }
kocemax 0:2f0362fef062 100 }