SharpShooter
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
MainGame.cpp
- Committer:
- SeanBuckingham
- Date:
- 2016-10-28
- Revision:
- 10:92538c02e6c8
- Parent:
- 8:56a24df93680
- Child:
- 11:55b65415b6ba
File content as of revision 10:92538c02e6c8:
#include "mbed.h" #include "Speaker.h" #include "uLCD_4DGL.h" #include "SDFileSystem.h" #include "wave_player.h" #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*/ 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; 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/pitfall.wav","r"); waver.play(wave_file); fclose(wave_file); } 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 handleObstacleHit(); void handleTargetHit(); void redrawTarget(); int main() { 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; } } }