- Timestamp:
- 2013-07-25 13:41:48 (10 years ago)
- Location:
- 2013/30/VilleF/Lentokone/Lentokone
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/30/VilleF/Lentokone/Lentokone/Lentokone/Lentokone.cs
r4652 r4659 8 8 9 9 public class Lentokone : PhysicsGame 10 { 10 { 11 11 private Animation rasa; 12 13 12 private Animation sauruksenLento; 14 13 private Animation juusto; 15 14 private Animation miesa; 16 //IntMeter Pisteaskuri;15 Image rasse = LoadImage("rasse"); 17 16 Image ukkeliPi = LoadImage("ukkeli"); 18 17 Image pommik = LoadImage("pommi"); 19 18 Image maisema = LoadImage("havutausta"); 20 19 Image havusaurus = LoadImage("havusauruskuva"); 20 21 21 Vector nopeusYlos = new Vector(0, 1000); 22 22 Vector nopeusAlas = new Vector(0, -1000); 23 23 24 PhysicsObject pelaaja; 24 25 PhysicsObject pommi; 25 26 PhysicsObject Rasa; 27 Cannon RasasenTykki; 26 28 27 29 Timer komboLaskurinAjastin; 28 29 30 IntMeter pisteLaskuri; 30 31 IntMeter KomboLaskuri; 31 32 32 33 33 public override void Begin() … … 68 68 Keyboard.Listen(Key.V, ButtonState.Released, LisaaVihollinen, "Ammu"); 69 69 Keyboard.Listen(Key.P, ButtonState.Pressed, Pause, "Pysäyttää pelin"); 70 71 Keyboard.Listen(Key.B, ButtonState.Released, tiputamuu, "Pysäyttää pelin"); 72 } 73 void tiputamuu() 74 { 75 76 Rasa = new PhysicsObject(100, 100); 77 //pommi.Shape = Shape.FromImage("pommik"); 78 Rasa.Position = pelaaja.Position; 79 Rasa.Animation = rasa; 80 Rasa.Animation.Start(); 81 Rasa.Animation.FPS = 3; 82 Add(Rasa); 70 Keyboard.Listen(Key.NumPad4, ButtonState.Down, LiikutaRasasta, null, -1); 71 Keyboard.Listen(Key.NumPad6, ButtonState.Down, LiikutaRasasta, null, 1); 72 Keyboard.Listen(Key.NumPad5, ButtonState.Released, RasanenPommi, "Saarnaa"); 73 Keyboard.Listen(Key.B, ButtonState.Released, tiputamuu, "Luo Rasa"); 83 74 84 } 85 void LuoPistelaskuri() 86 { 87 pisteLaskuri = new IntMeter(0); 88 89 Label pisteNaytto = new Label(); 90 pisteNaytto.X = Screen.Right - 100; 91 pisteNaytto.Y = Screen.Top - 100; 92 pisteNaytto.TextColor = Color.Green; 93 //pisteNaytto.Color = Color.White; 94 pisteNaytto.IntFormatString = "Pisteitä: {0:D1}"; 95 pisteNaytto.BindTo(pisteLaskuri); 96 Add(pisteNaytto); 97 } 98 void LuoKomboLaskuri() 99 { 100 KomboLaskuri = new IntMeter(0); 101 102 Label komboNaytto = new Label(); 103 komboNaytto.X = Screen.Right - 200; 104 komboNaytto.Y = Screen.Top - 200; 105 komboNaytto.TextColor = Color.Green; 106 //pisteNaytto.Color = Color.White; 107 komboNaytto.IntFormatString = "COMBO: {0:D1}"; 108 komboNaytto.BindTo(KomboLaskuri); 109 Add(komboNaytto); 110 111 komboLaskurinAjastin = new Timer(); 112 komboLaskurinAjastin.Interval = 5; 113 komboLaskurinAjastin.Timeout += delegate { KomboLaskuri.Reset(); }; 114 komboLaskurinAjastin.Start(); 115 116 KomboLaskuri.Changed += delegate { Kombot(); }; 117 118 119 120 121 } 122 void Kombot() 123 { 124 if (KomboLaskuri.Value == 3) 125 { 126 Label tekstikentta = new Label("kombo"); 127 Add(tekstikentta); 128 // PommiOsuu(100); 129 130 } 131 132 if (KomboLaskuri.Value > 6) { } 133 134 135 } 136 137 void LisaaVihollinen() 138 { 139 int n = 0; 140 while (n < 10) 141 { 142 143 144 double x = RandomGen.NextDouble(Level.Right, Level.Left); 145 PhysicsObject ukkeli1 = new PhysicsObject(40, 60); 146 //ukkeli1.Shape = Shape.FromImage("ukkeliP"); 147 ukkeli1.Animation = RandomGen.SelectOne(juusto, miesa); 148 ukkeli1.Animation.Start(); 149 ukkeli1.Animation.FPS = 5; 150 ukkeli1.Tag = "vihollinen"; 151 //PhysicsObject mies = new PhysicsObject(40, 60); 152 //mies.Animation = miesa; 153 //mies.Animation.Start(); 154 //mies.Animation.FPS = 4; 155 //mies.Tag = "vihollinen"; 156 ukkeli1.X = x; 157 //mies.X = x; 158 ukkeli1.Y = Level.Bottom + 80; 159 //mies.Y = Level.Bottom + 80; 160 161 Add(ukkeli1); 162 163 //Add(RandomGen.SelectOne (mies, ukkeli1)); 164 n++; 165 166 Timer ajastin = new Timer(); 167 ajastin.Interval = RandomGen.NextDouble(0.2, 2); 168 ajastin.Timeout += delegate 169 { 170 171 ukkeli1.Velocity = new Vector(RandomGen.SelectOne(-200, 200), 0); 172 }; 173 ajastin.Start(); 174 } 175 } 176 177 void TiputaPommi() 178 { 179 180 pommi = new PhysicsObject(50, 50); 181 //pommi.Shape = Shape.FromImage("pommik"); 182 pommi.Image = pommik; 183 pommi.Position = pelaaja.Position; 184 185 pommi.CollisionIgnoreGroup = pelaaja.CollisionIgnoreGroup; 186 187 188 Add(pommi); 189 190 AddCollisionHandler(pommi, PommiOsuu); 191 } 192 193 void PommiOsuu(PhysicsObject pommi, PhysicsObject kohde) 194 { 195 //Int k = 0; 196 197 if (kohde.Tag.Equals("vihollinen")) 198 { 199 kohde.Destroy(); 200 pisteLaskuri.Value += 1; 201 KomboLaskuri.Value += 1; 202 komboLaskurinAjastin.Reset(); 203 204 } 205 if (KomboLaskuri > 3) 206 { 207 208 Explosion e = new Explosion(600); 209 e.Position = pommi.Position; 210 pommi.Destroy(); 211 Add(e); 212 e.ShockwaveReachesObject += delegate(IPhysicsObject rKohde, Vector v) { if (rKohde.Tag.Equals("vihollinen")) rKohde.Destroy(); }; 213 } 214 else 215 { 216 Explosion e = new Explosion(60); 217 e.Position = pommi.Position; 218 pommi.Destroy(); 219 Add(e); 220 e.ShockwaveReachesObject += delegate(IPhysicsObject rKohde, Vector v) { if (rKohde.Tag.Equals("vihollinen")) rKohde.Destroy(); }; 221 //pisteet++;} 222 } 223 224 } 225 void Rajahdys() 226 { 227 228 } 229 230 void KaannaPelaajaa(double kaannos) 231 { 232 pelaaja.AngularVelocity = kaannos; 233 } 234 235 236 237 protected override void Update(Time time) 238 { 239 base.Update(time); 240 if (pelaaja != null) 241 { 242 if (pelaaja.Position.X > Level.Right) pelaaja.Position = new Vector(Level.Left, pelaaja.Position.Y); 243 if (pelaaja.Position.X < Level.Left) pelaaja.Position = new Vector(Level.Right, pelaaja.Position.Y); 244 } 245 } 246 247 void HidastaPelaajaa() 248 { 249 pelaaja.Velocity = new Vector(pelaaja.Velocity.X * 0.95, pelaaja.Velocity.Y); 250 251 } 252 253 void PelaajaTormasi(PhysicsObject tormaaja, PhysicsObject kohde) 254 { 255 256 } 257 void LiikutaPelaajaa(int suunta) 258 { 259 pelaaja.Push(Vector.FromLengthAndAngle(3000 * suunta, pelaaja.Angle)); 260 } 261 75 76 } 262 77 263 78 void LuoKentta() … … 271 86 272 87 PhysicsObject oikeaReuna = Level.CreateRightBorder(); 273 oikeaReuna.CollisionIgnoreGroup = pelaaja.CollisionIgnoreGroup;88 oikeaReuna.CollisionIgnoreGroup = 2; 274 89 275 90 PhysicsObject vasenReuna = Level.CreateLeftBorder(); 276 vasenReuna.CollisionIgnoreGroup = pelaaja.CollisionIgnoreGroup; 277 278 279 } 280 281 282 283 284 91 vasenReuna.CollisionIgnoreGroup = 2; 92 93 94 } 285 95 286 96 void LuoPelaaja() … … 306 116 } 307 117 118 void tiputamuu() 119 { 120 if (Rasa != null) return; 121 Rasa = new PhysicsObject(100, 100); 122 Rasa.Shape = Shape.FromImage(rasse); 123 Rasa.Position = pelaaja.Position; 124 Rasa.Animation = rasa; 125 Rasa.Animation.Start(); 126 Rasa.Animation.FPS = 3; 127 Rasa.CollisionIgnoreGroup = 2; 128 Add(Rasa); 129 130 RasasenTykki = new Cannon(50, 10); 131 RasasenTykki.Ammo.Value = 999; 132 RasasenTykki.ProjectileCollision = AmmusOsui; 133 134 Mouse.ListenMovement(0.1, Tahtaa, "Tähtää aseella"); 135 Keyboard.Listen(Key.NumPad8, ButtonState.Released, AmmuAseella, "Ammu", RasasenTykki); 136 137 Rasa.Add(RasasenTykki); 138 } 139 140 void TiputaPommi() 141 { 142 143 pommi = new PhysicsObject(50, 50); 144 //pommi.Shape = Shape.FromImage("pommik"); 145 pommi.Image = pommik; 146 pommi.Position = pelaaja.Position; 147 148 pommi.CollisionIgnoreGroup = pelaaja.CollisionIgnoreGroup; 149 150 151 Add(pommi); 152 153 AddCollisionHandler(pommi, PommiOsuu); 154 } 155 156 void LisaaVihollinen() 157 { 158 int n = 0; 159 while (n < 10) 160 { 161 162 163 double x = RandomGen.NextDouble(Level.Right, Level.Left); 164 PhysicsObject ukkeli1 = new PhysicsObject(40, 60); 165 ukkeli1.Animation = RandomGen.SelectOne(juusto, miesa); 166 ukkeli1.Animation.Start(); 167 ukkeli1.Animation.FPS = 5; 168 ukkeli1.Tag = "vihollinen"; 169 ukkeli1.X = x; 170 ukkeli1.Y = Level.Bottom + 80; 171 Add(ukkeli1); 172 n++; 173 Timer ajastin = new Timer(); 174 ajastin.Interval = RandomGen.NextDouble(0.2, 2); 175 ajastin.Timeout += delegate 176 { 177 178 ukkeli1.Velocity = new Vector(RandomGen.SelectOne(-200, 200), 0); 179 }; 180 ajastin.Start(); 181 } 182 } 183 184 void LuoPistelaskuri() 185 { 186 pisteLaskuri = new IntMeter(0); 187 188 Label pisteNaytto = new Label(); 189 pisteNaytto.X = Screen.Right - 100; 190 pisteNaytto.Y = Screen.Top - 100; 191 pisteNaytto.TextColor = Color.Green; 192 //pisteNaytto.Color = Color.White; 193 pisteNaytto.IntFormatString = "Pisteitä: {0:D1}"; 194 pisteNaytto.BindTo(pisteLaskuri); 195 Add(pisteNaytto); 196 } 197 198 void LuoKomboLaskuri() 199 { 200 KomboLaskuri = new IntMeter(0); 201 202 Label komboNaytto = new Label(); 203 komboNaytto.X = Screen.Right - 200; 204 komboNaytto.Y = Screen.Top - 200; 205 komboNaytto.TextColor = Color.Green; 206 //pisteNaytto.Color = Color.White; 207 komboNaytto.IntFormatString = "COMBO: {0:D1}"; 208 komboNaytto.BindTo(KomboLaskuri); 209 Add(komboNaytto); 210 211 komboLaskurinAjastin = new Timer(); 212 komboLaskurinAjastin.Interval = 5; 213 komboLaskurinAjastin.Timeout += delegate { KomboLaskuri.Reset(); }; 214 komboLaskurinAjastin.Start(); 215 216 KomboLaskuri.Changed += delegate { Kombot(); }; 217 218 219 220 221 } 222 223 void Kombot() 224 { 225 if (KomboLaskuri.Value == 10) 226 { 227 Label tekstikentta = new Label("Fatality"); 228 Add(tekstikentta); 229 // PommiOsuu(100); 230 231 } 232 233 if (KomboLaskuri.Value > 6) { } 234 235 236 } 237 238 void RasanenPommi() 239 { 240 PhysicsObject Raamattu = new PhysicsObject(30, 30); 241 Raamattu.Image = pommik; 242 Rasa.Throw(Raamattu, Angle.FromDegrees(30), 500); 243 Raamattu.CollisionIgnoreGroup = Rasa.CollisionIgnoreGroup; 244 AddCollisionHandler(Raamattu, RaamattuOsuu); 245 Add(Raamattu); 246 247 } 248 249 void Tahtaa(AnalogState hiirenLiike) 250 { 251 Vector suunta = (Mouse.PositionOnWorld - RasasenTykki.AbsolutePosition).Normalize(); 252 RasasenTykki.Angle = suunta.Angle; 253 } 254 255 void AmmuAseella(Cannon RasasenTykki) 256 { 257 PhysicsObject ammus = RasasenTykki.Shoot(); 258 259 if (ammus != null) 260 { 261 ammus.Size *= 6; 262 //ammus.Image = ... 263 //ammus.MaximumLifetime = TimeSpan.FromSeconds(2.0); 264 } 265 } 266 267 void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde) 268 { 269 if (kohde.Tag.Equals("vihollinen")) 270 { 271 kohde.Destroy(); 272 pisteLaskuri.Value += 1; 273 KomboLaskuri.Value += 1; 274 komboLaskurinAjastin.Reset(); 275 } 276 } 277 278 void RaamattuOsuu(PhysicsObject pommi, PhysicsObject kohde) 279 { 280 if (kohde.Tag.Equals("vihollinen")) 281 { 282 kohde.Destroy(); 283 pisteLaskuri.Value += 1; 284 KomboLaskuri.Value += 1; 285 komboLaskurinAjastin.Reset(); 286 } 287 if (KomboLaskuri > 3) 288 { 289 Explosion o = new Explosion(120); 290 o.Position = pommi.Position; 291 pommi.Destroy(); 292 Add(o); 293 o.ShockwaveReachesObject += delegate(IPhysicsObject rKohde, Vector v) 294 { 295 if (rKohde.Tag.Equals("vihollinen")) rKohde.Destroy(); 296 }; 297 } 298 else 299 { 300 Explosion o = new Explosion(60); 301 o.Position = pommi.Position; 302 pommi.Destroy(); 303 Add(o); 304 o.ShockwaveReachesObject += delegate(IPhysicsObject rKohde, Vector v) { if (rKohde.Tag.Equals("vihollinen")) rKohde.Destroy(); }; 305 //pisteet++;} 306 } 307 308 309 310 311 } 312 313 void PommiOsuu(PhysicsObject pommi, PhysicsObject kohde) 314 { 315 if (kohde.Tag.Equals("vihollinen")) 316 { 317 kohde.Destroy(); 318 pisteLaskuri.Value += 1; 319 KomboLaskuri.Value += 1; 320 komboLaskurinAjastin.Reset(); 321 } 322 if (KomboLaskuri > 3) 323 { 324 Explosion e = new Explosion(120); 325 e.Position = pommi.Position; 326 pommi.Destroy(); 327 Add(e); 328 e.ShockwaveReachesObject += delegate(IPhysicsObject rKohde, Vector v) 329 { 330 if (rKohde.Tag.Equals("vihollinen")) rKohde.Destroy(); 331 }; 332 } 333 else 334 { 335 Explosion o = new Explosion(60); 336 o.Position = pommi.Position; 337 pommi.Destroy(); 338 Add(o); 339 o.ShockwaveReachesObject += delegate(IPhysicsObject rKohde, Vector v) { if (rKohde.Tag.Equals("vihollinen")) rKohde.Destroy(); }; 340 //pisteet++;} 341 } 342 343 344 345 346 } 347 348 void KaannaPelaajaa(double kaannos) 349 { 350 pelaaja.AngularVelocity = kaannos; 351 } 352 353 protected override void Update(Time time) 354 { 355 base.Update(time); 356 if (pelaaja != null) 357 { 358 if (pelaaja.Position.X > Level.Right) pelaaja.Position = new Vector(Level.Left, pelaaja.Position.Y); 359 if (pelaaja.Position.X < Level.Left) pelaaja.Position = new Vector(Level.Right, pelaaja.Position.Y); 360 } 361 } 362 363 void HidastaPelaajaa() 364 { 365 pelaaja.Velocity = new Vector(pelaaja.Velocity.X * 0.95, pelaaja.Velocity.Y); 366 367 } 368 369 void PelaajaTormasi(PhysicsObject tormaaja, PhysicsObject kohde) 370 { 371 372 } 373 374 void LiikutaPelaajaa(int suunta) 375 { 376 pelaaja.Push(Vector.FromLengthAndAngle(3000 * suunta, pelaaja.Angle)); 377 } 378 308 379 void KaannaKohtiMaata() 309 380 { … … 316 387 } 317 388 389 void LiikutaRasasta(int suunta) 390 { 391 Rasa.Push(new Vector(suunta* 400, 0)); 392 if (Rasa.Position.X > Level.Right) 393 { 394 395 Rasa.Position = new Vector(Level.Left, Rasa.Position.Y); 396 return; 397 } 398 if (Rasa.Position.X <Level.Left) 399 { 400 401 Rasa.Position = new Vector(Level.Right, Rasa.Position.Y); 402 return; 403 } 404 } 318 405 319 406 } -
2013/30/VilleF/Lentokone/Lentokone/LentokoneContent/LentokoneContent.contentproj
r4652 r4659 139 139 </Compile> 140 140 </ItemGroup> 141 <ItemGroup> 142 <Compile Include="rasse.png"> 143 <Name>rasse</Name> 144 <Importer>TextureImporter</Importer> 145 <Processor>TextureProcessor</Processor> 146 </Compile> 147 </ItemGroup> 141 148 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 142 149 <!-- 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.