- Timestamp:
- 2010-06-08 11:28:08 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/teematma/Pong/Peli.cs
r519 r542 9 9 { 10 10 PhysicsObject Pallo; 11 PhysicsObject maila1; 12 PhysicsObject maila2; 11 13 12 14 protected override void Begin() 13 15 { 14 16 LuoKentta(); 17 AsetaOhjaimet(); 15 18 AloitaPeli(); 16 19 } … … 26 29 Pallo.Y = 0; 27 30 28 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 29 maila.Shape = Shapes.Rectangle; 30 maila.X = Level.Left + 20.0; 31 maila.Y = 0.0; 32 maila.Restitution = 1.0; 33 Add(maila); 31 32 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 33 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 34 34 35 35 Level.CreateBorders( 1.0, false); 36 Level.BackgroundColor = Color. YellowGreen;36 Level.BackgroundColor = Color.Black; 37 37 38 38 Camera.StayInLevel = true; 39 SetWindowSize(true); 39 40 40 41 } … … 44 45 Pallo.Hit(impulssi); 45 46 } 46 } 47 48 49 PhysicsObject LuoMaila(double x, double y) 50 { 51 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 52 maila.Shape = Shapes.Rectangle; 53 maila.X = x; 54 maila.Y = y; 55 maila.Restitution = 1.0; 56 Add(maila); 57 return maila; 58 59 } 60 void AsetaOhjaimet() 61 { 62 Keyboard.Listen(Key.A, ButtonState.Pressed, LiikutaMailaaYlos, "Pelaaja 1: liikuta mailaa ylös", maila1); 63 Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila, null, maila1); 64 Keyboard.Listen(Key.Z, ButtonState.Pressed, LiikutaMailaaAlas, "pelaaja 1: liikuta mailaa alas", maila1); 65 Keyboard.Listen(Key.Z, ButtonState.Released, PysaytaMaila, null, maila1); 66 67 Keyboard.Listen(Key.Up, ButtonState.Pressed, LiikutaMailaaYlos, "Pelaaja 2: liikuta mailaa ylös", maila2); 68 Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaMaila, null, maila2); 69 Keyboard.Listen(Key.Down, ButtonState.Pressed, LiikutaMailaaAlas, "Pelaaja 2: liikuta mailaa alas", maila2); 70 Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaMaila, null, maila2); 71 72 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "poistu"); 73 74 } 75 void LiikutaMailaaYlos(PhysicsObject Maila) 76 { 77 Vector nopeus = new Vector(0, 400); 78 Maila.Velocity = nopeus; 79 } 80 void LiikutaMailaaAlas(PhysicsObject Maila) 81 { 82 Vector nopeus = new Vector(0, -400); 83 Maila.Velocity = nopeus; 84 } 85 86 void PysaytaMaila(PhysicsObject Maila) 87 { 88 Maila.Velocity = Vector.Zero; 89 } 90 } 47 91 } 48 92
Note: See TracChangeset
for help on using the changeset viewer.