Changeset 8867
- Timestamp:
- 2017-07-04 12:00:50 (6 years ago)
- Location:
- 2017/27/MikaelL/pong/pong/pong
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2017/27/MikaelL/pong/pong/pong/pong.cs
r8843 r8867 10 10 { 11 11 PhysicsObject pallo; 12 13 Vector nopeusYlos = new Vector(0, 200); 14 Vector nopeusAlas = new Vector(0, -200); 15 PhysicsObject maila1; 16 PhysicsObject maila2; 17 12 18 public override void Begin() 13 19 { 20 14 21 LuoKentta(); 22 AloitaPeli(); 23 AsetaOhjaimet(); 24 maila1 = LuoMaila(Level.Left + 20, 0.0); 25 maila2 = LuoMaila(Level.Right - 20, 0.0); 15 26 Vector inpulssi = new Vector(500.0, 0.0); 16 17 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 27 18 28 pallo.Hit(inpulssi); 19 29 20 30 21 31 } 32 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 33 { 34 maila.Velocity = nopeus; 35 } 22 36 23 37 38 void AsetaOhjaimet() 39 { 40 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 41 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 24 42 43 44 45 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 25 46 } 26 47 void LuoKentta() 27 48 { 28 49 pallo = new PhysicsObject(40.0, 40.0); 29 50 pallo.Shape = Shape.Circle; 30 51 Add(pallo); … … 32 53 pallo.Y = 0.0; 33 54 34 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 35 maila.Shape = Shape.Rectangle; 36 maila.X = Level.Left + 20.0; 37 maila.Y = 0.0; 38 maila.Restitution = 1.0; 39 Add(maila); 55 40 56 Level.CreateBorders(1.0, false); 41 57 pallo.Restitution = 1.0; … … 45 61 46 62 } 47 void AloitaPeli 63 void AloitaPeli() 48 64 { 49 65 Vector inpulssi = new Vector(500.0, 0.0); 50 66 pallo.Hit(inpulssi); 51 67 } 68 69 PhysicsObject LuoMaila(double x, double y) 70 { 71 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 72 maila.Shape = Shape.Rectangle; 73 maila.X = x; 74 maila.Y = y; 75 maila.Restitution = 1.0; 76 Add(maila); 77 return maila; 78 } 52 79 }
Note: See TracChangeset
for help on using the changeset viewer.