- Timestamp:
- 2012-07-26 14:58:16 (10 years ago)
- Location:
- 2012/30/JesseN/Oma peli/OmaPeli/OmaPeli
- Files:
-
- 19 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/30/JesseN/Oma peli/OmaPeli/OmaPeli/OmaPeli/OmaPeli.cs
r3751 r3769 9 9 public class OmaPeli : PhysicsGame 10 10 { 11 HahmoClasshahmo;11 PlatformCharacter hahmo; 12 12 Image hahmostand = LoadImage("CharStand32"); 13 13 Image[] hahmojuoksu = LoadImages("CharRun1", "CharRun2", "CharRun3"); … … 25 25 Image panos2 = LoadImage("Bullet2"); 26 26 Image kiviblock = LoadImage("Stone"); 27 28 29 30 27 Image kattokivi1block = LoadImage("StoneCeiling"); 28 Image kattokivi2block = LoadImage("StoneCeiling2"); 29 Image kattokivi3block = LoadImage("StoneCeiling3"); 30 Image takakiviblock = LoadImage("StoneBackground"); 31 Image luolakiviblock1 = LoadImage("StoneCeilingBack1"); 32 Image luolakiviblock2 = LoadImage("StoneCeilingBack2"); 33 Image luolakiviblock3 = LoadImage("StoneCeilingBack3"); 34 Image borderblock = LoadImage("BorderWall"); 35 Image ammolaatikko = LoadImage("AmmoBox"); 36 Image taustakuva = LoadImage("CloudBackground"); 37 Image hpsalkku = LoadImage("Briefcase"); 38 Animation hahmoosuma; 39 ExplosionSystem rajahdys; 40 41 DoubleMeter elamaLaskuri; 42 IntMeter ammuslaskuri; 31 43 32 44 public override void Begin() … … 46 58 47 59 48 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 60 61 62 63 PhoneBackButton.Listen(ConfirmExit, "Lopeta Peli"); 49 64 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 50 65 } … … 65 80 } 66 81 82 void LuoTausta() 83 { 84 GameObject tausta = new GameObject(Level.Width, Level.Height); 85 tausta.Image = taustakuva; 86 Add(tausta, -3); 87 Layers[-3].RelativeTransition = new Vector(0.5, 0.5); 88 } 89 67 90 void Luokentta() 68 91 { 69 70 71 92 93 ammuslaskuri = new IntMeter(30); 94 95 96 LuoElamaLaskuri(); 97 Luoammustenmaara(); 72 98 73 99 ColorTileMap ruudut = ColorTileMap.FromLevelAsset("Level1"); … … 82 108 ruudut.SetTileMethod(Color.Rose, LuoKivi); 83 109 110 ruudut.SetTileMethod(Color.Gray, LuoKattoKivi1); 111 ruudut.SetTileMethod(Color.BrownGreen, LuoKattoKivi2); 112 ruudut.SetTileMethod(Color.Olive, LuoKattoKivi3); 113 ruudut.SetTileMethod(Color.DarkRed, LuoTakakivi); 114 ruudut.SetTileMethod(Color.ForestGreen, Luoluolakivi1); 115 ruudut.SetTileMethod(Color.DarkGray, Luoluolakivi2); 116 ruudut.SetTileMethod(Color.DarkJungleGreen, Luoluolakivi3); 117 ruudut.SetTileMethod(Color.YellowGreen, LuoBorderwall); 118 ruudut.SetTileMethod(Color.SpringGreen, LuoAmmuslaatikko); 119 Camera.Zoom(1.2); 84 120 85 121 ruudut.Execute(45, 45); 86 87 //Level.AmbientLight = 1.0; 88 89 //Light valo = new Light(); 90 //valo.Intensity = 0.8; 91 //valo.Distance = 150; 92 //valo.Position = hahmo.Position; 93 //Add(valo); 94 //int pMaxMaara = 200; 95 //ExplosionSystem rajahdys = new ExplosionSystem(LoadImage(""), pMaxMaara); 96 //Add(rajahdys); 97 } 122 int pMaxMaara = 200; 123 rajahdys = new ExplosionSystem(LoadImage("Explosion"), pMaxMaara); 124 rajahdys.MaxVelocity = 1; 125 Add(rajahdys); 126 LuoTausta(); 127 } 128 129 void LuoAmmuslaatikko(Vector paikka, double leveys, double korkeus) 130 { 131 PhysicsObject ammobox = new PhysicsObject(32, 32); 132 ammobox.Position = paikka; 133 ammobox.Image = ammolaatikko; 134 ammobox.CollisionIgnoreGroup = 0; 135 ammobox.Tag = "Ammo"; 136 Add(ammobox, -1); 137 } 138 139 void LuoHPsalkku(Vector paikka, double leveys, double korkeus) 140 { 141 PhysicsObject hpbox = new PhysicsObject(32, 32); 142 hpbox.Position = paikka; 143 hpbox.Image = hpsalkku; 144 hpbox.CollisionIgnoreGroup = 0; 145 hpbox.Tag = "HP"; 146 Add(hpbox, -1); 147 } 148 149 150 void Luoluolakivi1(Vector paikka, double leveys, double korkeus) 151 { 152 PhysicsObject luolakivi1 = PhysicsObject.CreateStaticObject(leveys, korkeus); 153 luolakivi1.Position = paikka; 154 luolakivi1.Image = luolakiviblock1; 155 luolakivi1.CollisionIgnoreGroup = 1; 156 luolakivi1.IgnoresCollisionResponse = true; 157 Add(luolakivi1, -1); 158 } 159 160 void LuoBorderwall(Vector paikka, double leveys, double korkeus) 161 { 162 PhysicsObject borderseina = PhysicsObject.CreateStaticObject(leveys, korkeus); 163 borderseina.Position = paikka; 164 borderseina.Image = borderblock; 165 borderseina.CollisionIgnoreGroup = 1; 166 Add(borderseina, -1); 167 } 168 169 170 171 172 void Luoluolakivi2(Vector paikka, double leveys, double korkeus) 173 { 174 PhysicsObject luolakivi2 = PhysicsObject.CreateStaticObject(leveys, korkeus); 175 luolakivi2.Position = paikka; 176 luolakivi2.Image = luolakiviblock2; 177 luolakivi2.CollisionIgnoreGroup = 1; 178 luolakivi2.IgnoresCollisionResponse = true; 179 Add(luolakivi2, -1); 180 } 181 182 void Luoluolakivi3(Vector paikka, double leveys, double korkeus) 183 { 184 PhysicsObject luolakivi3 = PhysicsObject.CreateStaticObject(leveys, korkeus); 185 luolakivi3.Position = paikka; 186 luolakivi3.Image = luolakiviblock3; 187 luolakivi3.CollisionIgnoreGroup = 1; 188 luolakivi3.IgnoresCollisionResponse = true; 189 Add(luolakivi3, -1); 190 } 191 192 193 void LuoKattoKivi1(Vector paikka, double leveys, double korkeus) 194 { 195 PhysicsObject kattokivi1 = PhysicsObject.CreateStaticObject(leveys, korkeus); 196 kattokivi1.Position = paikka; 197 kattokivi1.Image = kattokivi1block; 198 kattokivi1.CollisionIgnoreGroup = 1; 199 kattokivi1.IgnoresCollisionResponse = true; 200 Add(kattokivi1, -1); 201 } 202 203 void LuoKattoKivi2(Vector paikka, double leveys, double korkeus) 204 { 205 PhysicsObject kattokivi2 = PhysicsObject.CreateStaticObject(leveys, korkeus); 206 kattokivi2.Position = paikka; 207 kattokivi2.Image = kattokivi2block; 208 kattokivi2.CollisionIgnoreGroup = 1; 209 kattokivi2.IgnoresCollisionResponse = true; 210 Add(kattokivi2, -1); 211 } 212 213 void LuoKattoKivi3(Vector paikka, double leveys, double korkeus) 214 { 215 PhysicsObject kattokivi3 = PhysicsObject.CreateStaticObject(leveys, korkeus); 216 kattokivi3.Position = paikka; 217 kattokivi3.Image = kattokivi3block; 218 kattokivi3.CollisionIgnoreGroup = 1; 219 kattokivi3.IgnoresCollisionResponse = true; 220 Add(kattokivi3, -1); 221 } 222 223 98 224 99 225 void LuoKivi(Vector paikka, double leveys, double korkeus) 100 226 { 227 101 228 PhysicsObject kivi = PhysicsObject.CreateStaticObject(leveys, korkeus); 102 229 kivi.Position = paikka; … … 109 236 void LuoPelaaja(Vector paikka, double leveys, double korkeus) 110 237 { 111 hahmo = new HahmoClass(48, 48);238 hahmo = new PlatformCharacter(48, 48); 112 239 hahmo.AnimWalk = new Animation(hahmojuoksu); 113 240 hahmo.AnimWalk.FPS = 10; … … 116 243 hahmo.AnimFall = new Animation(hahmofall); 117 244 hahmo.Weapon = new LaserGun(30, 30); 118 hahmo.Weapon.Ammo.Value = 10000;245 hahmo.Weapon.Ammo.Value = 30; 119 246 hahmo.Weapon.Image = null; 120 247 hahmo.Weapon.Color = Color.Transparent; 121 248 hahmo.Weapon.Power.DefaultValue = 1000; 122 249 hahmo.Weapon.CanHitOwner = false; 250 AddCollisionHandler<PlatformCharacter, PhysicsObject>(hahmo, "Ammo", Ammuksia); 251 AddCollisionHandler<PlatformCharacter, PhysicsObject>(hahmo, "HP", Hpta); 252 253 Image[] hahmodmg = LoadImages("CharHit", "CharHit2", "CharHit3"); 254 hahmoosuma = new Animation(hahmodmg); 123 255 Add(hahmo); 124 256 hahmo.Position = paikka; … … 126 258 Ohjaus(); 127 259 Camera.Follow(hahmo); 128 260 } 261 262 void Hpta(PlatformCharacter hahmo, PhysicsObject hpbox) 263 { 264 hpbox.Destroy(); 265 266 elamaLaskuri.Value += 2; 267 } 268 269 void Ammuksia(PlatformCharacter hahmo, PhysicsObject ammobox) 270 { 271 ammobox.Destroy(); 272 hahmo.Weapon.Ammo.Value += 20; 273 ammuslaskuri.Value += 20; 129 274 } 130 275 … … 152 297 void LuoPuu(Vector paikka, double leveys, double korkeus) 153 298 { 154 PhysicsObject puu = PhysicsObject.CreateStaticObject(leveys, korkeus);299 GameObject puu = new GameObject(leveys, korkeus); 155 300 puu.Position = paikka; 156 301 puu.Image = puublock; 157 puu.CollisionIgnoreGroup = 1;158 puu.IgnoresCollisionResponse = true;159 302 Add(puu, -1); 160 303 } … … 162 305 void LuoLehdet(Vector paikka, double leveys, double korkeus) 163 306 { 164 PhysicsObject lehdet = PhysicsObject.CreateStaticObject(leveys, korkeus);307 GameObject lehdet = new GameObject(leveys, korkeus); 165 308 lehdet.Position = paikka; 166 309 lehdet.Image = lehdetblock; 167 lehdet.CollisionIgnoreGroup = 1;168 lehdet.IgnoresCollisionResponse = true;169 310 Add(lehdet, -1); 170 311 } … … 172 313 void LuoVesi(Vector paikka, double leveys, double korkeus) 173 314 { 174 PhysicsObject vesi = PhysicsObject.CreateStaticObject(leveys, korkeus);315 GameObject vesi = new GameObject(leveys, korkeus); 175 316 vesi.Position = paikka; 176 317 vesi.Image = vesiblock; 177 vesi.CollisionIgnoreGroup = 1;178 vesi.IgnoresCollisionResponse = true;179 318 Add(vesi, -1); 319 } 320 321 void LuoTakakivi(Vector paikka, double leveys, double korkeus) 322 { 323 GameObject takakivi = new GameObject(leveys, korkeus); 324 takakivi.Position = paikka; 325 takakivi.Image = takakiviblock; 326 Add(takakivi, -1); 180 327 } 181 328 … … 188 335 seuraajanAivot1.Speed = 100; 189 336 lentava.IgnoresGravity = true; 190 //seuraajanAivot1.DistanceFar = 500;191 //seuraajanAivot1.DistanceClose = 100;192 //seuraajanAivot1.StopWhenTargetClose = true;337 seuraajanAivot1.DistanceFar = 500; 338 seuraajanAivot1.DistanceClose = 100; 339 seuraajanAivot1.StopWhenTargetClose = true; 193 340 //seuraajanAivot1.TargetClose += vihulahella; 194 341 lentava.Animation = new Animation(flyer); … … 203 350 lentavagun.Color = Color.Transparent; 204 351 lentava.Tag = "vihollinen"; 205 352 lentava.Destroyed += delegate { vihollinen1tuhottu(lentava); }; 353 lentava.Destroyed += delegate { if (RandomGen.NextBool()) LuoHPsalkku(lentava.Position, leveys, korkeus); }; 354 206 355 lentava.Add(lentavagun); 207 356 208 357 Timer ajastin = new Timer(); 209 ajastin.Interval = 1.0;358 ajastin.Interval = 2.0; 210 359 ajastin.Timeout += delegate { VihollinenAmpuu(lentava, lentavagun, ajastin); }; 211 360 ajastin.Start(); 212 361 Add(lentava); 213 362 } 363 364 void vihollinen1tuhottu(Vihuclass paikka) 365 { 366 int pMaara = 50; 367 rajahdys.AddEffect(paikka.Position, pMaara); 368 } 214 369 215 370 void AmmusViholliseen(PhysicsObject ammus, Vihuclass lentava) … … 219 374 220 375 } 376 377 void AmmusPelaajaan(PhysicsObject ammus2, PlatformCharacter hahmo) 378 { 379 elamaLaskuri.Value -= 1; 380 hahmo.PlayAnimation(hahmoosuma); 381 //hahmo.PlayAnimation(...); 382 } 383 221 384 222 385 void VihollinenAmpuu(PhysicsObject lentava, LaserGun lentavagun, Timer ajastin) … … 240 403 ammus2.Image = panos2; 241 404 AddCollisionHandler(ammus2, CollisionHandler.DestroyObject); 405 AddCollisionHandler(ammus2, hahmo, AmmusPelaajaan); 242 406 243 407 … … 247 411 } 248 412 249 250 251 void vihulahella(Vector paikka, double leveys, double korkeus) 252 { 253 254 } 255 256 413 414 415 416 257 417 258 418 void Ohjaus() … … 280 440 //hahmo.Animation = new Animation(tahtaa); 281 441 //hahmo.Animation.Start(1); 442 ammuslaskuri.Value -= 1; 282 443 283 444 if (ammus != null) … … 288 449 AddCollisionHandler(ammus, CollisionHandler.DestroyObject); 289 450 AddCollisionHandler<PhysicsObject, Vihuclass>(ammus, "vihollinen", AmmusViholliseen); 451 290 452 } 291 453 } 292 454 293 294 455 void LuoElamaLaskuri() 456 { 457 elamaLaskuri = new DoubleMeter(6); 458 elamaLaskuri.MaxValue = 6; 459 elamaLaskuri.LowerLimit += ElamaLoppui; 460 461 ProgressBar elamaPalkki = new ProgressBar(140, 40); 462 elamaPalkki.X = Screen.Left + 88; 463 elamaPalkki.Y = Screen.Top - 100; 464 elamaPalkki.BindTo(elamaLaskuri); 465 elamaPalkki.Image = LoadImage("HPbarEmpty"); 466 elamaPalkki.BarImage = LoadImage("HPbarFull"); 467 Add(elamaPalkki); 468 } 469 470 void ElamaLoppui() 471 { 472 MessageDisplay.Add("You were destroyed. Game Over."); 473 int pMaara = 50; 474 rajahdys.AddEffect(hahmo.Position, pMaara); 475 } 476 477 478 void Luoammustenmaara() 479 { 480 Label ammustenmaara = new Label(); 481 ammustenmaara.X = Screen.Left + 100; 482 ammustenmaara.Y = Screen.Top - 70; 483 ammustenmaara.TextColor = Color.White; 484 ammustenmaara.Color = Color.Black; 485 ammustenmaara.BindTo(ammuslaskuri); 486 ammustenmaara.Title = "Ammunition"; 487 Add(ammustenmaara); 488 } 295 489 } -
2012/30/JesseN/Oma peli/OmaPeli/OmaPeli/OmaPeli/OmaPeli.csproj
r3751 r3769 111 111 </ItemGroup> 112 112 <ItemGroup> 113 <Compile Include="HahmoClass.cs" />114 113 <Compile Include="Ohjelma.cs" /> 115 114 <Compile Include="OmaPeli.cs" /> -
2012/30/JesseN/Oma peli/OmaPeli/OmaPeli/OmaPeliContent/OmaPeliContent.contentproj
r3751 r3769 74 74 <ItemGroup> 75 75 <Folder Include="NewFolder1\" /> 76 <Folder Include="NewFolder2\" /> 76 77 </ItemGroup> 77 78 <ItemGroup> … … 190 191 <Compile Include="Stone.png"> 191 192 <Name>Stone</Name> 193 <Importer>TextureImporter</Importer> 194 <Processor>TextureProcessor</Processor> 195 </Compile> 196 </ItemGroup> 197 <ItemGroup> 198 <Compile Include="Explosion.png"> 199 <Name>Explosion</Name> 200 <Importer>TextureImporter</Importer> 201 <Processor>TextureProcessor</Processor> 202 </Compile> 203 </ItemGroup> 204 <ItemGroup> 205 <Compile Include="HPbarFull.png"> 206 <Name>HPbarFull</Name> 207 <Importer>TextureImporter</Importer> 208 <Processor>TextureProcessor</Processor> 209 </Compile> 210 </ItemGroup> 211 <ItemGroup> 212 <Compile Include="HPbarEmpty.png"> 213 <Name>HPbarEmpty</Name> 214 <Importer>TextureImporter</Importer> 215 <Processor>TextureProcessor</Processor> 216 </Compile> 217 </ItemGroup> 218 <ItemGroup> 219 <Compile Include="StoneCeiling2.png"> 220 <Name>StoneCeiling2</Name> 221 <Importer>TextureImporter</Importer> 222 <Processor>TextureProcessor</Processor> 223 </Compile> 224 </ItemGroup> 225 <ItemGroup> 226 <Compile Include="StoneCeiling.png"> 227 <Name>StoneCeiling</Name> 228 <Importer>TextureImporter</Importer> 229 <Processor>TextureProcessor</Processor> 230 </Compile> 231 </ItemGroup> 232 <ItemGroup> 233 <Compile Include="StoneCeiling3.png"> 234 <Name>StoneCeiling3</Name> 235 <Importer>TextureImporter</Importer> 236 <Processor>TextureProcessor</Processor> 237 </Compile> 238 </ItemGroup> 239 <ItemGroup> 240 <Compile Include="Stonebackground.png"> 241 <Name>Stonebackground</Name> 242 <Importer>TextureImporter</Importer> 243 <Processor>TextureProcessor</Processor> 244 </Compile> 245 </ItemGroup> 246 <ItemGroup> 247 <Compile Include="StoneCeilingBack3.png"> 248 <Name>StoneCeilingBack3</Name> 249 <Importer>TextureImporter</Importer> 250 <Processor>TextureProcessor</Processor> 251 </Compile> 252 </ItemGroup> 253 <ItemGroup> 254 <Compile Include="StoneCeilingBack1.png"> 255 <Name>StoneCeilingBack1</Name> 256 <Importer>TextureImporter</Importer> 257 <Processor>TextureProcessor</Processor> 258 </Compile> 259 </ItemGroup> 260 <ItemGroup> 261 <Compile Include="StoneCeilingBack2.png"> 262 <Name>StoneCeilingBack2</Name> 263 <Importer>TextureImporter</Importer> 264 <Processor>TextureProcessor</Processor> 265 </Compile> 266 </ItemGroup> 267 <ItemGroup> 268 <Compile Include="BorderWall.png"> 269 <Name>BorderWall</Name> 270 <Importer>TextureImporter</Importer> 271 <Processor>TextureProcessor</Processor> 272 </Compile> 273 </ItemGroup> 274 <ItemGroup> 275 <Compile Include="AmmoBox.png"> 276 <Name>AmmoBox</Name> 277 <Importer>TextureImporter</Importer> 278 <Processor>TextureProcessor</Processor> 279 </Compile> 280 </ItemGroup> 281 <ItemGroup> 282 <Compile Include="CloudBackground.png"> 283 <Name>CloudBackground</Name> 284 <Importer>TextureImporter</Importer> 285 <Processor>TextureProcessor</Processor> 286 </Compile> 287 </ItemGroup> 288 <ItemGroup> 289 <Compile Include="CharHit.png"> 290 <Name>CharHit</Name> 291 <Importer>TextureImporter</Importer> 292 <Processor>TextureProcessor</Processor> 293 </Compile> 294 </ItemGroup> 295 <ItemGroup> 296 <Compile Include="CharHit2.png"> 297 <Name>CharHit2</Name> 298 <Importer>TextureImporter</Importer> 299 <Processor>TextureProcessor</Processor> 300 </Compile> 301 </ItemGroup> 302 <ItemGroup> 303 <Compile Include="CharHit3.png"> 304 <Name>CharHit3</Name> 305 <Importer>TextureImporter</Importer> 306 <Processor>TextureProcessor</Processor> 307 </Compile> 308 </ItemGroup> 309 <ItemGroup> 310 <Compile Include="Briefcase.png"> 311 <Name>Briefcase</Name> 192 312 <Importer>TextureImporter</Importer> 193 313 <Processor>TextureProcessor</Processor>
Note: See TracChangeset
for help on using the changeset viewer.