mbed tokyotech
Dependencies: C12832 EthernetInterface HTTPClient USBDevice mbed-rtos mbed Speaker
Diff: main.cpp
- Revision:
- 3:6d2b9fcb8fa8
- Parent:
- 2:d26f6e124f1a
- Child:
- 4:52109f4cb132
--- a/main.cpp Thu Feb 04 07:49:35 2016 +0000 +++ b/main.cpp Thu Feb 11 00:52:47 2016 +0000 @@ -7,6 +7,7 @@ #include "rtos.h" #include <sstream> #include "USBAudio.h" +#include "Speaker.h" /* Account: mbedTokyoTech @@ -66,7 +67,9 @@ BusIn joy(p15,p12,p13,p16); Mutex locker; - + +Speaker speaker2(p26); + // sting buffers for tweeting char str[512]; char buf[512]; @@ -88,6 +91,7 @@ int enemyIndex = 1; bool gameOver = false; +bool gameOverScreen = false; int k = 0; @@ -136,8 +140,14 @@ foodIndex = 1; enemyIndex = 1; } - - + +void gameOverFun(){ + speaker2.PlayNote(969.0, 0.5, 1.0); + speaker2.PlayNote(800.0, 0.5, 1.0); + lcd.cls(); + lcd.locate(xDim / 2 - 10, yDim / 2); + lcd.printf("Game Over"); +} //Function that actually draws the snake and handles the user input void playSnake(void const *args) @@ -147,13 +157,14 @@ Thread::wait(10000); } - if (!gameOver) { + if (!gameOver && !gameOverScreen) { //locker.lock(); setUpGame(); - //pc.printf("PlayLock"); - while(true) { + + while(!gameOverScreen) { + pc.printf("Inne"); //Handles joystick-input - pc.printf("Playsnake"); + if(joy) { if(joy == 0x4) { //Right Left k=0; @@ -208,10 +219,10 @@ if(hit2) createNewFood(); else if(hitE){ - + gameOver = true; - // break; - + gameOverScreen = true; + gameOverFun(); } Thread::wait(50); // Used to control the speed of the game } @@ -237,10 +248,10 @@ //pc.printf("\nTrying to post data...\n"); // replace special characters with URL-safe ones - /*rep(msg, " ", "%20"); + rep(msg, " ", "%20"); rep(msg, "#", "%23"); - rep(msg, ":", "%3A");*/ - msg = "heeej"; + rep(msg, ":", "%3A"); + url = url + msg; @@ -257,7 +268,9 @@ { pc.printf("Error #%d\n", ret); } - + + //Used to restart game + setUpGame(); pc.printf("Response code: %d\n", http.getHTTPResponseCode()); } @@ -285,6 +298,11 @@ pc.printf("efter tweet(msg)"); locker.lock(); gameOver = false; + bool kalle = true; + while(kalle){ + if(joy) kalle = false; + } + gameOverScreen = false; locker.unlock(); } //locker.unlock();