- Timestamp:
- 2010-06-08 11:29:45 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/jopehell/pong/Peli.cs
r508 r543 8 8 public class Peli : PhysicsGame 9 9 { 10 Vector nopeusYlos = new Vector(0, 200); 11 Vector nopeusAlas = new Vector(0, 200); 12 10 13 PhysicsObject pallo; 11 14 PhysicsObject maila1; … … 21 24 { 22 25 pallo = new PhysicsObject(20.0, 20.0); 23 Add(pallo);24 26 pallo.Shape = Shapes.Circle; 27 pallo.Restitution = 1.0; 25 28 pallo.X = -50; 26 29 pallo.Y = -50; 30 Add(pallo); 27 31 28 32 Level.CreateBorders(1.0, false); 29 pallo.Restitution = 1.0;33 30 34 Level.BackgroundColor = Color.Black; 31 35 Camera.ZoomToLevel(); 32 LuoMaila(Level.Left + 20.0, 0.0); 33 LuoMaila(Level.Right - 20.0, 0.0); 36 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 37 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 38 MessageDisplay.TextColor = Color.DarkCyan; 34 39 35 40 } … … 56 61 void AsetaOhjaimet() 57 62 { 58 Keyboard.Listen( Key.A, ButtonState. Pressed, LiikutaMailaaYlos, "Pelaaja 1: Liikuta mailaa ylös", maila1 );63 Keyboard.Listen( Key.A, ButtonState.Down, LiikutaMailaaYlos, "Pelaaja 1: Liikuta mailaa ylös", maila1 ); 59 64 Keyboard.Listen( Key.A, ButtonState.Released, PysaytaMaila, null, maila1 ); 60 Keyboard.Listen( Key.Z, ButtonState. Pressed, LiikutaMailaaAlas, "Pelaaja 1: Liikuta mailaa alas", maila1 );61 Keyboard.Listen( Key.Z, ButtonState.Released, PysaytaMaila, null, maila1 65 Keyboard.Listen( Key.Z, ButtonState.Down, LiikutaMailaaAlas, "Pelaaja 1: Liikuta mailaa alas", maila1 ); 66 Keyboard.Listen( Key.Z, ButtonState.Released, PysaytaMaila, null, maila1); 62 67 63 Keyboard.Listen( Key.Up, ButtonState. Pressed, LiikutaMailaaYlos, "Pelaaja 2: Liikuta mailaa ylös", maila2 );68 Keyboard.Listen( Key.Up, ButtonState.Down, LiikutaMailaaYlos, "Pelaaja 2: Liikuta mailaa ylös", maila2 ); 64 69 Keyboard.Listen( Key.Up, ButtonState.Released, PysaytaMaila, null, maila2 ); 65 Keyboard.Listen( Key.Down, ButtonState. Pressed, LiikutaMailaaAlas, "Pelaaja 2: Liikuta mailaa alas", maila2 );70 Keyboard.Listen( Key.Down, ButtonState.Down, LiikutaMailaaAlas, "Pelaaja 2: Liikuta mailaa alas", maila2 ); 66 71 Keyboard.Listen( Key.Down, ButtonState.Released, PysaytaMaila, null, maila2 ); 67 72 68 73 Keyboard.Listen( Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet" ); 69 74 Keyboard.Listen( Key.Escape, ButtonState.Pressed, Exit, "Poistu" ); 75 76 ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 77 ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 78 ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 79 ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 80 81 ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 82 ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 83 ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 84 ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 85 86 ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 87 ControllerTwo.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 88 } 89 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 90 { 91 if ((nopeus.Y < 0) && (maila.Y < Level.Bottom)) 92 { 93 maila.Velocity = Vector.Zero; 94 return; 95 } 96 97 if ((nopeus.Y > 0) && (maila.Y > Level.Top)) 98 { 99 maila.Velocity = Vector.Zero; 100 return; 101 } 102 maila.Velocity = nopeus; 103 } 104 105 void LiikutaMailaaYlos( PhysicsObject maila) 106 { 107 if ((maila.Y >= Level.Top)) 108 { 109 maila.Velocity = Vector.Zero; 110 return; 111 } 112 Vector nopeus = new Vector(0, 200); 113 maila.Velocity = nopeus; 114 } 115 116 void LiikutaMailaaAlas( PhysicsObject maila ) 117 { 118 if (maila.Y <= Level.Bottom) 119 { 120 maila.Velocity = Vector.Zero; 121 return; 122 } 123 Vector nopeus = new Vector(0, -200); 124 maila1.Velocity = nopeus; 70 125 } 71 126 72 void LiikutaMailaaYlos( PhysicsObject maila)127 void PysaytaMaila( PhysicsObject maila1 ) 73 128 { 74 Vector nopeus = new Vector( 0, 200 ); 75 maila.Velocity = nopeus; 76 } 77 78 void LiikutaMailaaAlas( PhysicsObject maila ) 79 { 80 Vector nopeus = new Vector( 0, -200 ); 81 maila.Velocity = nopeus; 82 } 83 84 void PysaytaMaila( PhysicsObject maila ) 85 { 86 maila.Velocity = Vector.Zero; 129 maila1.Velocity = Vector.Zero; 87 130 } 88 131 }
Note: See TracChangeset
for help on using the changeset viewer.