Changeset 4016
- Timestamp:
- 2013-06-07 12:30:17 (10 years ago)
- Location:
- 2013/23/LauriH/Peli_1/Peli_1
- Files:
-
- 18 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/23/LauriH/Peli_1/Peli_1/Peli_1/Peli_1.cs
r3986 r4016 12 12 PlatformCharacter Pelaaja2; 13 13 PlatformCharacter Vastustaja; 14 PlatformCharacter Vastustaja2;15 14 PlatformCharacter PelaajanAlus; 16 PlatformCharacter Hyokkaaja; 17 18 PhysicsObject PAmmus; 19 PhysicsObject Ammus; 20 21 private Image [] VastustajanLiike = LoadImages("Vastustaja", "Vastustaja2", "Vastustaja3"); 15 16 17 private Image[] VastustajanLiike = LoadImages("Vastustaja", "Vastustaja2", "Vastustaja3"); 18 private Image[] AlkuAnimaatio = LoadImages("Alku1", "Alku2", "Alku3", "Alku4", "Alku5", "Alku6"); 19 private Image[] ValiAnimaatio1 = LoadImages("Vali1", "Vali2", "Vali3"); 20 private Image[] ValiAnimaatio2 = LoadImages("2Vali1", "2Vali2", "2Vali3"); 21 private Image[] Uudestaan = LoadImages("Restart"); 22 private Image[] LoppuAnimaatio = LoadImages("Loppu"); 22 23 Image PelaajanKuva = LoadImage("Pelaaja"); 23 24 Image HyokkaajanKuva = LoadImage("Hyokkaaja"); 24 25 Image AluksenKuva = LoadImage("Alus"); 25 26 Image AsteroidiKuva = LoadImage("Asteroidi"); 26 27 Image AmmusKuva = LoadImage("Ammus"); 28 Image TaustaKuva1 = LoadImage("Metsa"); 29 Image TaustaKuva2 = LoadImage("Kaupunki"); 30 Image TaustaKuva3 = LoadImage("Avaruus"); 27 31 28 32 const double Nopeus = 200; … … 31 35 const double LaskuNopeus = 500; 32 36 33 DoubleMeter elamaLaskuri; 37 DoubleMeter elamaLaskuri; 34 38 IntMeter keratytPallot; 35 IntMeter TuhoLaskuri;36 39 int kenttaNro = 1; 37 40 string kenttaTiedostonNimi; … … 42 45 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 43 46 } 44 void LuoKentta(string kenttaTiedostonNimi) 45 { 46 TileMap ruudut = TileMap.FromLevelAsset(kenttaTiedostonNimi); 47 ruudut.SetTileMethod('#', LuoPalikka); 48 ruudut.SetTileMethod('P', LuoPelaaja); 49 ruudut.SetTileMethod('p', LuoPelaaja2); 50 ruudut.SetTileMethod('?', LuoPallo); 51 ruudut.SetTileMethod('M', LuoMaali); 52 ruudut.SetTileMethod('O', LuoVastustaja); 53 ruudut.SetTileMethod('o', LuoVastustaja2); 54 ruudut.SetTileMethod('H', LuoHyokkaaja); 55 ruudut.Execute(20,20); 56 57 Gravity = new Vector(0, -1000); 47 void LuoKentta(string kenttaTiedostonNimi) 48 { 49 TileMap ruudut = TileMap.FromLevelAsset(kenttaTiedostonNimi); 50 ruudut.SetTileMethod('#', LuoPalikka); 51 ruudut.SetTileMethod('P', LuoPelaaja); 52 ruudut.SetTileMethod('p', LuoPelaaja2); 53 ruudut.SetTileMethod('?', LuoPallo); 54 ruudut.SetTileMethod('M', LuoMaali); 55 ruudut.SetTileMethod('O', LuoVastustaja); 56 ruudut.SetTileMethod('o', LuoVastustaja2); 57 ruudut.SetTileMethod('H', LuoHyokkaaja); 58 59 ruudut.Execute(20, 20); 60 61 if (kenttaNro == 1) 62 { 63 //Pause(); 64 AnimaatioAlku(AlkuAnimaatio); 65 } 66 67 else if (kenttaNro == 3) 68 { 69 AnimaatioAlku(ValiAnimaatio1); 70 } 71 72 73 if (kenttaNro <= 2) 74 { 75 Level.Background.Image = TaustaKuva1; 76 } 77 78 else if (kenttaNro == 3 || kenttaNro == 4) 79 { 80 Level.Background.Image = TaustaKuva2; 81 } 82 83 Level.Background.FitToLevel(); 84 85 Gravity = new Vector(0, -1000); 86 Laskurit(); 87 Level.CreateBorders(); 88 89 90 } 91 92 void AnimaatioAlku(Image[] animaatioKuvat) 93 { 94 Label label = new Label(); 95 label.Size = new Vector(Screen.Width, Screen.Height); 96 label.Animation = new Animation(animaatioKuvat); 97 Add(label); 98 label.Animation.FPS = 1; 99 label.Animation.Start(1); 100 label.Animation.Played += delegate { 101 label.Destroy(); 102 //if (IsPaused) Pause(); 103 }; 104 } 105 106 //void AnimaatioVali_1(Image[] animaatioKuvat) 107 //{ 108 // Label label = new Label(); 109 // label.Size = new Vector(Screen.Width, Screen.Height); 110 // label.Animation = new Animation(ValiAnimaatio1); 111 // Add(label); 112 // label.Animation.Played += SeuraavaKentta; 113 //} 114 115 //void AnimaatioVali_2() 116 //{ 117 // Label label = new Label(); 118 // label.Size = new Vector(Screen.Width, Screen.Height); 119 // label.Animation = new Animation(ValiAnimaatio2); 120 // Add(label); 121 // label.Animation.Played += SeuraavaKentta; 122 //} 123 124 //void AnimaatioLoppu() 125 //{ 126 // Label label = new Label(); 127 // label.Size = new Vector(Screen.Width, Screen.Height); 128 // label.Animation = new Animation(LoppuAnimaatio); 129 // Add(label); 130 // label.Animation.Played += SeuraavaKentta; 131 //} 132 133 void AnimaatioRestart() 134 { 135 Label label = new Label(); 136 label.Size = new Vector(Screen.Width, Screen.Height); 137 label.Animation = new Animation(Uudestaan); 138 Add(label); 139 label.Animation.Start(1); 140 label.Animation.Played += delegate 141 { 142 label.Destroy(); 143 SeuraavaKentta(); 144 //if (IsPaused) Pause(); 145 }; 146 147 } 148 149 void SeuraavaKentta() 150 { 151 ClearAll(); 152 if (IsPaused) Pause(); 153 if (kenttaNro == 1) 154 { 155 //AnimaatioAlku(); 156 LuoKentta("Taso_1"); 157 } 158 else if (kenttaNro == 2) 159 { LuoKentta("Taso_2"); } 160 else if (kenttaNro == 3) 161 { LuoKentta("Taso_3"); } 162 else if (kenttaNro == 4) 163 { LuoKentta("Taso_4"); } 164 else if (kenttaNro == 5) 165 { LuoKentta5(); } 166 else if (kenttaNro > 5) 167 { Exit(); } 168 169 AsetaOhjaimet(); 170 171 if (kenttaNro <= 2) 172 { 58 173 Camera.Follow(Pelaaja); 59 Camera.StayInLevel = true; 60 Laskurit(); 61 62 Level.CreateBorders(); 63 } 64 65 void SeuraavaKentta() 66 { 67 ClearAll(); 68 if (kenttaNro == 1) 69 { LuoKentta("Taso_1"); } 70 else if (kenttaNro == 2) 71 { LuoKentta("Taso_2"); } 72 else if (kenttaNro == 3) 73 { LuoKentta("Taso_3"); } 74 else if (kenttaNro == 4) 75 { LuoKentta("Taso_4"); } 76 else if (kenttaNro == 5) 77 {LuoKentta5(); } 78 else if (kenttaNro > 5) 79 { Exit(); } 80 81 AsetaOhjaimet(); 82 83 } 84 85 void LuoKentta5() 86 { 87 TileMap ruudut = TileMap.FromLevelAsset("Taso_5"); 88 ruudut.SetTileMethod('A', LuoPelaajanAlus); 89 ruudut.SetTileMethod('H', LuoHyokkaaja); 90 ruudut.SetTileMethod('M', LuoAsteroidi); 91 ruudut.Execute(20, 20); 92 93 Level.CreateBottomBorder(); 94 Level.CreateTopBorder(); 95 Level.CreateLeftBorder(); 96 97 Camera.Follow(Pelaaja); 98 Camera.StayInLevel = true; 99 Laskurit(); 100 AsetaOhjaimet(); 101 } 102 103 void Valikko() 104 { 105 MultiSelectWindow alkuValikko = new MultiSelectWindow("Pelin alkuvalikko", "Taso 1", "Taso 2", "Taso 3", "Taso 4", "Taso 5", "Lopeta"); 106 Add(alkuValikko); 107 108 alkuValikko.AddItemHandler(0, delegate { kenttaNro = 1; SeuraavaKentta(); }); 109 alkuValikko.AddItemHandler(1, delegate { kenttaNro = 2; SeuraavaKentta(); }); 110 alkuValikko.AddItemHandler(2, delegate { kenttaNro = 3; SeuraavaKentta(); }); 111 alkuValikko.AddItemHandler(3, delegate { kenttaNro = 4; SeuraavaKentta(); }); 112 alkuValikko.AddItemHandler(4, LuoKentta5); 113 } 114 115 void LuoPelaaja(Vector paikka, double leveys, double korkeus) 116 { 117 Pelaaja = new PlatformCharacter(50,50); 118 Pelaaja.Position = paikka; 119 Pelaaja.Image = PelaajanKuva; 120 AddCollisionHandler(Pelaaja, "pallo", TormaaPalloon); 121 AddCollisionHandler(Pelaaja, "Vastustaja", TormaaVastustajaan); 122 AddCollisionHandler(Pelaaja, "Maali", TormaaMaaliin); 123 Add(Pelaaja); 124 } 125 126 void LuoPelaaja2(Vector paikka, double leveys, double korkeus) 127 { 128 Pelaaja2 = new PlatformCharacter(50, 50); 129 Pelaaja2.Position = paikka; 130 Pelaaja2.Image = PelaajanKuva; 131 AddCollisionHandler(Pelaaja2, "pallo", TormaaPalloon); 132 AddCollisionHandler(Pelaaja2, "Vastustaja", TormaaVastustajaan); 133 AddCollisionHandler(Pelaaja2, "Maali", TormaaMaaliin); 134 Add(Pelaaja); 135 Pelaaja2.Weapon = new LaserGun(10, 10); 136 Pelaaja2.Weapon.FireRate = 5.0; 137 138 139 } 140 141 void LuoPelaajanAlus(Vector paikka, double leveys, double korkeus) 142 { 143 PelaajanAlus = new PlatformCharacter(50, 50); 144 PelaajanAlus.Position = paikka; 145 PelaajanAlus.Image = AluksenKuva; 146 AddCollisionHandler(PelaajanAlus, "Ammus", TormaaAmmukseen); 147 AddCollisionHandler(Pelaaja, "Maali", TormaaMaaliin); 148 AddCollisionHandler(Pelaaja, "Asteroidi", TormaaAsteroidiin); 149 PelaajanAlus.Weapon = new LaserGun(10, 10); 150 PelaajanAlus.Weapon.FireRate = 5.0; 151 152 Add(PelaajanAlus); 153 154 } 155 156 void LuoHyokkaaja(Vector paikka, double leveys, double korkeus) 157 { 158 Hyokkaaja = new PlatformCharacter(50, 50); 159 Hyokkaaja.Position = paikka; 160 Hyokkaaja.Image = HyokkaajanKuva; 161 AddCollisionHandler(PAmmus, "Hyokkaaja", TormaaPAmmukseen); 162 Add(Hyokkaaja); 163 164 FollowerBrain seurausAivot = new FollowerBrain(); 165 seurausAivot.Speed = 200; 166 Vastustaja2.Brain = seurausAivot; 167 168 Hyokkaaja.Weapon = new LaserGun(10, 10); 169 Hyokkaaja.Weapon.FireRate = 5.0; 170 } 171 172 void LuoAsteroidi(Vector paikka, double leveys, double korkeus) 173 { 174 PhysicsObject Asteroidi = new PhysicsObject(30, 30); 175 Asteroidi.Position = paikka; 176 Asteroidi.Image = AsteroidiKuva; 177 Asteroidi.Tag = "Asteroidi"; 178 179 RandomMoverBrain HaahuiluAivot = new RandomMoverBrain(); 180 HaahuiluAivot.ChangeMovementSeconds = 3; 181 HaahuiluAivot.WanderRadius = 200; 182 Asteroidi.Brain = HaahuiluAivot; 183 184 185 186 } 187 188 void LuoPalikka(Vector paikka, double leveys, double korkeus) 189 { 190 PhysicsObject Taso = PhysicsObject.CreateStaticObject(leveys, korkeus); 191 Taso.Position = paikka; 192 Taso.Color = Color.Green; 193 Add(Taso); 194 } 195 196 void LuoPallo(Vector paikka, double leveys, double korkeus) 197 { 198 PhysicsObject pallo = new PhysicsObject (10,10); 199 pallo.MakeStatic(); 200 pallo.Shape = Shape.Circle; 201 pallo.Color = Color.Red; 202 pallo.Position = paikka; 203 pallo.Tag = "pallo"; 204 Add(pallo, 1); 205 206 pallo.IgnoresGravity = true; 207 pallo.IgnoresCollisionResponse = true; 208 209 } 210 211 void LuoVastustaja(Vector paikka, double leveys, double korkeus) 212 { 213 Vastustaja = new PlatformCharacter(50,50); 214 Vastustaja.Position = paikka; 215 Vastustaja.Animation = new Animation(VastustajanLiike); 216 Vastustaja.Tag = "Vastustaja"; 217 218 Add(Vastustaja); 219 220 Vastustaja.Animation.Start(); 221 222 // Vastustaja2.Weapon = new LaserGun(10, 10); 223 224 PlatformWandererBrain tasoAivot = new PlatformWandererBrain(); 225 tasoAivot.Speed = 100; 226 227 Vastustaja.Brain = tasoAivot; 228 229 230 } 231 232 void LuoVastustaja2(Vector paikka, double leveys, double korkeus) 233 { 234 Vastustaja2 = new PlatformCharacter(50, 50); 235 Vastustaja2.Position = paikka; 236 Vastustaja2.Animation = new Animation(VastustajanLiike); 237 Vastustaja2.Tag = "Vastustaja"; 238 239 Add(Vastustaja); 240 241 Vastustaja.Animation.Start(); 242 243 FollowerBrain seurausAivot = new FollowerBrain(); 244 seurausAivot.Speed = 200; 245 Vastustaja2.Brain = seurausAivot; 246 247 Vastustaja2.Weapon = new LaserGun(10, 10); 248 Vastustaja2.Weapon.FireRate = 5.0; 249 } 250 251 void LuoMaali(Vector paikka, double leveys, double korkeus) 252 { 253 PhysicsObject Maali = new PhysicsObject(100, 1000); 254 Maali.Position = paikka; 255 Maali.Shape = Shape.Rectangle; 256 Maali.Color = Color.Yellow; 257 Maali.Tag = "Maali"; 258 Add(Maali); 259 } 260 261 void AsetaOhjaimet() 262 { 263 if(kenttaNro <= 2) 264 { 174 Camera.ZoomTo(Pelaaja.Position + new Vector(-200, -200), Pelaaja.Position + new Vector(200, 200)); 175 } 176 if (kenttaNro == 3 || kenttaNro == 4) 177 { 178 Camera.Follow(Pelaaja2); 179 Camera.ZoomTo(Pelaaja2.Position + new Vector(-200, -200), Pelaaja2.Position + new Vector(200, 200)); 180 } 181 if (kenttaNro == 5) 182 { 183 Camera.Follow(PelaajanAlus); 184 Camera.ZoomTo(PelaajanAlus.Position + new Vector(-200, -200), PelaajanAlus.Position + new Vector(200, 200)); 185 } 186 Camera.StayInLevel = true; 187 188 } 189 190 void LuoKentta5() 191 { 192 TileMap ruudut = TileMap.FromLevelAsset("Taso_5"); 193 ruudut.SetTileMethod('A', LuoPelaajanAlus); 194 ruudut.SetTileMethod('H', LuoHyokkaaja); 195 ruudut.SetTileMethod('m', LuoAsteroidi); 196 ruudut.SetTileMethod('M', LuoMaali); 197 ruudut.Execute(20, 20); 198 Level.Background.Image = TaustaKuva3; 199 Level.Background.FitToLevel(); 200 Level.CreateBottomBorder(); 201 Level.CreateTopBorder(); 202 Level.CreateLeftBorder(); 203 204 if (kenttaNro == 5) 205 { 206 AnimaatioAlku(ValiAnimaatio2); 207 } 208 209 210 211 Camera.StayInLevel = true; 212 Laskurit(); 213 214 } 215 216 void Valikko() 217 { 218 if (!(IsPaused)) Pause(); 219 MultiSelectWindow alkuValikko = new MultiSelectWindow("Pelin alkuvalikko", "Taso 1", "Taso 2", "Taso 3", "Taso 4", "Taso 5", "Jatka", "Lopeta"); 220 Add(alkuValikko); 221 222 alkuValikko.AddItemHandler(0, delegate { kenttaNro = 1; SeuraavaKentta(); }); 223 alkuValikko.AddItemHandler(1, delegate { kenttaNro = 2; SeuraavaKentta(); }); 224 alkuValikko.AddItemHandler(2, delegate { kenttaNro = 3; SeuraavaKentta(); }); 225 alkuValikko.AddItemHandler(3, delegate { kenttaNro = 4; SeuraavaKentta(); }); 226 alkuValikko.AddItemHandler(4, delegate { kenttaNro = 5; SeuraavaKentta(); }); 227 alkuValikko.AddItemHandler(5, delegate 228 { 229 alkuValikko.Destroy(); 230 Pause(); 231 if (Pelaaja == null && Pelaaja2 == null && PelaajanAlus == null) 232 kenttaNro = 1; SeuraavaKentta(); 233 }); 234 alkuValikko.AddItemHandler(6, Exit); 235 } 236 237 void AsetaOhjaimet() 238 { 239 if (kenttaNro <= 2) 240 { 265 241 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 266 242 Keyboard.Listen(Key.Up, ButtonState.Pressed, PelaajaHyppaa, "Pelaaja hyppää", Pelaaja, HyppyNopeus); 267 243 Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, "Pelaaja liiku oikealle", Pelaaja, Nopeus); 268 244 Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, "Pelaaja liiku vasemmalle", Pelaaja, -Nopeus); 245 } 246 247 else if (kenttaNro == 3 || kenttaNro == 4) 248 { 249 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 250 Keyboard.Listen(Key.Up, ButtonState.Pressed, PelaajaHyppaa, "Pelaaja hyppää", Pelaaja2, HyppyNopeus); 251 Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, "Pelaaja liiku oikealle", Pelaaja2, Nopeus); 252 Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, "Pelaaja liiku vasemmalle", Pelaaja2, -Nopeus); 253 Keyboard.Listen(Key.Space, ButtonState.Down, AmmuAseella, "Ammu vastustajaa", Pelaaja2); 254 } 255 256 else if (kenttaNro == 5) 257 { 258 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 259 Keyboard.Listen(Key.Up, ButtonState.Down, SiirraPelaajanAlusta, "Alus ylös", PelaajanAlus, 0.0, 5.0); 260 Keyboard.Listen(Key.Down, ButtonState.Down, SiirraPelaajanAlusta, "Alus alas", PelaajanAlus, 0.0, -5.0); 261 Keyboard.Listen(Key.Space, ButtonState.Down, AmmuAseella, "Lopeta peli", PelaajanAlus); 262 Keyboard.Listen(Key.Right, ButtonState.Down, SiirraPelaajanAlusta, "alus oikealle", PelaajanAlus, 5.0, 0.0); 263 } 264 Keyboard.Listen(Key.X, ButtonState.Pressed, Valikko, null); 265 } 266 267 void LuoPelaaja(Vector paikka, double leveys, double korkeus) 268 { 269 Pelaaja = new PlatformCharacter(50, 50); 270 Pelaaja.Position = paikka; 271 Pelaaja.Image = PelaajanKuva; 272 AddCollisionHandler(Pelaaja, "pallo", TormaaPalloon); 273 AddCollisionHandler(Pelaaja, "Vastustaja", TormaaVastustajaan); 274 AddCollisionHandler(Pelaaja, "Maali", TormaaMaaliin); 275 Add(Pelaaja); 276 } 277 278 void LuoPelaaja2(Vector paikka, double leveys, double korkeus) 279 { 280 Pelaaja2 = new PlatformCharacter(50, 50); 281 Pelaaja2.Position = paikka; 282 Pelaaja2.Image = PelaajanKuva; 283 Pelaaja2.Tag = "Pelaaja2"; 284 AddCollisionHandler(Pelaaja2, "pallo", TormaaPalloon); 285 AddCollisionHandler(Pelaaja2, "Vastustaja", TormaaVastustajaan); 286 AddCollisionHandler(Pelaaja2, "Maali", TormaaMaaliin2); 287 AddCollisionHandler(Pelaaja2, "Ammus", VastustajanAmmusOsuu); 288 Add(Pelaaja2); 289 Pelaaja2.Weapon = new LaserGun(25, 10); 290 Pelaaja2.Weapon.FireRate = 5.0; 291 Pelaaja2.Weapon.ProjectileCollision += Pelaaja2AmmusOsuu; 292 293 } 294 295 void LuoPelaajanAlus(Vector paikka, double leveys, double korkeus) 296 { 297 PelaajanAlus = new PlatformCharacter(50, 50); 298 PelaajanAlus.CanMoveOnAir = true; 299 PelaajanAlus.WalkOnAir = true; 300 PelaajanAlus.Velocity = new Vector(500, 0); 301 PelaajanAlus.Position = paikka; 302 PelaajanAlus.Image = AluksenKuva; 303 PelaajanAlus.Tag = "PelaajanAlus"; 304 AddCollisionHandler(PelaajanAlus, "Maali", TormaaMaaliin2); 305 AddCollisionHandler(PelaajanAlus, "Asteroidi", TormaaAsteroidiin); 306 PelaajanAlus.Weapon = new LaserGun(10, 10); 307 PelaajanAlus.Weapon.FireRate = 5.0; 308 PelaajanAlus.Weapon.ProjectileCollision += (AmmusOsuuHyokkaajaan); 309 PelaajanAlus.Hit(new Vector(1000, 0)); 310 PelaajanAlus.KineticFriction = 0; 311 PelaajanAlus.Destroyed += delegate { SeuraavaKentta(); }; 312 Add(PelaajanAlus); 313 314 315 } 316 317 void LuoVastustaja(Vector paikka, double leveys, double korkeus) 318 { 319 Vastustaja = new PlatformCharacter(50, 50); 320 Vastustaja.Position = paikka; 321 Vastustaja.Animation = new Animation(VastustajanLiike); 322 Vastustaja.Tag = "Vastustaja"; 323 324 Add(Vastustaja); 325 326 Vastustaja.Animation.Start(); 327 328 PlatformWandererBrain tasoAivot = new PlatformWandererBrain(); 329 tasoAivot.Speed = 100; 330 331 Vastustaja.Brain = tasoAivot; 332 333 334 } 335 336 void LuoVastustaja2(Vector paikka, double leveys, double korkeus) 337 { 338 PlatformCharacter Vastustaja2 = new PlatformCharacter(50, 50); 339 Vastustaja2.Position = paikka; 340 Vastustaja2.Animation = new Animation(VastustajanLiike); 341 Vastustaja2.Tag = "Vastustaja"; 342 343 Add(Vastustaja2); 344 345 Vastustaja2.Animation.Start(); 346 347 FollowerBrain seurausAivot = new FollowerBrain(Pelaaja2); 348 seurausAivot.Speed = 200; 349 Vastustaja2.Brain = seurausAivot; 350 351 Vastustaja2.Weapon = new LaserGun(10, 10); 352 Vastustaja2.Weapon.FireRate = 5.0; 353 Vastustaja2.Weapon.ProjectileCollision += VastustajanAmmusOsuu; 354 Vastustaja2.Weapon.CanHitOwner = false; 355 Timer ajastin = new Timer(); 356 ajastin.Interval = 1; 357 ajastin.Timeout += delegate 358 { 359 PhysicsObject ammus = Vastustaja2.Weapon.Shoot(); 360 if (ammus != null) 361 { 362 ammus.Color = Color.Violet; 363 ammus.Tag = "Ammus"; 269 364 } 270 271 else if(kenttaNro == 3 && kenttaNro == 4) 272 { 273 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 274 Keyboard.Listen(Key.Up, ButtonState.Pressed, PelaajaHyppaa, "Pelaaja hyppää", Pelaaja, HyppyNopeus); 275 Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, "Pelaaja liiku oikealle", Pelaaja, Nopeus); 276 Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, "Pelaaja liiku vasemmalle", Pelaaja, -Nopeus); 277 Keyboard.Listen(Key.Space, ButtonState.Down, AmmuAseella, "Ammu vastustajaa", Pelaaja); 278 } 279 280 else if(kenttaNro == 5) 281 { 282 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 283 Keyboard.Listen(Key.Up, ButtonState.Down, SiirraPelaajaa, "Alus ylös", Pelaaja, 1.0); 284 Keyboard.Listen(Key.Escape, ButtonState.Down, SiirraPelaajaa, "Alus alas", Pelaaja, 1.0); 285 Keyboard.Listen(Key.Space, ButtonState.Down, AmmuAseella, "Lopeta peli", Pelaaja); 286 } 287 } 288 289 void PelaajaHyppaa(PlatformCharacter pelaaja, double nopeus) 290 { 291 pelaaja.Jump(nopeus); 292 } 293 294 void LiikutaPelaajaa(PlatformCharacter pelaaja, double nopeus) 295 { 296 pelaaja.Walk(nopeus); 297 } 298 299 void SiirraPelaajaa(PlatformCharacter Pelaaja, double paikanSiirto) 300 { 301 Pelaaja.Position += new Vector(0, paikanSiirto); 302 } 303 304 305 void AmmuAseella(PlatformCharacter Pelaaja) 306 { 307 PhysicsObject ammus = Pelaaja.Weapon.Shoot(); 308 309 //if(ammus) 310 } 311 312 void Laskurit() 313 { 314 LuoElamaLaskuri(Screen.Left + 100, Screen.Top - 100); 315 keratytPallot = LuoPistelaskuri(Screen.Left + 100, Screen.Top - 200); 316 TuhoLaskuri = LuoTuholaskuri(Screen.Left + 100, Screen.Top - 300); 317 } 318 319 void LuoElamaLaskuri(double x, double y) 365 }; 366 ajastin.Start(); 367 } 368 369 void LuoHyokkaaja(Vector paikka, double leveys, double korkeus) 370 { 371 PlatformCharacter Hyokkaaja = new PlatformCharacter(50, 50); 372 Hyokkaaja.Position = paikka; 373 Hyokkaaja.Image = HyokkaajanKuva; 374 Hyokkaaja.Tag = "Hyokkaaja"; 375 Hyokkaaja.IgnoresCollisionResponse = false; 376 AddCollisionHandler(Hyokkaaja, "Asteroidi", TormaaAsteroidiin); 377 Add(Hyokkaaja); 378 379 FollowerBrain seurausAivot = new FollowerBrain("PelaajanAlus"); 380 seurausAivot.Speed = 200; 381 Hyokkaaja.Brain = seurausAivot; 382 383 Hyokkaaja.Weapon = new LaserGun(10, 10); 384 Hyokkaaja.Weapon.FireRate = 5.0; 385 Hyokkaaja.Weapon.ProjectileCollision += HyokkaajanAmmusOsuu; 386 Timer ajastin = new Timer(); 387 ajastin.Interval = 1; 388 ajastin.Timeout += delegate { PhysicsObject ammus = Hyokkaaja.Weapon.Shoot(); if (ammus != null) ammus.Tag = "Ammus"; }; 389 ajastin.Start(); 390 } 391 392 void HyokkaajanAmmusOsuu(PhysicsObject ammus, PhysicsObject kohde) 393 { 394 ammus.Destroy(); 395 if (kohde.Tag.Equals("PelaajanAlus")) 396 { 397 MessageDisplay.Add("Ai varo vähän!!!"); 398 PelaajanAlus.IgnoresExplosions = true; 399 400 Explosion rajahdys = new Explosion(50); 401 rajahdys.Position = PelaajanAlus.Position; 402 rajahdys.Speed = 1000.0; 403 rajahdys.Force = 10; 404 Add(rajahdys); 405 elamaLaskuri.Value -= 1; 406 } 407 } 408 409 void VastustajanAmmusOsuu(PhysicsObject ammus, PhysicsObject kohde) 410 { 411 ammus.Destroy(); 412 if (kohde.Tag.Equals("Pelaaja2")) 413 { 414 MessageDisplay.Add("Ai varo vähän!!!"); 415 elamaLaskuri.Value -= 1; 416 } 417 } 418 419 void LuoAsteroidi(Vector paikka, double leveys, double korkeus) 420 { 421 PhysicsObject Asteroidi = new PhysicsObject(30, 30); 422 Asteroidi.Position = paikka; 423 Asteroidi.Image = AsteroidiKuva; 424 Asteroidi.Tag = "Asteroidi"; 425 Add(Asteroidi); 426 427 RandomMoverBrain HaahuiluAivot = new RandomMoverBrain(); 428 HaahuiluAivot.ChangeMovementSeconds = 3; 429 HaahuiluAivot.WanderRadius = 200; 430 Asteroidi.Brain = HaahuiluAivot; 431 432 433 434 } 435 436 void LuoPalikka(Vector paikka, double leveys, double korkeus) 437 { 438 PhysicsObject Taso = PhysicsObject.CreateStaticObject(leveys, korkeus); 439 Taso.Position = paikka; 440 Taso.Color = Color.Green; 441 Add(Taso); 442 443 if (kenttaNro == 3 || kenttaNro == 4) 444 { 445 Taso.Color = Color.Black; 446 } 447 } 448 449 void LuoPallo(Vector paikka, double leveys, double korkeus) 450 { 451 PhysicsObject pallo = new PhysicsObject(10, 10); 452 pallo.MakeStatic(); 453 pallo.Shape = Shape.Circle; 454 pallo.Color = Color.Red; 455 pallo.Position = paikka; 456 pallo.Tag = "pallo"; 457 Add(pallo, 1); 458 459 pallo.IgnoresGravity = true; 460 pallo.IgnoresCollisionResponse = true; 461 462 } 463 464 void LuoMaali(Vector paikka, double leveys, double korkeus) 465 { 466 PhysicsObject Maali = new PhysicsObject(leveys, korkeus); 467 Maali.MakeStatic(); 468 Maali.IgnoresGravity = true; 469 Maali.IgnoresExplosions = true; 470 Maali.IgnoresCollisionResponse = true; 471 Maali.Position = paikka; 472 Maali.Shape = Shape.Rectangle; 473 Maali.Color = Color.Yellow; 474 Maali.Tag = "Maali"; 475 Maali.IsVisible = true; 476 Add(Maali); 477 478 } 479 480 void PelaajaHyppaa(PlatformCharacter pelaaja, double nopeus) 481 { 482 pelaaja.Jump(nopeus); 483 } 484 485 void LiikutaPelaajaa(PlatformCharacter pelaaja, double nopeus) 486 { 487 pelaaja.Walk(nopeus); 488 } 489 490 void SiirraPelaajanAlusta(PlatformCharacter PelaajanAlus, double x, double y) 491 { 492 PelaajanAlus.Position += new Vector(x, y); 493 } 494 495 void AmmuAseella(PlatformCharacter Pelaaja) 496 { 497 PhysicsObject ammus = Pelaaja.Weapon.Shoot(); 498 if (ammus == null) return; 499 ammus.Tag = "Ammus"; 500 501 } 502 503 void AmmusOsuuHyokkaajaan(PhysicsObject ammus, PhysicsObject hyokkaaja) 504 { 505 if ("Hyokkaaja".Equals(hyokkaaja.Tag)) 506 hyokkaaja.Destroy(); 507 ammus.Destroy(); 508 } 509 510 void Pelaaja2AmmusOsuu(PhysicsObject ammus, PhysicsObject kohde) 511 { 512 513 if (kohde.Tag.Equals("Vastustaja")) 514 { 515 kohde.Destroy(); 516 517 } 518 ammus.Destroy(); 519 520 } 521 522 void Laskurit() 523 { 524 LuoElamaLaskuri(Screen.Left + 100, Screen.Top - 100); 525 keratytPallot = LuoPistelaskuri(Screen.Left + 100, Screen.Top - 200); 526 } 527 528 void LuoElamaLaskuri(double x, double y) 529 { 530 if (kenttaNro <= 2) 320 531 { 321 532 elamaLaskuri = new DoubleMeter(10); 322 533 elamaLaskuri.MaxValue = 10; 323 534 elamaLaskuri.LowerLimit += ElamaLoppui; 324 325 ProgressBar elamaPalkki = new ProgressBar(100, 20); 326 elamaPalkki.BindTo(elamaLaskuri); 327 elamaPalkki.X = Screen.Left +100; 328 elamaPalkki.Y = Screen.Top - 100; 329 elamaPalkki.BorderColor = Color.Black; 330 Add(elamaPalkki); 331 332 } 333 334 void ElamaLoppui() 335 { 336 MessageDisplay.Add("AUUUUUUUU!!! \n Game Over"); 535 } 536 537 else if (kenttaNro >= 3) 538 { 539 elamaLaskuri = new DoubleMeter(1); 540 elamaLaskuri.MaxValue = 100; 541 elamaLaskuri.LowerLimit += ElamaLoppui; 542 } 543 544 ProgressBar elamaPalkki = new ProgressBar(100, 20); 545 elamaPalkki.BindTo(elamaLaskuri); 546 elamaPalkki.X = Screen.Left + 100; 547 elamaPalkki.Y = Screen.Top - 100; 548 elamaPalkki.BorderColor = Color.Black; 549 Add(elamaPalkki); 550 551 } 552 553 void ElamaLoppui() 554 { 555 AnimaatioRestart(); 556 557 } 558 559 IntMeter LuoPistelaskuri(double x, double y) 560 { 561 IntMeter laskuri = new IntMeter(0); 562 laskuri.MaxValue = 11; 563 564 Label naytto = new Label(); 565 naytto.BindTo(laskuri); 566 naytto.X = x; 567 naytto.Y = y; 568 naytto.TextColor = Color.White; 569 naytto.BorderColor = Level.BackgroundColor; 570 naytto.Color = Level.BackgroundColor; 571 Add(naytto); 572 573 return laskuri; 574 575 } 576 577 void TormaaPalloon(PhysicsObject Pelaaja, PhysicsObject pallo) 578 { 579 MessageDisplay.Add("Sait pallon!"); 580 keratytPallot.Value += 1; 581 pallo.Destroy(); 582 } 583 584 void TormaaVastustajaan(PhysicsObject Pelaaja, PhysicsObject Vastustaja) 585 { 586 MessageDisplay.Add("Ai varo vähän!!!"); 587 elamaLaskuri.Value -= 1; 588 } 589 590 void TormaaMaaliin(PhysicsObject Maali, PhysicsObject Pelaaja) 591 { 592 if (keratytPallot == 11) 593 { 594 MessageDisplay.Add("LOISTAVAA"); 595 kenttaNro++; 337 596 SeuraavaKentta(); 338 597 } 339 598 340 IntMeter LuoPistelaskuri(double x, double y) 341 { 342 IntMeter laskuri = new IntMeter(0); 343 laskuri.MaxValue = 11; 344 345 Label naytto = new Label(); 346 naytto.BindTo(laskuri); 347 naytto.X = x; 348 naytto.Y = y; 349 naytto.TextColor = Color.White; 350 naytto.BorderColor = Level.BackgroundColor; 351 naytto.Color = Level.BackgroundColor; 352 Add(naytto); 353 354 return laskuri; 355 356 } 357 358 IntMeter LuoTuholaskuri(double x, double y) 359 { 360 IntMeter laskuri = new IntMeter(0); 361 laskuri.MaxValue = 10; 362 363 Label naytto = new Label(); 364 naytto.BindTo(laskuri); 365 naytto.X = x; 366 naytto.Y = y; 367 naytto.TextColor = Color.Red; 368 naytto.BorderColor = Level.BackgroundColor; 369 naytto.Color = Level.BackgroundColor; 370 Add(naytto); 371 372 return laskuri; 373 } 374 375 void TormaaPalloon(PhysicsObject Pelaaja, PhysicsObject pallo) 376 { 377 MessageDisplay.Add("Sait pallon!"); 378 keratytPallot.Value += 1; 379 pallo.Destroy(); 380 } 381 382 void TormaaVastustajaan(PhysicsObject Pelaaja, PhysicsObject Vastustaja) 383 { 384 MessageDisplay.Add("Ai varo vähän!!!"); 385 elamaLaskuri.Value -= 1; 386 } 387 388 void TormaaMaaliin(PhysicsObject Maali, PhysicsObject Pelaaja) 389 { 390 if (keratytPallot == 11) 391 { 392 MessageDisplay.Add("LOISTAVAA"); 393 kenttaNro++; 394 SeuraavaKentta(); 395 } 396 397 else if (keratytPallot < 11) 398 { 399 MessageDisplay.Add("Et ole viela valmis!!!"); 400 } 401 } 402 403 void TormaaAmmukseen(PhysicsObject PelaajanAlus, PhysicsObject Ammus) 404 { 405 MessageDisplay.Add("Ai varo vähän!!!"); 406 elamaLaskuri.Value -= 1; 407 Ammus.Destroy(); 408 } 409 410 void TormaaPAmmukseen(PhysicsObject Hyokkaaja, PhysicsObject PAmmus) 411 { 412 MessageDisplay.Add("Ai varo vähän!!!"); 413 TuhoLaskuri.Value += 1; 414 Hyokkaaja.Destroy(); 415 } 416 417 void TormaaAsteroidiin(PhysicsObject PelaajanAlus, PhysicsObject Asteroidi) 418 { 419 Pelaaja.Destroy(); 420 SeuraavaKentta(); 421 } 422 599 else if (keratytPallot < 11) 600 { 601 MessageDisplay.Add("Et ole viela valmis!!!"); 602 } 603 604 } 605 606 void TormaaMaaliin2(PhysicsObject Maali, PhysicsObject Pelaaja2) 607 { 608 MessageDisplay.Add("LOISTAVAA"); 609 kenttaNro++; 610 SeuraavaKentta(); 611 } 612 613 void TormaaAsteroidiin(PhysicsObject PelaajanAlus, PhysicsObject Asteroidi) 614 { 615 PelaajanAlus.IgnoresExplosions = true; 616 617 Explosion rajahdys = new Explosion(50); 618 rajahdys.Position = PelaajanAlus.Position; 619 rajahdys.Speed = 1000.0; 620 rajahdys.Force = 10; 621 Add(rajahdys); 622 Timer tuho = new Timer(); 623 tuho.Interval = 5.0; 624 tuho.Start(); 625 PelaajanAlus.Destroy(); 626 } 627 423 628 } -
2013/23/LauriH/Peli_1/Peli_1/Peli_1Content/Peli_1Content.contentproj
r3986 r4016 125 125 </Compile> 126 126 </ItemGroup> 127 <ItemGroup> 128 <Compile Include="Ammus.png"> 129 <Name>Ammus</Name> 130 <Importer>TextureImporter</Importer> 131 <Processor>TextureProcessor</Processor> 132 </Compile> 133 <Compile Include="Rajahdys.png"> 134 <Name>Rajahdys</Name> 135 <Importer>TextureImporter</Importer> 136 <Processor>TextureProcessor</Processor> 137 </Compile> 138 </ItemGroup> 139 <ItemGroup> 140 <Compile Include="Avaruus.jpg"> 141 <Name>Avaruus</Name> 142 <Importer>TextureImporter</Importer> 143 <Processor>TextureProcessor</Processor> 144 </Compile> 145 </ItemGroup> 146 <ItemGroup> 147 <Compile Include="Metsa.png"> 148 <Name>Metsa</Name> 149 <Importer>TextureImporter</Importer> 150 <Processor>TextureProcessor</Processor> 151 </Compile> 152 </ItemGroup> 153 <ItemGroup> 154 <Compile Include="Kaupunki.png"> 155 <Name>Kaupunki</Name> 156 <Importer>TextureImporter</Importer> 157 <Processor>TextureProcessor</Processor> 158 </Compile> 159 </ItemGroup> 160 <ItemGroup> 161 <Compile Include="Vali1.png"> 162 <Name>Vali1</Name> 163 <Importer>TextureImporter</Importer> 164 <Processor>TextureProcessor</Processor> 165 </Compile> 166 <Compile Include="Vali2.png"> 167 <Name>Vali2</Name> 168 <Importer>TextureImporter</Importer> 169 <Processor>TextureProcessor</Processor> 170 </Compile> 171 <Compile Include="Vali3.png"> 172 <Name>Vali3</Name> 173 <Importer>TextureImporter</Importer> 174 <Processor>TextureProcessor</Processor> 175 </Compile> 176 </ItemGroup> 177 <ItemGroup> 178 <Compile Include="Alku1.png"> 179 <Name>Alku1</Name> 180 <Importer>TextureImporter</Importer> 181 <Processor>TextureProcessor</Processor> 182 </Compile> 183 <Compile Include="Alku2.png"> 184 <Name>Alku2</Name> 185 <Importer>TextureImporter</Importer> 186 <Processor>TextureProcessor</Processor> 187 </Compile> 188 <Compile Include="Alku3.png"> 189 <Name>Alku3</Name> 190 <Importer>TextureImporter</Importer> 191 <Processor>TextureProcessor</Processor> 192 </Compile> 193 <Compile Include="Alku4.png"> 194 <Name>Alku4</Name> 195 <Importer>TextureImporter</Importer> 196 <Processor>TextureProcessor</Processor> 197 </Compile> 198 <Compile Include="Alku5.png"> 199 <Name>Alku5</Name> 200 <Importer>TextureImporter</Importer> 201 <Processor>TextureProcessor</Processor> 202 </Compile> 203 <Compile Include="Alku6.png"> 204 <Name>Alku6</Name> 205 <Importer>TextureImporter</Importer> 206 <Processor>TextureProcessor</Processor> 207 </Compile> 208 </ItemGroup> 209 <ItemGroup> 210 <Compile Include="Restart.png"> 211 <Name>Restart</Name> 212 <Importer>TextureImporter</Importer> 213 <Processor>TextureProcessor</Processor> 214 </Compile> 215 </ItemGroup> 216 <ItemGroup> 217 <Compile Include="Loppu.png"> 218 <Name>Loppu</Name> 219 <Importer>TextureImporter</Importer> 220 <Processor>TextureProcessor</Processor> 221 </Compile> 222 </ItemGroup> 223 <ItemGroup> 224 <Compile Include="2Vali1.png"> 225 <Name>2Vali1</Name> 226 <Importer>TextureImporter</Importer> 227 <Processor>TextureProcessor</Processor> 228 </Compile> 229 <Compile Include="2Vali2.png"> 230 <Name>2Vali2</Name> 231 <Importer>TextureImporter</Importer> 232 <Processor>TextureProcessor</Processor> 233 </Compile> 234 <Compile Include="2Vali3.png"> 235 <Name>2Vali3</Name> 236 <Importer>TextureImporter</Importer> 237 <Processor>TextureProcessor</Processor> 238 </Compile> 239 </ItemGroup> 127 240 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 128 241 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
2013/23/LauriH/Peli_1/Peli_1/Peli_1Content/Taso_2.txt
r3986 r4016 1 2 3 4 5 6 7 1 8 2 9 3 10 O ? O ? O 4 11 ####### ############################################################## 5 12 ? 6 13 ################### 7 14 8 9 10 11 15 ? 12 16 ############# … … 16 20 17 21 ? 18 19 20 22 ################# 21 23 22 24 23 25 ######### 24 26 25 O ?27 ? O ? 26 28 ########### ###################################### 27 29 M … … 29 31 M 30 32 O ### M 31 #################M33 ################# M 32 34 O O M 33 35 ############## ################################# -
2013/23/LauriH/Peli_1/Peli_1/Peli_1Content/Taso_3.txt
r3986 r4016 24 24 25 25 26 o oo26 o o 27 27 ######################################### 28 28 29 o o o oo o o o29 o o o o o o 30 30 ############################################ ################################# 31 31 M 32 32 M 33 o o o o o oo o M33 o o o o o M 34 34 ################################################ ########################## M 35 35 M 36 36 M 37 p o o o o o o o o o o o o o o o o o o o o o o o o o o o o o oM37 p o o o o o o o o o o o o o o o o o o o M 38 38 ################################################################################################################################################################################################################################################################################################################## -
2013/23/LauriH/Peli_1/Peli_1/Peli_1Content/Taso_4.txt
r3986 r4016 23 23 M M 24 24 M 25 o o oM25 o M 26 26 ######################## 27 28 o o o o o 29 ###################################### #################################### 30 31 o o 27 ########### 28 o o o o 29 ###################################### #### #################################### 30 o o 32 31 ################################### 33 32 … … 36 35 37 36 38 o o o o o o o o o o o o o o o o o oo o o o o o37 p o o o o o o o o o o o o o o o o o o 39 38 ############################################################################################################################################################################################################################################# -
2013/23/LauriH/Peli_1/Peli_1/Peli_1Content/Taso_5.txt
r3986 r4016 1 2 3 4 5 6 7 8 9 10 11 12 13 14 H H H H H15 16 17 18 19 20 H H H H21 22 23 24 25 26 27 28 A H H H H H 29 30 31 32 H H H H33 34 35 36 H H H H37 38 39 40 41 H H H H H1 2 3 4 5 6 7 8 9 10 11 12 13 14 H H H H H M 15 M 16 M 17 H H m M 18 m m M 19 M 20 H H H H M 21 M 22 M 23 m H M 24 H M 25 H m H M 26 M 27 M 28 A H H H H H H M 29 M 30 M 31 m M 32 H H H m H H M 33 M 34 M 35 m M 36 H H H H m M 37 H H H M 38 39 H 40 41 H H H m H H
Note: See TracChangeset
for help on using the changeset viewer.