コード例 #1
0
ファイル: PlayerEnemy.cs プロジェクト: PhoenixWright/NePlus
        private void UpdateProjectiles()
        {
            int idx = 0;
            while (idx < bullets.Count)
            {
                if (bullets[idx].Disposed)
                {
                    bullets.RemoveAt(idx);
                    continue;
                }

                ++idx;
            }

            bool firePressed = random.Next(100) > 95;

            if (!releasedFire)
            {
                if (!firePressed)
                {
                    releasedFire = true;
                }
            }

            bool canFire = releasedFire && bullets.Count < 2;

            // handle firing projectiles
            if (canFire)
            {
                if (firePressed && Math.Abs(Engine.Player.Position.X - Position.X) < 800)
                {
                    releasedFire = false;

                    Vector2 bulletPosition;
                    float bulletX = 0.0f;
                    float bulletY = 0.0f;
                    float bulletAngle = 0.0f;

                    // determine bullet position and direction
                    switch (LastDirection)
                    {
                        case Global.Directions.Left:
                            bulletPosition = Position + new Vector2(-40.0f, 9.0f);
                            bulletX = -16.0f;
                            break;
                        case Global.Directions.Right:
                            bulletPosition = Position + new Vector2(40.0f, 9.0f);
                            bulletX = 16.0f;
                            break;
                        default:
                            bulletPosition = Position;
                            break;
                    }

                    // determine bullet vertical movement and angle
                    if (Engine.Player.Position.Y > Position.Y + 20)
                    {
                        bulletY = -13.0f;
                        bulletAngle = 90.0f;
                    }

                    if (Crouching)
                    {
                        bulletPosition.Y += 40.0f;
                    }

                    Bullet bullet = new Bullet(Engine, bulletPosition, new Vector2(bulletX, bulletY), bulletAngle, Global.CollisionCategories.EnemyBullet);
                    bullets.Add(bullet);
                    bulletTimer = 0.0f;

                    Cue lazer = Engine.Audio.GetCue("LazerShot");
                    lazer.Play();
                }
                else
                {
                    releasedFire = true;
                }
            }
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: PhoenixWright/NePlus
        private void UpdateProjectiles()
        {
            int idx = 0;
            while (idx < bullets.Count)
            {
                if (bullets[idx].Disposed)
                {
                    bullets.RemoveAt(idx);
                    continue;
                }

                ++idx;
            }

            bool firePressed = Engine.Input.IsButtonDown(Global.Configuration.GetButtonConfig("GameControls", "FireButton")) || Engine.Input.IsKeyDown(Global.Configuration.GetKeyConfig("GameControls", "FireKey"));

            if (!releasedFire)
            {
                if (!firePressed)
                {
                    releasedFire = true;
                }
            }

            bool canFire = releasedFire && bullets.Count < 2;

            // handle firing projectiles
            if (canFire)
            {
                if (firePressed)
                {
                    releasedFire = false;

                    Vector2 bulletPosition;
                    float bulletX = 0.0f;
                    float bulletY = 0.0f;
                    float bulletAngle = 0.0f;

                    // determine bullet position and direction
                    switch (LastDirection)
                    {
                        case Global.Directions.Left:
                            bulletPosition = Position + new Vector2(-40.0f, 9.0f);
                            bulletX = -16.0f;
                            break;
                        case Global.Directions.Right:
                            bulletPosition = Position + new Vector2(40.0f, 9.0f);
                            bulletX = 16.0f;
                            break;
                        default:
                            bulletPosition = Position;
                            break;
                    }

                    // determine bullet vertical movement and angle
                    if (Engine.Input.IsButtonDown(Global.Configuration.GetButtonConfig("GameControls", "UpButton")) || Engine.Input.IsKeyDown(Global.Configuration.GetKeyConfig("GameControls", "UpKey")))
                    {
                        bulletY = -13.0f;
                        bulletAngle = 90.0f;
                    }

                    if (Crouching)
                    {
                        bulletPosition.Y += 40.0f;
                    }

                    Bullet bullet = new Bullet(Engine, bulletPosition, new Vector2(bulletX, bulletY), bulletAngle, Global.CollisionCategories.PlayerBullet);
                    bullets.Add(bullet);
                    bulletTimer = 0.0f;

                    Cue lazer = Engine.Audio.GetCue("LazerShot");
                    lazer.Play();
                }
                else
                {
                    releasedFire = true;
                }
            }
        }