- Timestamp:
- 2015-06-29 14:56:23 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/27/MiroS/Pong/Pong/Pong/Pong.cs
r6502 r6533 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; 15 PhysicsObject maila1; 16 PhysicsObject maila2; 17 12 18 public override void Begin() 13 19 { 14 20 LuoKentta(); 21 AsetaOhjaimet(); 15 22 AloitaPeli(); 23 } 16 24 17 25 18 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");19 }20 void AloitaPeli()21 {22 Vector impullssi = new Vector(500.10, 0.0);23 pallo.Hit(impullssi);24 26 25 } 27 28 26 29 void LuoKentta() 27 30 { … … 32 35 pallo.Y = 200.0; 33 36 pallo.Restitution = 10.0; 37 pallo.Color = Color.Yellow; 38 Add(pallo); 39 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); 44 Level.Background.Color = Color.Green; 45 46 Camera.ZoomToLevel(); 47 } 48 49 void AloitaPeli() 50 { 51 Vector impullssi = new Vector(500.10, 0.0); 52 pallo.Hit(impullssi); 53 54 55 56 } 57 58 PhysicsObject LuoMaila(double X, double y) 59 { 34 60 35 61 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 36 62 maila.Shape = Shape.Rectangle; 37 maila.X = Level.Left + 20.0;38 maila.Y = 0.0;63 maila.X = X; 64 maila.Y = y; 39 65 maila.Restitution = 1.0; 40 66 Add(maila); 67 maila.Color = Color.Blue; 68 return maila; 41 69 42 Level.CreateBorders(1.0, false); 43 Level.Background.Color = Color.Black; 44 Camera.ZoomToLevel(); 70 71 72 73 } 74 75 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 76 { 77 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 78 { 79 maila.Velocity = Vector.Zero; 80 return; 81 } 82 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 83 { 84 85 maila.Velocity = Vector.Zero; 86 return; 87 88 } 89 90 91 maila.Velocity = nopeus; 92 93 } 94 95 void AsetaOhjaimet() 96 { 97 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 98 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 99 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 100 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 101 102 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 103 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 104 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 105 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 106 107 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 108 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 109 45 110 } 46 111 } 47 112 113 114 115
Note: See TracChangeset
for help on using the changeset viewer.