示例#1
0
        public void Update(GameTime gameTime, Turret turret, List<Enemy> enemies)
        {
            List<Projectile> turretProjectiles = turret.ActiveProjectiles;

            for (int E = 0; E < enemies.Count; E++)
            {
                if (turret.BoundingBox.Intersects(enemies[E].BoundingBox))
                {
                    if (gameTime.TotalGameTime - previousHitTime > hitRate)
                    {
                        turret.CurrentHealth -= enemies[E].CollisionDamage;
                        enemies[E].CurrentHealth -= enemies[E].CollisionDamage;

                        previousHitTime = gameTime.TotalGameTime;

                        if (enemies[E].CurrentHealth > 0)
                            SoundEffectManager.Instance.GruntDamage();
                        else
                        {
                            TotalScore -= enemies[E].ScorePoints;
                            enemies.RemoveAt(E);
                            SoundEffectManager.Instance.GruntDeath();
                        }

                        if (turret.CurrentHealth > 0)
                        {
                            //Play sound effect
                        }
                        else
                        {
                            turret.CurrentState = Constants.CharacterState.Dead;
                        }
                    }
                }
            }

            for (int p = 0; p < turretProjectiles.Count; p++)
            {
                bool projectileRemoved = false;

                if (!GameArea.Intersects(turretProjectiles[p].BoundingBox))
                {
                    projectileRemoved = true;
                    turretProjectiles.RemoveAt(p);
                }

                for (int e = 0; e < enemies.Count; e++)
                {
                    if (!projectileRemoved)
                    {
                        for (int v = (int)turretProjectiles[p].TangentialVelocity + turretProjectiles[p].BoundingBox.Width; v >= 0; v--)
                        {
                            Vector2 point = turretProjectiles[p].Position - turretProjectiles[p].Direction * v;

                            if (enemies[e].BoundingBox.Contains((int)point.X, (int)point.Y))
                            {
                                enemies[e].InflictDamage(turretProjectiles[p].Damage);

                                if (enemies[e].CurrentHealth > 0)
                                    SoundEffectManager.Instance.GruntDamage();
                                else
                                {
                                    enemies[e].Slay();
                                    TotalScore += enemies[e].ScorePoints;
                                    enemies.RemoveAt(e);

                                    SoundEffectManager.Instance.GruntDeath();

                                }
                                turretProjectiles.RemoveAt(p);
                                projectileRemoved = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        public void Initialize(GraphicsDevice graphics)
        {
            this.graphics = graphics;

            viewPort = graphics.Viewport;
            origin = new Vector2(viewPort.Width / 2, viewPort.Height / 2);

            turret = new Turret(origin);
            turretProjectiles = new List<Projectile>();

            camControll = new CameraController(origin);
            GameCamera = new Camera(viewPort);
            gameArea = new Rectangle(-400, -400, viewPort.Width + 800, viewPort.Height + 800);
            CombatHandler.Instance.GameArea = gameArea;
            CombatHandler.Instance.TotalScore = 0;

            upCords = new Vector2[2] { new Vector2(-10, -camControll.MovingRadius - 210), new Vector2(viewPort.Width + 10, -camControll.MovingRadius - 10) };
            leftCords = new Vector2[2] { new Vector2(-camControll.MovingRadius - 210, -10), new Vector2(-camControll.MovingRadius - 10, viewPort.Height + 10) };
            rightCords = new Vector2[2] { new Vector2(viewPort.Width + camControll.MovingRadius + 10, -10), new Vector2(viewPort.Width + camControll.MovingRadius + 210, viewPort.Height + 10) };
            downCords = new Vector2[2] { new Vector2(-10, viewPort.Height + camControll.MovingRadius + 10), new Vector2(viewPort.Width + 10, viewPort.Height + camControll.MovingRadius + 210) };

            enemySpawner = new EnemySpawner(new GameTime(), 1000, 20000.0f, 5000.0f, 5000.0f, 500.0f, 500.0f, upCords, downCords, leftCords, rightCords);

            hud = new HeadsUpDisplay((int)turret.CurrentHealth);

            enemies = enemySpawner.SpawnedEnemies;

            Behaviour.Initialize(turret.Position + turret.Origin);

            clutter = new GroundClutter[clutterAmount];
        }