Changeset 6535 for 2015/27/SampoR/Pong
- Timestamp:
- 2015-06-29 14:58:02 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/27/SampoR/Pong/Pong/Pong/Pong.cs
r6503 r6535 9 9 public class Pong : PhysicsGame 10 10 { 11 const double PALLON_MIN_NOPEUS = 500; 12 13 Vector nopeusYlos = new Vector(0, 200); 14 Vector nopeusAlas = new Vector(0, -200); 15 11 16 PhysicsObject pallo; 17 18 PhysicsObject maila1; 19 PhysicsObject maila2; 20 12 21 public override void Begin() 13 22 { 14 23 LuoKenttä(); 15 16 Vector impulssi = new Vector(500.0, 0.0); 17 pallo.Hit(impulssi); 18 19 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 24 AsetaOhjaimet(); 25 LisaaLaskurit(); 26 AloitaPeli(); 20 27 } 21 28 … … 29 36 Add(pallo); 30 37 31 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 32 maila.Shape = Shape.Rectangle; 33 maila.X = Level.Left + 20.0; 34 maila.Y = 0.0; 35 maila.Restitution = 1.0; 36 Add(maila); 38 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 39 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 37 40 38 41 Level.CreateBorders(1.0, false); … … 41 44 Camera.ZoomToLevel(); 42 45 } 46 47 PhysicsObject LuoMaila(double x, double y) 48 { 49 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 50 maila.Shape = Shape.Rectangle; 51 maila.X = x; 52 maila.Y = y; 53 maila.Restitution = 1.0; 54 Add(maila); 55 return maila; 56 } 57 58 void AloitaPeli() 59 { 60 Vector impulssi = new Vector(300.0, 0.0); 61 pallo.Hit(impulssi); 62 } 63 64 protected override void Update(Time time) 65 { 66 if (pallo != null && Math.Abs(pallo.Velocity.X) < PALLON_MIN_NOPEUS) 67 { 68 pallo.Velocity = new Vector(pallo.Velocity.X * 1.1, pallo.Velocity.Y); 69 } 70 base.Update(time); 71 } 72 73 void AsetaOhjaimet() 74 { 75 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 76 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero) ; 77 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja1: Liikuta mailaa alas", maila1, nopeusAlas); 78 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 79 80 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 81 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 82 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 83 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 84 85 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 86 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 87 } 88 89 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 90 { 91 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 92 { 93 maila.Velocity = Vector.Zero; 94 return; 95 } 96 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 97 { 98 maila.Velocity = Vector.Zero; 99 return; 100 } 101 102 maila.Velocity = nopeus; 103 } 104 105 void LisaaLaskurit() 106 { 107 108 } 109 110 IntMeter LuoPisteLaskuri() 111 { 112 IntMeter laskuri = new IntMeter(0); 113 laskuri.MaxValue = 10; 114 return laskuri; 115 } 116 43 117 }
Note: See TracChangeset
for help on using the changeset viewer.