SharpShooter
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
MainGame.cpp@11:55b65415b6ba, 2016-10-28 (annotated)
- Committer:
- jboettcher
- Date:
- Fri Oct 28 20:07:38 2016 +0000
- Revision:
- 11:55b65415b6ba
- Parent:
- 10:92538c02e6c8
- Child:
- 12:2f358065ba3f
First compile;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jboettcher | 0:137546fb5da1 | 1 | #include "mbed.h" |
jboettcher | 0:137546fb5da1 | 2 | #include "Speaker.h" |
jboettcher | 0:137546fb5da1 | 3 | #include "uLCD_4DGL.h" |
jboettcher | 0:137546fb5da1 | 4 | #include "SDFileSystem.h" |
jboettcher | 0:137546fb5da1 | 5 | #include "wave_player.h" |
jboettcher | 1:8a3fa9e90572 | 6 | #include "Nav_Switch.h" |
jboettcher | 1:8a3fa9e90572 | 7 | #include "rtos.h" |
jboettcher | 11:55b65415b6ba | 8 | #include "Obstacle.h" |
jboettcher | 11:55b65415b6ba | 9 | #include "Shooter.h" |
jboettcher | 11:55b65415b6ba | 10 | #include "Bullet.h" |
jboettcher | 0:137546fb5da1 | 11 | |
SeanBuckingham | 10:92538c02e6c8 | 12 | DigitalOut myled1(LED1); |
SeanBuckingham | 10:92538c02e6c8 | 13 | DigitalOut myled2(LED2); |
SeanBuckingham | 10:92538c02e6c8 | 14 | DigitalOut myled3(LED3); |
SeanBuckingham | 10:92538c02e6c8 | 15 | DigitalOut myled4(LED4); |
SeanBuckingham | 10:92538c02e6c8 | 16 | |
SeanBuckingham | 10:92538c02e6c8 | 17 | ///sd/wavfiles/def_swar.wav |
SeanBuckingham | 10:92538c02e6c8 | 18 | |
SeanBuckingham | 8:56a24df93680 | 19 | /*INSTANTIATION*/ |
jboettcher | 0:137546fb5da1 | 20 | uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; |
jboettcher | 1:8a3fa9e90572 | 21 | Nav_Switch myNav( p24, p25, p26, p27, p28); //up, down, left, right, fire |
SeanBuckingham | 8:56a24df93680 | 22 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
jboettcher | 0:137546fb5da1 | 23 | AnalogOut DACout(p18); |
jboettcher | 0:137546fb5da1 | 24 | wave_player waver(&DACout); |
jboettcher | 0:137546fb5da1 | 25 | |
SeanBuckingham | 10:92538c02e6c8 | 26 | /*STRUCT INITIALIZATION*/ |
SeanBuckingham | 10:92538c02e6c8 | 27 | struct ObstLocation { |
SeanBuckingham | 10:92538c02e6c8 | 28 | int x1, y1, x2, y2; |
jboettcher | 11:55b65415b6ba | 29 | }; |
SeanBuckingham | 10:92538c02e6c8 | 30 | |
SeanBuckingham | 10:92538c02e6c8 | 31 | struct TargetLocation { |
SeanBuckingham | 10:92538c02e6c8 | 32 | int x,y,r; |
jboettcher | 11:55b65415b6ba | 33 | }; |
jboettcher | 11:55b65415b6ba | 34 | /* |
SeanBuckingham | 10:92538c02e6c8 | 35 | struct BulletLocation { |
SeanBuckingham | 10:92538c02e6c8 | 36 | int x, topY, bottomY; |
jboettcher | 11:55b65415b6ba | 37 | }; |
jboettcher | 11:55b65415b6ba | 38 | */ |
SeanBuckingham | 8:56a24df93680 | 39 | /*LOCAL VARIABLES*/ |
SeanBuckingham | 8:56a24df93680 | 40 | int numTries; |
SeanBuckingham | 8:56a24df93680 | 41 | int levelNum; |
SeanBuckingham | 10:92538c02e6c8 | 42 | BulletLocation bulletLocation; |
SeanBuckingham | 10:92538c02e6c8 | 43 | ObstLocation * obstaclePtr; |
SeanBuckingham | 10:92538c02e6c8 | 44 | TargetLocation * targetsPtr = new TargetLocation[3]; |
SeanBuckingham | 10:92538c02e6c8 | 45 | |
SeanBuckingham | 10:92538c02e6c8 | 46 | |
SeanBuckingham | 8:56a24df93680 | 47 | |
SeanBuckingham | 8:56a24df93680 | 48 | void startGame() { |
SeanBuckingham | 8:56a24df93680 | 49 | uLCD.locate(34,34); |
SeanBuckingham | 8:56a24df93680 | 50 | uLCD.set_font_size(4, 4); |
SeanBuckingham | 8:56a24df93680 | 51 | uLCD.printf("\nSharp Shooter!!\n"); |
SeanBuckingham | 10:92538c02e6c8 | 52 | wait(0.1); |
SeanBuckingham | 8:56a24df93680 | 53 | |
SeanBuckingham | 8:56a24df93680 | 54 | FILE *wave_file; |
SeanBuckingham | 10:92538c02e6c8 | 55 | wave_file=fopen("/sd/wavfiles/pitfall.wav","r"); |
SeanBuckingham | 8:56a24df93680 | 56 | waver.play(wave_file); |
SeanBuckingham | 8:56a24df93680 | 57 | fclose(wave_file); |
jboettcher | 0:137546fb5da1 | 58 | } |
jboettcher | 0:137546fb5da1 | 59 | |
SeanBuckingham | 10:92538c02e6c8 | 60 | void initializeLevel(int level) { |
SeanBuckingham | 10:92538c02e6c8 | 61 | levelNum = level; |
SeanBuckingham | 10:92538c02e6c8 | 62 | numTries = 10; |
SeanBuckingham | 10:92538c02e6c8 | 63 | //draw header (level #, numTries) at the top |
SeanBuckingham | 10:92538c02e6c8 | 64 | |
jboettcher | 11:55b65415b6ba | 65 | //createTargets(); |
jboettcher | 11:55b65415b6ba | 66 | //createObstacles(level); |
jboettcher | 11:55b65415b6ba | 67 | //createShooter(); |
SeanBuckingham | 10:92538c02e6c8 | 68 | } |
SeanBuckingham | 10:92538c02e6c8 | 69 | |
SeanBuckingham | 10:92538c02e6c8 | 70 | void createTargets() { |
SeanBuckingham | 10:92538c02e6c8 | 71 | //draw all targets |
SeanBuckingham | 10:92538c02e6c8 | 72 | //initialize targetPtr w locations of where theyre drawn |
SeanBuckingham | 10:92538c02e6c8 | 73 | } |
SeanBuckingham | 10:92538c02e6c8 | 74 | |
SeanBuckingham | 10:92538c02e6c8 | 75 | void createShooter() { |
SeanBuckingham | 10:92538c02e6c8 | 76 | |
SeanBuckingham | 10:92538c02e6c8 | 77 | } |
jboettcher | 11:55b65415b6ba | 78 | /* |
SeanBuckingham | 10:92538c02e6c8 | 79 | void createObstacles(int num) { |
SeanBuckingham | 10:92538c02e6c8 | 80 | Obstacle obsArr[num]; |
SeanBuckingham | 10:92538c02e6c8 | 81 | obstaclePtr = new ObstLocation[num]; |
SeanBuckingham | 10:92538c02e6c8 | 82 | //dummy x values, CHANGE LATER |
SeanBuckingham | 10:92538c02e6c8 | 83 | if (num == 1) { |
SeanBuckingham | 10:92538c02e6c8 | 84 | obsArr[0] = new Obstacle(15, 15, 115, 115, uLCD); |
SeanBuckingham | 10:92538c02e6c8 | 85 | } else if (num == 2) { |
SeanBuckingham | 10:92538c02e6c8 | 86 | obsArr[0] = new Obstacle(15, 15, 115, 115, uLCD); |
SeanBuckingham | 10:92538c02e6c8 | 87 | obsArr[1] = new Obstacle(15, 15, 115, 115, uLCD); |
SeanBuckingham | 10:92538c02e6c8 | 88 | } else if (num == 3) { |
SeanBuckingham | 10:92538c02e6c8 | 89 | obsArr[0] = new Obstacle(15, 15, 115, 115, uLCD); |
SeanBuckingham | 10:92538c02e6c8 | 90 | obsArr[1] = new Obstacle(15, 15, 115, 115, uLCD); |
SeanBuckingham | 10:92538c02e6c8 | 91 | obsArr[2] = new Obstacle(15, 15, 115, 115, uLCD); |
SeanBuckingham | 10:92538c02e6c8 | 92 | } |
SeanBuckingham | 10:92538c02e6c8 | 93 | for (int i = 0; i < num; i++) { |
SeanBuckingham | 10:92538c02e6c8 | 94 | obstaclePtr[i] = obsArr[i].getLocation(); |
SeanBuckingham | 10:92538c02e6c8 | 95 | } |
SeanBuckingham | 10:92538c02e6c8 | 96 | } |
jboettcher | 11:55b65415b6ba | 97 | */ |
SeanBuckingham | 10:92538c02e6c8 | 98 | void shoot() { |
SeanBuckingham | 10:92538c02e6c8 | 99 | |
SeanBuckingham | 10:92538c02e6c8 | 100 | } |
SeanBuckingham | 8:56a24df93680 | 101 | |
SeanBuckingham | 8:56a24df93680 | 102 | void checkIfHit(); |
SeanBuckingham | 8:56a24df93680 | 103 | |
SeanBuckingham | 8:56a24df93680 | 104 | void gameOver(); |
SeanBuckingham | 8:56a24df93680 | 105 | |
SeanBuckingham | 10:92538c02e6c8 | 106 | |
SeanBuckingham | 8:56a24df93680 | 107 | |
SeanBuckingham | 8:56a24df93680 | 108 | void handleObstacleHit(); |
SeanBuckingham | 8:56a24df93680 | 109 | |
SeanBuckingham | 8:56a24df93680 | 110 | void handleTargetHit(); |
SeanBuckingham | 8:56a24df93680 | 111 | |
SeanBuckingham | 8:56a24df93680 | 112 | void redrawTarget(); |
SeanBuckingham | 8:56a24df93680 | 113 | |
jboettcher | 0:137546fb5da1 | 114 | int main() { |
SeanBuckingham | 10:92538c02e6c8 | 115 | int currLevel = 1; |
jboettcher | 1:8a3fa9e90572 | 116 | while(1) { |
jboettcher | 1:8a3fa9e90572 | 117 | |
SeanBuckingham | 8:56a24df93680 | 118 | startGame(); |
SeanBuckingham | 10:92538c02e6c8 | 119 | //uLCD.rectangle(0,0,100,100, 0xffffff); |
SeanBuckingham | 10:92538c02e6c8 | 120 | initializeLevel(currLevel); |
SeanBuckingham | 10:92538c02e6c8 | 121 | bool play = true; |
SeanBuckingham | 8:56a24df93680 | 122 | |
jboettcher | 11:55b65415b6ba | 123 | wait(100); |
jboettcher | 11:55b65415b6ba | 124 | |
jboettcher | 11:55b65415b6ba | 125 | /* |
SeanBuckingham | 10:92538c02e6c8 | 126 | while (play) { //actual game play code |
SeanBuckingham | 10:92538c02e6c8 | 127 | //handle controls (5 tactile swtich) |
SeanBuckingham | 10:92538c02e6c8 | 128 | if(myNav.fire()) shoot(); |
SeanBuckingham | 10:92538c02e6c8 | 129 | if(myNav.right()) moveShooter(); |
SeanBuckingham | 10:92538c02e6c8 | 130 | if(myNav.left()) myled=!myled; |
SeanBuckingham | 10:92538c02e6c8 | 131 | |
SeanBuckingham | 10:92538c02e6c8 | 132 | |
SeanBuckingham | 10:92538c02e6c8 | 133 | |
SeanBuckingham | 10:92538c02e6c8 | 134 | } |
SeanBuckingham | 8:56a24df93680 | 135 | |
jboettcher | 11:55b65415b6ba | 136 | */ |
SeanBuckingham | 8:56a24df93680 | 137 | |
SeanBuckingham | 8:56a24df93680 | 138 | |
SeanBuckingham | 8:56a24df93680 | 139 | |
SeanBuckingham | 8:56a24df93680 | 140 | |
SeanBuckingham | 8:56a24df93680 | 141 | } |
jboettcher | 0:137546fb5da1 | 142 | } |