diff projects/tank_wars/game.cpp @ 67:472e892c6e41

Merge newapi into default
author Andrew McPherson <a.mcpherson@qmul.ac.uk>
date Fri, 17 Jul 2015 15:28:18 +0100
parents fbfeb5895efd
children 59edd5780fef
line wrap: on
line diff
--- a/projects/tank_wars/game.cpp	Sun Feb 08 00:20:01 2015 +0000
+++ b/projects/tank_wars/game.cpp	Fri Jul 17 15:28:18 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()
 {