public void spawnPowerup() { position.X = (float)rand.NextDouble() * outerLimit * 2 - outerLimit; //In the playing area position.Y = (float)rand.NextDouble() * outerLimit * 2 - outerLimit; position.Z = (float)rand.NextDouble() * outerLimit * 2 - outerLimit; type = (Constants.PowerUpType)rand.Next(0, 3); isActive = true; }
private void checkCollisions() { //checks to see if the player is touching an aseroid BoundingSphere playerBoundingSphere = player.model.Meshes[0].BoundingSphere.Transform(Matrix.CreateTranslation(player.position)); foreach (Asteroid a in allAsteroids) { if (a.isActive) { BoundingSphere aBoundSphere = a.getModel().Meshes[0].BoundingSphere.Transform(a.getWorldMatrix()); if (playerBoundingSphere.Intersects(aBoundSphere)) { //System.Diagnostics.Debug.Write("MAN DOWN\n"); //DIE! currentState = GameStates.Dead; lives--; } } } //Is the player hitting an item? foreach (Powerup p in allItems) { if (p.isActive) { BoundingSphere aBoundSphere = p.getModel().Meshes[0].BoundingSphere.Transform(p.getWorldMatrix()); if (playerBoundingSphere.Intersects(aBoundSphere)) { //System.Diagnostics.Debug.Write("Got a powerup!\n"); //Find Item type powerupSound.Play(); Constants.PowerUpType thisType = p.PickUp(); if (thisType == Constants.PowerUpType.Fuel) { player.addFuel(25); } if (thisType == Constants.PowerUpType.MultiShot) { player.multiBullet = true; } if (thisType == Constants.PowerUpType.Speed) { player.doubleSpeed = true; } } } } //checks to see if an asteroid is colliding with another asteroid foreach (Asteroid a in allAsteroids) { foreach (Asteroid b in allAsteroids) { if (!a.Equals(b) && a.isActive && b.isActive) { CheckForCollision(a, b); } } } //checks if a bullet is hitting an asteroid foreach (Bullet b in player.bulletSupply) { if (b.isActive) { BoundingBox bulletBox = UpdateBoundingBox(bullet, b.getWorldMatrix()); foreach (Asteroid a in allAsteroids) { if (a.isActive) { BoundingSphere aBoundSphere = a.getModel().Meshes[0].BoundingSphere.Transform(a.getWorldMatrix()); if (bulletBox.Intersects(aBoundSphere)) { //System.Diagnostics.Debug.Write("Asteroid Shot Down!\n"); //Destroy asteroid!! if (a.hit()) { asteroidsLeft--; //destroy the asteroid } b.isActive = false; //destory the bullet //asteroidsLeft--; //TODO MAKE AN EXPLOSION HERE! explosionSound.Play(); createExplosion(a.position); } } } } } }