Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Jypeli;
  4. using Jypeli.Assets;
  5. using Jypeli.Controls;
  6. using Jypeli.Widgets;
  7.  
  8. public class Ht : PhysicsGame
  9. {
  10. PhysicsObject pelaaja;
  11. PhysicsObject tahtain;
  12. PhysicsObject golfpallo;
  13. const double golfpallopysahtyy = 0.1;
  14.  
  15. public override void Begin()
  16. {
  17. LuoKenttä();
  18. AsetaOhjaimet();
  19. //Update(Jypeli.Time.SinceLastUpdate);
  20.  
  21.  
  22. }
  23. //protected override void Update(Time time)
  24. //{
  25. // if (golfpallo != null &&( Math.Abs(golfpallo.Velocity.X + golfpallo.Velocity.Y) < golfpallopysahtyy))
  26. // {
  27. //pelaaja.X = golfpallo.X;
  28. //pelaaja.Y = golfpallo.Y;
  29. //golfpallo.Destroy();
  30. //}
  31. //base.Update(time);
  32. //}
  33.  
  34. // Luo pelikentän ja tarvittavat oliot
  35. void LuoKenttä()
  36. {
  37. pelaaja = new PhysicsObject(20.0, 30.0);
  38. pelaaja.Shape = Shape.Rectangle;
  39. Mouse.ListenMovement(0.01, Tahtaa, null);
  40. pelaaja.IgnoresCollisionResponse = true;
  41. Add(pelaaja);
  42.  
  43. tahtain = new PhysicsObject(15.0, 15.0, Shape.Circle);
  44. tahtain.IgnoresCollisionResponse = true;
  45. //tahtain.Image = LoadImage("tahtain");
  46.  
  47.  
  48. Add(tahtain);
  49. Mouse.IsCursorVisible = true;
  50. Mouse.ListenMovement(0.001, KuunteleLiiketta, null);
  51.  
  52. Level.CreateBorders(1.0, false);
  53. Level.BackgroundColor = Color.LightBlue;
  54.  
  55. }
  56.  
  57.  
  58. void Tahtaa(AnalogState hiirenLiike)
  59. {
  60. Vector suunta = (Mouse.PositionOnWorld - pelaaja.AbsolutePosition).Normalize();
  61. pelaaja.Angle = suunta.Angle;
  62. }
  63.  
  64. void KuunteleLiiketta(AnalogState hiirenTila)
  65. {
  66. tahtain.X = Mouse.PositionOnWorld.X;
  67. tahtain.Y = Mouse.PositionOnWorld.Y;
  68.  
  69. Vector hiirenLiike = hiirenTila.MouseMovement;
  70. }
  71.  
  72. void AsetaOhjaimet()
  73. {
  74. Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Ammu, "Ammu aseella.");
  75.  
  76. PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
  77. Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
  78. }
  79.  
  80.  
  81. private void Ammu()
  82. //aliohjelma ampuu golfpallon kohti kursoria
  83. {
  84. // if (golfpallo is PhysicsObject) return;
  85. //else
  86. golfpallo = new PhysicsObject(5.0, 5.0);
  87. golfpallo.Shape = Shape.Circle;
  88. golfpallo.X = pelaaja.X;
  89. golfpallo.Y = pelaaja.Y;
  90. golfpallo.Restitution = 0.5;
  91. golfpallo.KineticFriction = 1.0;
  92. golfpallo.LinearDamping = 0.99;
  93.  
  94. Add(golfpallo);
  95. Vector lyonti = new Vector(tahtain.X, tahtain.Y);
  96. golfpallo.Hit(lyonti);
  97.  
  98. }
  99.  
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement