diff projects/tank_wars/game.cpp @ 268:8d80eda512cd prerelease

Added new overlay for using PRU0 or PRU1, a script to halt board on button press, and several example projects
author andrewm
date Tue, 17 May 2016 14:46:26 +0100
parents 59edd5780fef
children
line wrap: on
line diff
--- a/projects/tank_wars/game.cpp	Tue May 17 14:38:03 2016 +0100
+++ b/projects/tank_wars/game.cpp	Tue May 17 14:46:26 2016 +0100
@@ -35,6 +35,7 @@
 
 // Infor needed for sound rendering
 bool collisionJustOccurred = false;
+bool tankHitJustOccurred = false;
 
 // Useful utility function for generating random floating-point values
 float randomFloat(float low, float hi)
@@ -46,8 +47,8 @@
 // Restart the game, without reallocating memory
 void restartGame()
 {
-	float player1Height = randomFloat(screenHeight/2, screenHeight-5);
-	float player2Height = randomFloat(screenHeight/2, screenHeight-5);
+	float player1Height = screenHeight * 3/4; // randomFloat(screenHeight/2, screenHeight-5);
+	float player2Height = screenHeight - 5; // randomFloat(screenHeight/2, screenHeight-5);
 	for(int i = 0; i < screenWidth * 0.2; i++) {
 		groundLevel[i] = player1Height;
 	}
@@ -104,7 +105,8 @@
 		<= tankRadius * tankRadius)
 	{
 		projectileInMotion = false;
-		collisionJustOccurred = true;
+		collisionJustOccurred = false;
+		tankHitJustOccurred = true;
 		playerHasWon = 2;
 	}
 	else if((tank2X - projectilePositionX)*(tank2X - projectilePositionX) +
@@ -112,7 +114,8 @@
 		<= tankRadius * tankRadius)
 	{
 		projectileInMotion = false;
-		collisionJustOccurred = true;
+		collisionJustOccurred = false;
+		tankHitJustOccurred = true;
 		playerHasWon = 1;
 	}
 	else if(projectilePositionX < 0 || projectilePositionX >= screenWidth) {
@@ -201,6 +204,16 @@
 	return false;
 }
 
+bool gameStatusTankHitOccurred()
+{
+	if(tankHitJustOccurred) {
+		tankHitJustOccurred = false;
+		return true;
+	}
+	return false;
+}
+
+
 float gameStatusProjectileHeight()
 {
 	return projectilePositionY / (float)screenHeight;