Exemplo n.º 1
0
        public void InitializeGameObjects(int animalCount)
        {
            Animals = new List<Animal>();
            Hitlist = new Stack<Animal>();
            // Create player
            Player = new Player();

            Random rnd = new Random();
            for (int i = 0; i < animalCount; i++)
            {
                // Generate random index
                int ind = rnd.Next(0, Breeds.Count);
                // Create animal using factory
                Animal animal = Breeds[ind].CreateAnimal();
                // Set x and y
                animal.XPosition = rnd.Next(animal.Size * 2, Width - animal.Size * 2);
                animal.YPosition = rnd.Next(animal.Size * 2, Height - animal.Size * 2);

                Animals.Add(animal);
            }
        }
Exemplo n.º 2
0
 private void AnimatePlayer(Player player)
 {
     TranslateTransform trans = new TranslateTransform();
     player.Image.RenderTransform = trans;
     DoubleAnimation anim1 = new DoubleAnimation(player.X, player.XTrajectory, TimeSpan.FromSeconds(0));
     DoubleAnimation anim2 = new DoubleAnimation(player.Y, player.YTrajectory, TimeSpan.FromSeconds(0));
     trans.BeginAnimation(TranslateTransform.XProperty, anim1);
     trans.BeginAnimation(TranslateTransform.YProperty, anim2);
     player.X = player.XTrajectory;
     player.Y = player.YTrajectory;
 }
Exemplo n.º 3
0
 public void Initialize(List<Animal> animals, Player player)
 {
     this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
     {
         for (int i = 0; i < animals.Count; i++)
         {
             this.Children.Add(animals[i].Image);
         }
         this.Children.Add(player.Image);
         CreateLabels();
     }));
 }
Exemplo n.º 4
0
 public void Render(List<Animal> animals, Player player)
 {
     this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
     {
         foreach (Animal animal in animals)
         {
             Animate(animal);
         }
         AnimatePlayer(player);
     }));
 }