SharpShooter
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
Diff: MainGame.cpp
- Revision:
- 10:92538c02e6c8
- Parent:
- 8:56a24df93680
- Child:
- 11:55b65415b6ba
--- a/MainGame.cpp Fri Oct 28 01:06:01 2016 +0000 +++ b/MainGame.cpp Fri Oct 28 19:02:28 2016 +0000 @@ -6,39 +6,102 @@ #include "Nav_Switch.h" #include "rtos.h" +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +///sd/wavfiles/def_swar.wav + /*INSTANTIATION*/ -DigitalOut myled(LED1); uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; Nav_Switch myNav( p24, p25, p26, p27, p28); //up, down, left, right, fire SDFileSystem sd(p5, p6, p7, p8, "sd"); AnalogOut DACout(p18); wave_player waver(&DACout); +/*STRUCT INITIALIZATION*/ +struct ObstLocation { + int x1, y1, x2, y2; +} + +struct TargetLocation { + int x,y,r; +} + +struct BulletLocation { + int x, topY, bottomY; +} + /*LOCAL VARIABLES*/ int numTries; int levelNum; -int bulletLocation; -int obstacleLocations; -int targetLocations; +BulletLocation bulletLocation; +ObstLocation * obstaclePtr; +TargetLocation * targetsPtr = new TargetLocation[3]; + + void startGame() { uLCD.locate(34,34); uLCD.set_font_size(4, 4); uLCD.printf("\nSharp Shooter!!\n"); + wait(0.1); FILE *wave_file; - wave_file=fopen("/sd/wavfiles/def_swar.wav","r"); + wave_file=fopen("/sd/wavfiles/pitfall.wav","r"); waver.play(wave_file); fclose(wave_file); } -void createTargets(); +void initializeLevel(int level) { + levelNum = level; + numTries = 10; + //draw header (level #, numTries) at the top + + + createTargets(); + createObstacles(level); + createShooter(); +} + +void createTargets() { + //draw all targets + //initialize targetPtr w locations of where theyre drawn +} + +void createShooter() { + +} + +void createObstacles(int num) { + Obstacle obsArr[num]; + obstaclePtr = new ObstLocation[num]; + //dummy x values, CHANGE LATER + if (num == 1) { + obsArr[0] = new Obstacle(15, 15, 115, 115, uLCD); + } else if (num == 2) { + obsArr[0] = new Obstacle(15, 15, 115, 115, uLCD); + obsArr[1] = new Obstacle(15, 15, 115, 115, uLCD); + } else if (num == 3) { + obsArr[0] = new Obstacle(15, 15, 115, 115, uLCD); + obsArr[1] = new Obstacle(15, 15, 115, 115, uLCD); + obsArr[2] = new Obstacle(15, 15, 115, 115, uLCD); + } + for (int i = 0; i < num; i++) { + obstaclePtr[i] = obsArr[i].getLocation(); + } +} + +void shoot() { + +} void checkIfHit(); void gameOver(); -void initializeLevel(); + void handleObstacleHit(); @@ -46,19 +109,24 @@ void redrawTarget(); -/*if(myNav.fire()) myled=!myled; - if(myNav.up()) myled=!myled; - if(myNav.down()) myled=!myled; - if(myNav.right()) myled=!myled; - if(myNav.left()) myled=!myled; - */ - int main() { - myled=0; + int currLevel = 1; while(1) { startGame(); + //uLCD.rectangle(0,0,100,100, 0xffffff); + initializeLevel(currLevel); + bool play = true; + while (play) { //actual game play code + //handle controls (5 tactile swtich) + if(myNav.fire()) shoot(); + if(myNav.right()) moveShooter(); + if(myNav.left()) myled=!myled; + + + + }