예제 #1
0
        public void Shoot()
        {
            var gameWorld = GameWorld as GameWorld;
            if (gameWorld.EnemySpawner.Objects.Count > 0)
            {
                //Shortest length
                float x = 99999;
                //index of object with shortest length
                int y = 0;

                if (Visible)
                {
                    for (int i = 0; i < gameWorld.EnemySpawner.Objects.Count; i++)
                    {
                        float length = (gameWorld.EnemySpawner.Objects[i].Position - position).Length();
                        if (length < x)
                        {
                            x = length;
                            y = i;
                        }
                    }

                    float adjacent = (gameWorld.EnemySpawner.Objects[y].Position.X - position.X) * 1.2f;
                    float opposite = -(gameWorld.EnemySpawner.Objects[y].Position.Y - position.Y);

                    float newAdjacent = GameEnvironment.Random.Next((int)(adjacent - 50), (int)(adjacent + 50));
                    float newOpposite = GameEnvironment.Random.Next((int)(opposite - 50), (int)(opposite + 50));

                    Vector2 direction = new Vector2(newAdjacent, newOpposite);
                    Vector2 directionNormal = Vector2.Normalize(direction);

                    Arrow arrow = new Arrow(position, directionNormal, 300, direction);
                    gameWorld.ArcherArrows.Add(arrow);
                }
            }
        }
예제 #2
0
        public void Shoot(float playerPositionX, float playerPositionY)
        {
            canShoot = false;

            Vector2 direction = new Vector2(playerPositionX, playerPositionY);
            Vector2 directionNormal = Vector2.Normalize(direction);

            Arrow arrow = new Arrow(player.Position, directionNormal, arrowSpeed, direction);

            arrows.Add(arrow);
        }