- Timestamp:
- 2013-06-24 14:57:43 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/26/JustusK/Pong/Pong/Pong/Pong.cs
r4182 r4189 9 9 public class Pong : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200); 12 Vector nopeusAlas = new Vector(0, -200); 13 11 14 PhysicsObject pallo; 12 15 16 PhysicsObject maila1; 17 PhysicsObject maila2; 18 13 19 public override void Begin() 14 {20 { 15 21 LuoKentta(); 22 AsetaOhjaimet(); 23 AloitaPeli(); 16 24 17 Vector impulssi = new Vector(500.0, 0.0); 18 pallo.Hit(impulssi); 19 20 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 21 } 25 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 26 } 27 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 28 { 29 maila.Velocity = nopeus; 30 } 22 31 void LuoKentta() 23 32 { 24 PhysicsObjectpallo = new PhysicsObject(40.0, 40.0);33 pallo = new PhysicsObject(40.0, 40.0); 25 34 pallo.Shape = Shape.Circle; 26 pallo.X = 40.0;27 pallo.Y = 40.0;35 pallo.X = -200.0; 36 pallo.Y = 0.0; 28 37 pallo.Restitution = 1.0; 29 38 Add(pallo); 30 39 31 Level.CreateBorders(1.0, true); 40 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 41 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 42 43 Level.CreateBorders(1.0, false); 32 44 Level.BackgroundColor = Color.Black; 33 45 34 46 Camera.ZoomToLevel(); 47 } 48 49 void AsetaOhjaimet() 50 { 51 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 52 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 53 54 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 35 55 } 56 57 PhysicsObject LuoMaila(double x, double y) 58 { 59 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 60 maila.Shape = Shape.Rectangle; 61 maila.X = x; 62 maila.Y = y; 63 maila.Restitution = 1.0; 64 Add(maila); 65 return maila; 66 } 67 68 void AloitaPeli() 69 { 70 Vector impulssi = new Vector(500.0, 0.0); 71 pallo.Hit(impulssi); 72 73 } 74 36 75 }
Note: See TracChangeset
for help on using the changeset viewer.