Changeset 2886
- Timestamp:
- 2012-06-08 13:39:07 (11 years ago)
- Location:
- 2012/23/SimoH/JalkapalloPeli2/JalkapalloPeli2
- Files:
-
- 10 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/23/SimoH/JalkapalloPeli2/JalkapalloPeli2/JalkapalloPeli2/JalkapalloPeli2.cs
r2777 r2886 16 16 PhysicsObject kentta, katsomoVasen, katsomoOikea; 17 17 18 Image vasenVerkko = LoadImage("maali"); 19 Image oikeaVerkko = LoadImage("maaliOikea"); 20 18 21 ProgressBar pelaaja1Energia, pelaaja2Energia; 19 22 IntMeter pelaaja1Maalit, pelaaja2Maalit; 20 23 24 ExplosionSystem es = new ExplosionSystem(LoadImage("pallo"), 500); 25 ExplosionSystem es2 = new ExplosionSystem(LoadImage("pallo"), 500); 26 27 SoundEffect potku = LoadSoundEffect("kick"); 28 SoundEffect tolppa = LoadSoundEffect("post"); 29 SoundEffect isoPotku = LoadSoundEffect("bighit"); 30 SoundEffect maali = LoadSoundEffect("maaliPilli"); 31 21 32 public override void Begin() 22 33 { 23 AloitaPeli(); 34 Level.BackgroundColor = Color.Gray; 35 Level.Background.Image = LoadImage("tausta"); 36 Camera.ZoomFactor = 1.5; 37 ControllerOne.Listen(Button.Start, ButtonState.Pressed, delegate { AloitaPeli(); }, ""); 38 ControllerTwo.Listen(Button.Start, ButtonState.Pressed, delegate { AloitaPeli(); }, ""); 24 39 } 25 40 … … 34 49 public void AlustaKentta() 35 50 { 36 Gravity = new Vector(0, -300); 51 Gravity = new Vector(0, -600); 52 53 Level.BackgroundColor = Color.SkyBlue; 37 54 38 55 kentta = Surface.CreateBottom(Level); … … 57 74 pelaaja1 = LuoPelaaja(new Vector(Level.Left + 100, Level.Bottom + 30)); 58 75 pelaaja2 = LuoPelaaja(new Vector(Level.Right - 100, Level.Bottom + 30)); 59 76 //pelaaja1.Image = LoadImage("pelaaja1"); 77 pelaaja1.LeftWalkingAnimation = Image.Mirror(LoadImage("pelaaja1")); 78 pelaaja1.RightWalkingAnimation = LoadImage("pelaaja1"); 79 pelaaja2.LeftWalkingAnimation = LoadImage("pelaaja2"); 80 pelaaja2.RightWalkingAnimation = Image.Mirror(LoadImage("pelaaja2")); 60 81 pallo = new PhysicsObject(20, 20); 61 82 pallo.Shape = Shape.Circle; 62 63 pallo.CollisionIgnoreGroup = 1; 64 tolppaOikea.CollisionIgnoreGroup = 1; 65 tolppaVasen.CollisionIgnoreGroup = 1; 66 83 pallo.Image = LoadImage("pallo"); 84 85 es = new ExplosionSystem(LoadImage("pallo"), 500); 86 es2 = new ExplosionSystem(LoadImage("pallo"), 500); 87 es.MaxScale = 20; 88 es.MinScale = 5; 89 es.MinVelocity = 5; 90 es.MaxVelocity = 10; 91 Add(es); 92 93 es2.MaxScale = 30; 94 es2.MinScale = 10; 95 es2.MaxVelocity = 100; 96 es2.MinVelocity = 80; 97 es2.MaxLifetime = 1; 98 es2.MinLifetime = 0.8; 99 Add(es2); 100 101 Timer t = new Timer(); 102 t.Interval = 0.05; 103 t.Timeout += delegate 104 { 105 if (pallo.Velocity.Magnitude > 700) 106 { 107 es.AddEffect(pallo.Position, 10); 108 } 109 }; 110 t.Start(); 111 112 //pallo.CollisionIgnoreGroup = 1; 113 tolppaOikea.IgnoresCollisionResponse = true; 114 tolppaVasen.IgnoresCollisionResponse = true; 115 //tolppaOikea.CollisionIgnoreGroup = 1; 116 //tolppaVasen.CollisionIgnoreGroup = 1; 117 AddCollisionHandler(pallo, OsuiTolppaan); 67 118 Add(pallo); 68 119 … … 76 127 77 128 // Pelaaja 1 78 ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa, " ", pelaaja1);79 ControllerOne.ListenAnalog(AnalogControl.RightTrigger, 0.1, Potkaise, " ", pelaaja1, ControllerOne);80 ControllerOne.Listen(Button.LeftStick, ButtonState.Down, Sprinttaa, " ", pelaaja1, true);129 ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa, "Liiku", pelaaja1); 130 ControllerOne.ListenAnalog(AnalogControl.RightTrigger, 0.1, Potkaise, "Potkaise", pelaaja1, ControllerOne); 131 ControllerOne.Listen(Button.LeftStick, ButtonState.Down, Sprinttaa, "Sprinttaa", pelaaja1, true); 81 132 ControllerOne.Listen(Button.LeftStick, ButtonState.Released, Sprinttaa, "", pelaaja1, false); 82 ControllerOne.ListenAnalog(AnalogControl.LeftTrigger, 0.1, Hyppaa, "", pelaaja1); 133 ControllerOne.ListenAnalog(AnalogControl.LeftTrigger, 0.1, Hyppaa, "Hyppää", pelaaja1); 134 ControllerOne.Listen(Button.Y, ButtonState.Pressed, ResetoiPelaaja, "", pelaaja1); 83 135 84 136 // Pelaaja 2 85 ControllerTwo.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa, " ", pelaaja2);86 ControllerTwo.ListenAnalog(AnalogControl.RightTrigger, 0.1, Potkaise, " ", pelaaja2, ControllerTwo);87 ControllerTwo.Listen(Button.LeftStick, ButtonState.Down, Sprinttaa, " ", pelaaja2, true);137 ControllerTwo.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa, "Liiku", pelaaja2); 138 ControllerTwo.ListenAnalog(AnalogControl.RightTrigger, 0.1, Potkaise, "Potakise", pelaaja2, ControllerTwo); 139 ControllerTwo.Listen(Button.LeftStick, ButtonState.Down, Sprinttaa, "Sprinttaa", pelaaja2, true); 88 140 ControllerTwo.Listen(Button.LeftStick, ButtonState.Released, Sprinttaa, "", pelaaja2, false); 89 ControllerTwo.ListenAnalog(AnalogControl.LeftTrigger, 0.1, Hyppaa, "", pelaaja2); 141 ControllerTwo.ListenAnalog(AnalogControl.LeftTrigger, 0.1, Hyppaa, "Hyppää", pelaaja2); 142 ControllerTwo.Listen(Button.Y, ButtonState.Pressed, ResetoiPelaaja, "", pelaaja2); 90 143 } 91 144 … … 93 146 { 94 147 //pelaaja.Move(new Vector(state.StateVector.X * 100, 0)); 95 pelaaja.Velocity = new Vector(state.StateVector.X * (pelaaja.Nopeus + pelaaja.Sprinttaa), pelaaja.Velocity.Y); 148 pelaaja.Walk(state.StateVector.X * (pelaaja.Nopeus + pelaaja.Sprinttaa)); 149 //pelaaja.Velocity = new Vector(state.StateVector.X * (pelaaja.Nopeus + pelaaja.Sprinttaa), pelaaja.Velocity.Y); 96 150 } 97 151 … … 110 164 public void Potkaise(AnalogState state, Pelaaja pelaaja, GamePad controller) 111 165 { 112 pelaaja.Potkaise(pallo, controller.RightThumbDirection * 650); 166 double normi = 0.90; 167 double iso = 0.10; 168 double tosiIso = 0.00; 169 if (Math.Abs(pelaaja.Y - kentta.Y) < 200) 170 { 171 if (Math.Abs(pelaaja.Y - kentta.Y) > 100) 172 { 173 normi = 0.60; 174 iso = 0.30; 175 tosiIso = 0.10; 176 } 177 int tod = RandomGen.NextIntWithProbabilities(new double[] { 0.0, normi, iso, tosiIso }); 178 if ((tod == 2 || tod == 3)) 179 { 180 if (pelaaja.Potkaise(pallo, controller.RightThumbDirection * 650 * tod)) 181 { 182 es2.AddEffect(pallo.Position, 40); 183 if(tod == 2) 184 controller.Vibrate(0.2, 0.2, 0.5, 0.5, 0.5); 185 isoPotku.Play(); 186 if (tod == 3) 187 { 188 controller.Vibrate(0.6, 0.6, 1, 1, 0.8); 189 isoPotku.Play(); 190 es.AddEffect(pallo.Position, 100); 191 } 192 } 193 } 194 else 195 { 196 if (pelaaja.Potkaise(pallo, controller.RightThumbDirection * 650)) 197 { 198 potku.Play(); 199 } 200 } 201 } 113 202 } 114 203 … … 124 213 tolppa.Color = Color.White; 125 214 tolppa.Mass = Int16.MaxValue; 215 tolppa.Tag = "tolppa"; 126 216 tolppa.CanRotate = false; 127 217 if (onkoVasen) … … 133 223 pystyRima.Color = Color.White; 134 224 pystyRima.CanRotate = false; 225 AddCollisionHandler(pystyRima, OsuiRimaan); 135 226 //Add(tolppa); 136 227 if (onkoVasen) … … 143 234 maali.Add(pystyRima); 144 235 236 237 145 238 AxleJoint liitos; 146 239 if (onkoVasen) … … 155 248 maali.Position = new Vector(pos.X - maali.Width, pos.Y + maali.Height / 2); 156 249 Add(maali); 250 251 GameObject verkko = new GameObject(60, 100); 252 if (onkoVasen) 253 { 254 verkko.Image = vasenVerkko; 255 verkko.Position = maali.Position - new Vector(verkko.Image.Width / 2, 0); 256 } 257 else 258 { 259 verkko.Image = oikeaVerkko; 260 verkko.Position = maali.Position + new Vector(verkko.Image.Width / 2, 0); 261 } 262 263 264 Add(verkko, -1); 157 265 return maali; 158 266 159 267 } 160 268 269 public void OsuiRimaan(PhysicsObject rima, PhysicsObject osuja) 270 { 271 if (osuja == pallo) 272 tolppa.Play(); 273 } 274 275 public void OsuiTolppaan(PhysicsObject pallo, PhysicsObject kohde) 276 { 277 /*if (kohde == tolppaVasen) 278 if (RandomGen.NextDouble(0.0, 4.0) < (double)Microsoft.Xna.Framework.MathHelper.Lerp(0.0f, 1.0f, (float)pelaaja2.X)) 279 { 280 tolppa.Play(); 281 pallo.Velocity = new Vector(pallo.Velocity.X * -1, pallo.Velocity.Y); 282 } 283 if (kohde == tolppaOikea) 284 if (RandomGen.NextDouble(0.0, 4.0) < (double)Microsoft.Xna.Framework.MathHelper.Lerp((float)tolppaOikea.X, (float)Level.Left, (float)pelaaja1.X)) 285 { 286 tolppa.Play(); 287 pallo.Velocity = new Vector(pallo.Velocity.X * -1, pallo.Velocity.Y); 288 }*/ 289 } 290 161 291 public Pelaaja LuoPelaaja(Vector pos) 162 292 { 163 Pelaaja pelaaja = new Pelaaja( 20, 40);293 Pelaaja pelaaja = new Pelaaja(40, 40); 164 294 pelaaja.Position = pos; 295 pelaaja.Shape = Shape.Circle; 165 296 pelaaja.CanRotate = false; 166 297 pelaaja.Restitution = 0.0; … … 185 316 pallo.Stop(); 186 317 pallo.Position = Level.Center; 318 maali.Play(); 187 319 if (pelaaja == 1) 188 320 pelaaja1Maalit.Value++; … … 193 325 protected override void Update(Time time) 194 326 { 195 if (pallo.Right < tolppaVasen.Left && pallo.Top < tolppaVasen.Top) 196 Maali(1); 197 if (pallo.Left > tolppaOikea.Right && pallo.Top < tolppaOikea.Top) 198 Maali(2); 327 if (pallo != null && tolppaVasen != null && tolppaOikea != null) 328 { 329 if (pallo.Right < tolppaVasen.Left && pallo.Top < tolppaVasen.Top) 330 Maali(2); 331 if (pallo.Left > tolppaOikea.Right && pallo.Top < tolppaOikea.Top) 332 Maali(1); 333 } 199 334 base.Update(time); 335 } 336 337 public void ResetoiPelaaja(PlatformCharacter pelaaja) 338 { 339 if ((pelaaja.Right < tolppaVasen.Left && pelaaja.Top < tolppaVasen.Top) || (pelaaja.Left > tolppaOikea.Right && pelaaja.Top < tolppaOikea.Top)) 340 { 341 if (pelaaja == pelaaja1) 342 pelaaja.Position = new Vector(Level.Left + 100, Level.Bottom + 30); 343 if (pelaaja == pelaaja2) 344 pelaaja.Position = new Vector(Level.Right - 100, Level.Bottom + 30); 345 } 200 346 } 201 347 … … 218 364 pelaaja1Maalit = new IntMeter(0); 219 365 pelaaja1Maalit.MaxValue = 10; 366 pelaaja1Maalit.UpperLimit += delegate { PeliPaattyi(1); }; 220 367 Label pelaaja1Naytto = new Label(); 221 368 pelaaja1Naytto.Position = new Vector(Screen.LeftSafe + 250, Screen.TopSafe - 70); … … 225 372 pelaaja2Maalit = new IntMeter(0); 226 373 pelaaja2Maalit.MaxValue = 10; 374 pelaaja2Maalit.UpperLimit += delegate { PeliPaattyi(2); }; 227 375 Label pelaaja2Naytto = new Label(); 228 376 pelaaja2Naytto.Position = new Vector(Screen.RightSafe - 250, Screen.TopSafe - 70); … … 230 378 Add(pelaaja2Naytto); 231 379 } 380 381 void PeliPaattyi(int pelaaja) 382 { 383 string s = ""; 384 if (pelaaja == 1) 385 s = "Pelaaja 1 voitti!"; 386 if (pelaaja == 2) 387 s = "Pelaaja 2 voitti!"; 388 Timer t = new Timer(); 389 t.Interval = 1.0; 390 t.Timeout += delegate 391 { 392 es2.AddEffect(RandomGen.NextVector(Level.Left + 100, Level.Bottom + 100, Level.Right - 100, Level.Top - 100), 100); 393 }; 394 t.Start(); 395 ClearControls(); 396 MessageWindow mw = new MessageWindow(s); 397 mw.IsModal = false; 398 mw.Closed += delegate { AloitaPeli(); }; 399 ControllerOne.Listen(Button.X, ButtonState.Pressed, delegate { mw.Close(); }, ""); 400 ControllerTwo.Listen(Button.X, ButtonState.Pressed, delegate { mw.Close(); }, ""); 401 402 403 404 Add(mw); 405 } 232 406 } -
2012/23/SimoH/JalkapalloPeli2/JalkapalloPeli2/JalkapalloPeli2/Pelaaja.cs
r2777 r2886 39 39 } 40 40 41 public voidPotkaise(PhysicsObject kohde, Vector voima)41 public bool Potkaise(PhysicsObject kohde, Vector voima) 42 42 { 43 43 if (Vector.Distance(this.Position, kohde.Position) < 50 && !potkaissut) 44 { 44 45 kohde.Velocity = voima; 45 potkaissut = true; 46 Timer.SingleShot(0.5, delegate { potkaissut = false; }); 46 potkaissut = true; 47 Timer.SingleShot(0.5, delegate { potkaissut = false; }); 48 return true; 49 } 50 return false; 47 51 } 48 52 -
2012/23/SimoH/JalkapalloPeli2/JalkapalloPeli2/JalkapalloPeli2Content/JalkapalloPeli2Content.contentproj
r2777 r2886 65 65 </Compile> 66 66 </ItemGroup> 67 <ItemGroup> 68 <Compile Include="pelaaja1.png"> 69 <Name>pelaaja1</Name> 70 <Importer>TextureImporter</Importer> 71 <Processor>TextureProcessor</Processor> 72 </Compile> 73 <Compile Include="pelaaja2.png"> 74 <Name>pelaaja2</Name> 75 <Importer>TextureImporter</Importer> 76 <Processor>TextureProcessor</Processor> 77 </Compile> 78 </ItemGroup> 79 <ItemGroup> 80 <Compile Include="pallo.png"> 81 <Name>pallo</Name> 82 <Importer>TextureImporter</Importer> 83 <Processor>TextureProcessor</Processor> 84 </Compile> 85 </ItemGroup> 86 <ItemGroup> 87 <Compile Include="maali.png"> 88 <Name>maali</Name> 89 <Importer>TextureImporter</Importer> 90 <Processor>TextureProcessor</Processor> 91 </Compile> 92 <Compile Include="maaliOikea.png"> 93 <Name>maaliOikea</Name> 94 <Importer>TextureImporter</Importer> 95 <Processor>TextureProcessor</Processor> 96 </Compile> 97 </ItemGroup> 98 <ItemGroup> 99 <Compile Include="bighit.wav"> 100 <Name>bighit</Name> 101 <Importer>WavImporter</Importer> 102 <Processor>SoundEffectProcessor</Processor> 103 </Compile> 104 <Compile Include="kick.wav"> 105 <Name>kick</Name> 106 <Importer>WavImporter</Importer> 107 <Processor>SoundEffectProcessor</Processor> 108 </Compile> 109 <Compile Include="post.wav"> 110 <Name>post</Name> 111 <Importer>WavImporter</Importer> 112 <Processor>SoundEffectProcessor</Processor> 113 </Compile> 114 </ItemGroup> 115 <ItemGroup> 116 <Compile Include="maaliPilli.wav"> 117 <Name>maaliPilli</Name> 118 <Importer>WavImporter</Importer> 119 <Processor>SoundEffectProcessor</Processor> 120 </Compile> 121 </ItemGroup> 122 <ItemGroup> 123 <Compile Include="tausta.png"> 124 <Name>tausta</Name> 125 <Importer>TextureImporter</Importer> 126 <Processor>TextureProcessor</Processor> 127 </Compile> 128 </ItemGroup> 67 129 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 68 130 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset
for help on using the changeset viewer.