Changeset 1874 for 2011/23/jopontin
- Timestamp:
- 2011-06-10 11:21:05 (11 years ago)
- Location:
- 2011/23/jopontin
- Files:
-
- 22 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/23/jopontin/pong/pong/pong/Peli.cs
r1722 r1874 9 9 public class Peli : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200);12 Vector nopeusAlas = new Vector(0, - 200);11 Vector nopeusYlos = new Vector(0, 800); 12 Vector nopeusAlas = new Vector(0, -800); 13 13 14 14 PhysicsObject maila1; 15 15 PhysicsObject maila2; 16 16 PhysicsObject pallo; 17 IntMeter pelaajan1Pisteet; 17 18 IntMeter pelaajan1Pisteet; 18 19 IntMeter pelaajan2Pisteet; 19 20 20 PhysicsObject vasenReuna; 21 PhysicsObject oikeaReuna; 22 PhysicsObject alaReuna; 23 PhysicsObject katto; 24 PhysicsObject este; 21 25 22 26 … … 29 33 AsetaOhjaimet(); 30 34 LisaaLaskurit(); 35 31 36 32 37 // TODO: Kirjoita ohjelmakoodisi tähän 33 38 34 35 36 39 40 37 41 38 42 … … 42 46 void luokentta() 43 47 { 44 Level.CreateBorders(1.0, false); 45 Level.BackgroundColor = Color.Transparent; 48 49 50 vasenReuna = Level.CreateLeftBorder(); 51 vasenReuna.Restitution = 1.0 ; 52 vasenReuna.IsVisible = true; 53 alaReuna = Level.CreateBottomBorder(); 54 alaReuna.Restitution = 1.0 ; 55 alaReuna.IsVisible = false ; 56 oikeaReuna = Level.CreateRightBorder(); 57 oikeaReuna.Restitution = 1.0; 58 oikeaReuna.IsVisible = true; 59 katto = Level.CreateTopBorder(); 60 katto.Restitution = 1.0; 61 katto.IsVisible = false; 62 63 64 Level.BackgroundColor = RandomGen.NextColor() ; 65 46 66 Camera.ZoomToLevel(); 67 47 68 pallo = new PhysicsObject(50.0, 50.0); 48 69 pallo.Shape = Shape.Circle; 49 70 pallo.Color = Color.GreenYellow; 50 pallo.Restitution = 1.0; 51 pallo.Shape = Shape.Circle; 52 pallo.Color = Color.GreenYellow; 53 pallo.Restitution = 1.0; 71 pallo.Restitution = 1.05; 72 54 73 55 74 pallo.X = 0; 56 75 pallo.Y = 0; 76 77 78 57 79 Add(pallo); 80 81 AddCollisionHandler(pallo, KasittelePallonTormays); 58 82 59 83 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 60 84 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 61 85 86 PhysicsObject este = new PhysicsObject(225.0, 225.0); 87 este.Shape = Shape.Hexagon; 88 este.X = -1; 89 este.Y = 0; 90 este.Mass = 1.0; 91 este.Restitution = 10.0; 62 92 63 93 Add(este); 64 94 65 95 } … … 67 97 void AloitaPeli() 68 98 { 69 Vector impulssi = new Vector( 1000.0, 0.0);99 Vector impulssi = new Vector(2000.0, 0.0); 70 100 pallo.Hit(impulssi); 71 101 … … 73 103 PhysicsObject LuoMaila(double x, double y) 74 104 { 75 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 1 00.0);105 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 120.0); 76 106 maila.Shape = Shape.Rectangle; 77 107 maila.X = x; … … 105 135 { 106 136 maila.Velocity = Vector.Zero; 107 return;} 137 return; 138 } 108 139 109 110 111 112 140 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 141 { 142 maila.Velocity = Vector.Zero; 143 return; 113 144 114 145 } 115 146 116 maila.Velocity = nopeus; 117 } 118 void LisaaLaskurit(); 119 { 120 pelaajan1Pisteet = LuoPisteLaskuri ( Screen.Left + 100.0, Screen.Top - 100.0 ); 121 pelaajan2Pisteet = LuoPisteLaskuri ( Screen.Right - 100.0, Screen.Top - 100.0 ); } 147 maila.Velocity = nopeus; 148 } 149 void LisaaLaskurit() 150 { 151 pelaajan1Pisteet = LuoPistelaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 152 pelaajan2Pisteet = LuoPistelaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 153 } 122 154 123 155 124 IntMeter LuoPistelaskuri ( double x, double y ); 156 IntMeter LuoPistelaskuri(double x, double y) 157 { 158 IntMeter laskuri = new IntMeter(0); 159 laskuri.MaxValue = 10; 160 Label naytto = new Label(); 161 naytto.BindTo(laskuri); 162 naytto.X = x; 163 naytto.Y = y; 164 naytto.TextColor = Color.White; 165 naytto.BorderColor = Level.BackgroundColor; 166 naytto.Color = Level.BackgroundColor; 167 Add(naytto); 168 return laskuri; 169 } 170 void KasittelePallonTormays ( PhysicsObject pallo , PhysicsObject kohde ) 125 171 126 } 127 IntMeter laskuri = new IntMeter ( 0 ); 128 laskuri.MaxValue = 10; 129 Label naytto = new Label (); 130 naytto.BindTo( laskuri ); 131 naytto.X = x; 132 naytto.Y = y; 133 naytto.TextColor = Color.White; 134 naytto.BorderColor = Level.BackgroundColor; 135 naytto.Color = Level.BackgroundColor; 136 Add( naytto ); 172 { if ( kohde == vasenReuna ) 173 { 174 pelaajan2Pisteet.Value += 1; 137 175 138 return laskuri; 176 } 177 else if (kohde == oikeaReuna ) 178 { 179 pelaajan1Pisteet.Value += 1; 180 181 } 182 183 184 185 186 187 188 189 } 190 139 191 140 192
Note: See TracChangeset
for help on using the changeset viewer.