diff projects/tank_wars/game.cpp @ 22:fbfeb5895efd matrix_gpio

Updated tank wars demo for new API
author andrewm
date Sun, 03 May 2015 01:10:17 +0100
parents 49f22e1246b2
children 59edd5780fef
line wrap: on
line diff
--- a/projects/tank_wars/game.cpp	Thu Apr 30 17:43:08 2015 +0100
+++ b/projects/tank_wars/game.cpp	Sun May 03 01:10:17 2015 +0100
@@ -33,6 +33,9 @@
 float projectilePositionX, projectilePositionY;
 float projectileVelocityX, projectileVelocityY;
 
+// Infor needed for sound rendering
+bool collisionJustOccurred = false;
+
 // Useful utility function for generating random floating-point values
 float randomFloat(float low, float hi)
 {
@@ -101,6 +104,7 @@
 		<= tankRadius * tankRadius)
 	{
 		projectileInMotion = false;
+		collisionJustOccurred = true;
 		playerHasWon = 2;
 	}
 	else if((tank2X - projectilePositionX)*(tank2X - projectilePositionX) +
@@ -108,16 +112,19 @@
 		<= tankRadius * tankRadius)
 	{
 		projectileInMotion = false;
+		collisionJustOccurred = true;
 		playerHasWon = 1;
 	}
 	else if(projectilePositionX < 0 || projectilePositionX >= screenWidth) {
 		// Check collision whether projectile has exited the screen to the left or right
 		projectileInMotion = false;
+		collisionJustOccurred = true;
 		nextPlayersTurn();
 	}
 	else if(projectilePositionY >= groundLevel[(int)floorf(projectilePositionX)]) {
 		// Check for projectile collision with ground
 		projectileInMotion = false;
+		collisionJustOccurred = true;
 		nextPlayersTurn();
 	}
 }
@@ -185,6 +192,20 @@
 	return playerHasWon;
 }
 
+bool gameStatusCollisionOccurred()
+{
+	if(collisionJustOccurred) {
+		collisionJustOccurred = false;
+		return true;
+	}
+	return false;
+}
+
+float gameStatusProjectileHeight()
+{
+	return projectilePositionY / (float)screenHeight;
+}
+
 // Clean up any allocated memory for the game
 void cleanupGame()
 {