public void Update(float timeDelta, Model[] asteroidModel, Camera camera) { for (int i = 0; i < asteroidList.Count(); i++) { asteroidList[i].Update(timeDelta); if (asteroidList[i].IsActive() == false) { asteroidList[i].addLife(-1); if (asteroidList[i].getLife() > 0) { //(-Y, X) //(Y, -X) //adds two more asteroids when one is destroyed Vector3 perpendicularVector1 = new Vector3(-asteroidList[i].getVelocity().Y, asteroidList[i].getVelocity().X, 0); //maybe we should add bullet vector? Vector3 perpendicularVector2 = new Vector3(asteroidList[i].getVelocity().Y, -asteroidList[i].getVelocity().X, 0); //maybe we should add bullet vector? Vector3 newVector1 = ((asteroidList[i].getVelocity() * 2) + perpendicularVector1 + bulletVector) / 4; Vector3 newVector2 = ((asteroidList[i].getVelocity() * 2) + perpendicularVector2 + bulletVector) / 4; AddAsteroid( asteroidModel[asteroidList[i].getLife() - 1], //pass in smaller roid asteroidList[i].getPosition().X, //pass in x position of parent roid asteroidList[i].getPosition().Y, //pass in y position of parent roid newVector1.X, newVector1.Y, asteroidList[i].getSpeed(), asteroidList[i].getLife(), 10 * asteroidList[i].getLife());// adds perpendicular vector (-y, x) AddAsteroid( asteroidModel[asteroidList[i].getLife() - 1], //pass in smaller model asteroidList[i].getPosition().X, //pass in x position of parent roid asteroidList[i].getPosition().Y, //pass in y position of parent roid newVector2.X, newVector2.Y, asteroidList[i].getSpeed(), asteroidList[i].getLife(), 10 * asteroidList[i].getLife());// adds perpendicular vector (y, -x) } int total = 25; for (int j = 0; j < total; j++) { Vector3 velocity = new Vector3(1f * (float)(random.NextDouble() * 2 - 1), 1f * (float)(random.NextDouble() * 2 - 1), 0); asteroidParticle.getParticles().Add(asteroidParticle.GenerateNewParticle(asteroidList[i].getPosition(), Vector3.Multiply(velocity, 0.1f), camera)); } asteroidList.RemoveAt(i); // removes old asteroid i--; } } asteroidParticle.Update(); }
public void Update(KeyboardState state, Model bulletModel, Camera camera, float timeDelta) { spawnTimer -= timeDelta; //if (multiplier > 1) //{ // multiplier -= timeDelta * 5; //} //else //{ // multiplier = 1; //} if (spawnTimer <= 0.0f) { isSpawning = false; isVisible = true; } else { isSpawning = true; } if (hasScored) { multiplier = multiplier * 2; score = score + (10 * (int)multiplier); hasScored = false; } if (!isActive) { explosion(camera); lives--; Reset(); } if (state.IsKeyDown(Keys.Left) || state.IsKeyDown(Keys.A)) { Rotation += 0.095f; } if (state.IsKeyDown(Keys.Right) || state.IsKeyDown(Keys.D)) { Rotation -= 0.095f; } RotationMatrix = Matrix.CreateRotationZ(Rotation); VelocityAdd = Vector3.Zero; VelocityAdd.X = (float)Math.Sin(Rotation); VelocityAdd.Y = -(float)Math.Cos(Rotation); VelocityAdd /= 75; if (state.IsKeyDown(Keys.Up) || state.IsKeyDown(Keys.W)) { setThrust(camera); } else { killThrust(); } engineParticle.Update(); explosionParticle.Update(); Position -= Velocity; Velocity *= 0.999f; if (Position.X > GameConstants.PlayfieldSizeX) { Position.X -= 2 * GameConstants.PlayfieldSizeX; } if (Position.X < -GameConstants.PlayfieldSizeX) { Position.X += 2 * GameConstants.PlayfieldSizeX; } if (Position.Y > GameConstants.PlayfieldSizeY) { Position.Y -= 2 * GameConstants.PlayfieldSizeY; } if (Position.Y < -GameConstants.PlayfieldSizeY) { Position.Y += 2 * GameConstants.PlayfieldSizeY; } }