Advertisement
Guest User

Untitled

a guest
May 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. using System.Windows.Media.Animation;
  17.  
  18. namespace Save_the_humanes
  19. {
  20. /// <summary>
  21. /// Interaction logic for MainWindow.xaml
  22. /// </summary>
  23. public partial class MainWindow : Window
  24. {
  25. Random random = new Random();
  26. public MainWindow()
  27. {
  28. InitializeComponent();
  29. }
  30.  
  31. private void StartButton_Click(object sender, RoutedEventArgs e)
  32. {
  33. AddEnemy();
  34. {
  35. ContentControl enemy = new ContentControl();
  36. enemy.Template = Resources["EnemyTemplate"] as ControlTemplate;
  37. AnimateEnemy(enemy, 0, playArea.ActualWidth - 100, "(Canvas.Left)");
  38. AnimateEnemy(enemy, random.Next((int)playArea.ActualHeight - 100),
  39. random.Next((int)playArea.ActualHeight - 100), "(Cabvas.Top)");
  40. playArea.Children.Add(enemy);
  41. }
  42.  
  43. }
  44.  
  45. private void AnimateEnemy(ContentControl enemy, double from, double to, string propertyToAnimate)
  46. {
  47. Storyboard storyboard = new Storyboard() { AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever };
  48. DoubleAnimation animation = new DoubleAnimation()
  49. {
  50. From = from,
  51. To = to,
  52. Duration = new Duration(TimeSpan.FromSeconds(random.Next(4, 6)))
  53. };
  54. Storyboard.SetTarget(animation, enemy);
  55. Storyboard.SetTargetProperty(animation, new PropertyPath(propertyToAnimate));
  56. storyboard.Children.Add(animation);
  57. storyboard.Begin();
  58. }
  59.  
  60. private void AddEnemy()
  61. {
  62.  
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement