- Timestamp:
- 2011-06-14 15:01:55 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/24/OtsoM/Pong/Pong/FysiikkaPeli/Peli.cs
r1957 r1999 4 4 using System.Text; 5 5 using Jypeli; 6 using Jypeli.Widgets; 6 7 7 8 class Peli : PhysicsGame 8 { 9 { Vector nopeusYlös = new Vector( 0, 200 ); 10 Vector nopeusAlas = new Vector( 0, -200 ); 11 12 9 13 PhysicsObject pallo; 10 14 PhysicsObject maila1; 15 PhysicsObject maila2; 16 IntMeter pelaajan1Pisteet; 17 IntMeter pelaajan2Pisteet; 11 18 12 19 public override void Begin() … … 14 21 // TODO: Kirjoita ohjelmakoodisi tähän 15 22 LuoKentta(); 16 Vector impulssi = new Vector(600.0, 0.0);17 pallo.Hit(impulssi);18 19 23 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 24 AsetaOhjaimet(); 25 LisaaLaskurit(); 26 AloitaPeli(); 20 27 } 21 28 … … 24 31 25 32 pallo = new PhysicsObject(50.0, 50.0); 26 pallo.Shape = Shape.Star; 33 pallo.Shape = Shape.Heart; 34 35 AddCollisionHandler( pallo, KasittelePallonTormays ); 36 37 38 27 39 pallo.Restitution = 1.0; 28 40 pallo.Color = Color.Fuchsia; … … 32 44 Add(pallo); 33 45 34 46 maila1 = LuoMaila( Level.Left + 20.0, 0.0); 47 maila2 = LuoMaila( Level.Right - 20.0, 0.0); 35 48 36 Level.CreateBorders(1.0, false); 49 50 PhysicsObject vasenReuna = Level.CreateBorders(); 51 vasenReuna.Restitution = 1.0; 52 vasenReuna.IsVisible = false; 53 54 55 37 56 Level.BackgroundColor = Color.Lime; 38 57 Camera.ZoomToLevel(); 39 PhysicsObject maila = PhysicsObject.CreateStaticObject( 20.0, 100.0 ); 58 } 59 60 61 62 void AloitaPeli() 63 { 64 Vector impulssi = new Vector(600.0, 0.0); 65 pallo.Hit(impulssi); 66 67 68 } 69 70 71 72 73 PhysicsObject LuoMaila( double x, double y ){ 74 75 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 40 76 maila.Shape = Shape.Rectangle; 41 maila.X = Level.Left + 20.0;42 maila.Y = 0.0;77 maila.X = x; 78 maila.Y = y; 43 79 maila.Restitution = 1.0; 44 80 Add(maila); 81 82 return maila; 83 84 85 86 87 } 88 89 90 91 92 93 94 95 void AsetaOhjaimet() 96 { 97 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlös); 98 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 99 100 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 101 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 102 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 103 104 105 { 106 Keyboard.Listen(Key.I, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlös); 107 Keyboard.Listen(Key.I, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 108 109 Keyboard.Listen(Key.K, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 110 Keyboard.Listen(Key.K, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 111 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 112 113 114 115 116 45 117 } 118 } 46 119 47 PhysicsObject pallo; 120 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 121 { 122 maila.Velocity = nopeus; 123 } 124 125 void LisaaLaskurit() 126 { 127 pelaajan1Pisteet = LuoPisteLaskuri( Screen.Left + 100.0, Screen.Top - 100.0 ); 128 pelaajan2Pisteet = LuoPisteLaskuri( Screen.Right - 100.0, Screen.Top - 100.0 ); 129 130 //... 131 132 133 134 } 135 136 137 IntMeter LuoPisteLaskuri( double x, double y ) 138 139 { 140 IntMeter laskuri = new IntMeter( 0 ); 141 laskuri.MaxValue = 10; 142 Label naytto = new Label(); 143 naytto.BindTo(laskuri); 144 naytto.X = x; 145 naytto.Y = y; 146 naytto.TextColor = Color.White; 147 naytto.BorderColor = Level.BackgroundColor; 148 naytto.Color = Level.BackgroundColor; 149 Add( naytto ); 150 return laskuri; 151 152 153 154 155 } 156 157 158 void KasittelePallonTormays(PhysicsObject kohde) 159 { 160 if (kohde == vasenReuna) 161 162 pelaajan1Pisteet.Value += 1; 163 164 165 166 167 168 else if (kohde == vasenReuna) 169 pelaajan2Pisteet.Value += 1; 170 171 172 } 173 48 174 49 175
Note: See TracChangeset
for help on using the changeset viewer.