public override void Update(GameTime gameTime) { Vector3 cur_pos; // update for bullet's view for (int i = 0; i < gameP.Components.Count; i++) { if (gameP.Components[i] is Bullet) { cur_pos = ((Bullet)(gameP.Components[i])).Position; // means outstanding bullet in the room if (wall_collision(cur_pos.X) || wall_collision(cur_pos.Y) || wall_collision(cur_pos.X)) { // bullet out of bound gameP.Components.RemoveAt(i); break; } else { if (bullet != null) { bullet.ViewMatrix = viewMatrix; bullet.ProjectionMatrix = projectionMatrix; } else { bullet = (Bullet)(gameP.Components[i]); bullet.ViewMatrix = viewMatrix; bullet.ProjectionMatrix = projectionMatrix; } } } } base.Update(gameTime); }
public void Shoot() { audioComponent.PlayCue("shoot"); bullet = new Bullet(gameP); bullet.Coefficient_A_Materials = new Vector4(0.8f, 0.8f, 0.8f, 1.0f); bullet.Coefficient_D_Materials = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); bullet.Coefficient_S_Materials = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); bullet.Position = position; bullet.ViewMatrix = viewMatrix; bullet.ProjectionMatrix = projectionMatrix; bullet.Trajectory = Vector3.Normalize(lookAtVec); bullet.WorldMatrix = Matrix.Identity*Matrix.CreateTranslation(bullet.Position); bullet.gWVP = bullet.WorldMatrix * viewMatrix * projectionMatrix; bullet.BulletEffect = gameP.Content.Load<Effect>("DungeonEffect"); bullet.BulletEffect.CurrentTechnique = bullet.BulletEffect.Techniques["myTech"]; gameP.Components.Add(bullet); }
public override void Update(GameTime gameTime) { Vector3 cur_pos; // update for bullet's view for (int i = 0; i < gameP.Components.Count; i++) { if (gameP.Components[i] is Bullet) { bullet = (Bullet)gameP.Components[i]; cur_pos = bullet.Position; //cur_pos = ((Bullet)(gameP.Components[i])).Position; // means outstanding bullet in the room if (wall_collision(cur_pos.X) || wall_collision(cur_pos.Y) || wall_collision(cur_pos.X)) { // bullet out of bound gameP.Components.RemoveAt(i); break; } else { bullet.ViewMatrix = viewMatrix; bullet.ProjectionMatrix = projectionMatrix; } } } //Check to see if dinosaur has eaten me. bool hit = false; BoundingSphere[] bounds = ((Game1)this.Game).enemy.Bounds; foreach (BoundingSphere sphere in bounds) { hit |= this.Bounds.Intersects(sphere); } if (hit) { //Get an x and z at a safe distance from enemy. Vector3 enemyPosition = (this.Game as Game1).enemy.Position; Vector3 newPosition = Vector3.Zero; do { newPosition.X = 200 * (float)this.rng.NextDouble(); newPosition.Z = 200 * (float)this.rng.NextDouble(); } while (Vector3.DistanceSquared(enemyPosition, newPosition) < 2500); float x = 200 * (float)this.rng.NextDouble(); float z = 200 * (float)this.rng.NextDouble(); this.Position = new Vector3(x, this.Position.Y, z); Console.WriteLine("You Died!"); } base.Update(gameTime); }