- Timestamp:
- 2017-07-06 14:50:42 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2017/27/EeliN/Selviytyja/Selviytyja/Selviytyja/Selviytyja.cs
r8935 r8965 11 11 int Speed = 100; 12 12 public bool menuopened = false; 13 //public bool hakkaamassa = false; 13 14 public Image idleRight = LoadImage("PlayerIdleRight_0"); 14 15 public Image woodItem = LoadImage("WoodItem_0"); … … 19 20 public Image stoneBottom = LoadImage("StoneBottom"); 20 21 public Image stoneimg = LoadImage("Stone_0"); 22 public Image appleimg = LoadImage("Apple_0"); 23 24 public Image stoneitemimg = LoadImage("StoneItem_0"); 21 25 private Image[] playerWalkR = LoadImages("PlayerWalkRight_0", "PlayerWalkRight_1"); 26 private Image[] playerHitR = LoadImages("PlayerHitRight_0", "PlayerHitRight_1"); 22 27 Image idleLeft; 23 28 public bool pausegame = false; … … 28 33 GameObject darkfade; 29 34 GameObject nappi; 30 Inventory inventory = new Inventory(); 31 32 PhysicsObject wood; 35 GameObject apple; 36 public int slotitemsize = 30; 37 Tavaraluettelo tavaraluettelo; 38 Player ukko; 39 40 PhysicsObject wood; 41 PhysicsObject stone; 33 42 Timer fader; 34 43 private Image[] playerWalkL; … … 40 49 public override void Begin() 41 50 { 51 tavaraluettelo = new Tavaraluettelo(657, 150, inventoryimg); 52 Add(tavaraluettelo, 2); 53 42 54 // TODO: Kirjoita ohjelmakoodisi tähän 43 55 Level.Width = Window.Width; 44 56 Level.Height = Window.Height; 45 57 SmoothTextures = false; 46 Player ukko = new Player(22, 42); 58 ukko = new Player(24, 52); 59 47 60 //ukko.MakeStatic(); 48 61 ukko.Image = idleRight; … … 57 70 //playerWalkL[0] = Image.Mirror(playerWalkR[0]).Clone(); 58 71 ukko.PlayerWalkR = new Animation(playerWalkR); 72 ukko.PlayerHitR = new Animation(playerHitR); 73 ukko.PlayerHitL = new Animation(Animation.Mirror(ukko.PlayerHitR)); 59 74 //ukko.PlayerWalkL = Animation.Mirror(ukko.PlayerWalkR.cl); 60 75 ukko.Restitution = 0; … … 69 84 LuoPauseMenu(); 70 85 fader = new Timer(); 71 Add(inventory); 72 86 //inventory.Image = LoadImage("ToolBar_0"); 87 //inventory.Y = Screen.Bottom + 100; 88 //Add(inventory, 3); 89 //inventory.AddItem(wood, woodItem, 1); 90 //inventory.AddItem(wood, stoneimg, 2); 91 tavaraluettelo.Y = -400; 92 93 94 //ITEMIT 73 95 wood = new PhysicsObject(40, 40); 96 stone = new PhysicsObject(40, 40); 97 apple = new PhysicsObject(40, 40); 98 stone.Image = stoneitemimg; 99 apple.Image = appleimg; 100 //-------------------------------// 101 74 102 75 103 Keyboard.Listen(Key.D, ButtonState.Down, MoveSideways, null, ukko, new Vector(Speed, 0)); … … 85 113 Keyboard.Listen(Key.Escape, ButtonState.Pressed, AvaaPauseMenu, "Pause the game"); 86 114 87 Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Hakkaaminen, null, ukko); 88 115 Mouse.Listen(MouseButton.Left, ButtonState.Pressed, HakkaaminenAlkaa, null, ukko); 116 Mouse.Listen(MouseButton.Left, ButtonState.Released, HakkaaminenLoppuu, null, ukko); 117 89 118 90 119 } … … 92 121 { 93 122 //pelaaja.Velocity = new Vector(direction.X, pelaaja.Velocity.Y); 123 124 PlayerAnimation(pelaaja, direction); 125 126 pelaaja.Velocity += direction; 127 128 } 129 130 void MoveVertically(Player pelaaja, Vector direction) 131 { 132 //pelaaja.Velocity = new Vector(pelaaja.Velocity.X, direction.Y); 133 pelaaja.Velocity += direction; 134 135 if (pelaaja.PelaajaHakkaamassa) return; 136 94 137 PlayerAnimation(pelaaja, direction); 95 pelaaja.Velocity += direction; 96 } 97 98 void MoveVertically(Player pelaaja, Vector direction) 99 { 100 //pelaaja.Velocity = new Vector(pelaaja.Velocity.X, direction.Y); 101 PlayerAnimation(pelaaja, direction); 102 pelaaja.Velocity += direction; 138 103 139 } 104 140 … … 113 149 foreach (GameObject nappi in menubuttonit) nappi.Color = Color.Transparent; 114 150 FadeRuutu(false); 115 151 116 152 Keyboard.EnableAll(); 117 153 118 119 120 121 } else 154 155 156 157 } 158 else 122 159 { 123 160 menu.IsVisible = true; … … 178 215 public void LuoPauseMenu() 179 216 { 180 217 181 218 menu = new GameObject(450, 500); 182 219 menu.Image = menuimg; … … 203 240 resumebutton.Color = Color.Transparent; 204 241 quitbutton.Color = Color.Transparent; 205 242 206 243 207 244 } … … 234 271 public void PlayerAnimation(Player player, Vector direction) 235 272 { 236 // MessageDisplay.Clear();237 // MessageDisplay.Add("PlayerRight = " + player.PlayerRight + ", direction = " + direction);273 // MessageDisplay.Clear(); 274 // MessageDisplay.Add("PlayerRight = " + player.PlayerRight + ", direction = " + direction); 238 275 if (direction.X != 0) 239 276 { … … 255 292 } 256 293 257 void Hakkaaminen (Player ukko)294 void HakkaaminenAlkaa(Player ukko) 258 295 { 259 296 if (pausegame == true) … … 272 309 if (pausegame == false) 273 310 { 274 275 276 List<GameObject> resurssit; 277 278 if (ukko.PlayerRight) 279 { 280 resurssit = GetObjectsBetween((ukko.Position + new Vector(ukko.Width * 0.5, ukko.Height * 0.1)), (ukko.Position + new Vector(ukko.Width * 1, ukko.Height + 10))); 281 } 282 else 283 { 284 resurssit = GetObjectsBetween((ukko.Position - new Vector(ukko.Width * 0.5, ukko.Height * 0.1)), (ukko.Position - new Vector(ukko.Width * 1, -ukko.Height - 10))); 285 } 286 287 if (resurssit.Count > 0) 288 { 289 foreach (GameObject resurssi in resurssit) 290 { 291 if (resurssi == null) return; 292 if (resurssi.Tag.Equals("")) return; 293 if (resurssi.Tag.Equals("Puu")) 311 ukko.PelaajaHakkaamassa= true; 312 //PlayerAnimationHit(ukko); 313 ukko.Width = ukko.HakkaamisLeveys; 314 315 List<GameObject> resurssit; 316 317 if (ukko.PlayerRight) 318 { 319 resurssit = GetObjectsBetween((ukko.Position + new Vector(ukko.Width * 0.5, ukko.Height * 0.1)), (ukko.Position + new Vector(ukko.Width * 1, ukko.Height + 10))); 320 ukko.Animation = ukko.PlayerHitR; 321 322 } 323 else 324 { 325 resurssit = GetObjectsBetween((ukko.Position - new Vector(ukko.Width * 0.5, ukko.Height * 0.1)), (ukko.Position - new Vector(ukko.Width * 1, -ukko.Height - 10))); 326 ukko.Animation = ukko.PlayerHitL; 327 328 } 329 ukko.Animation.Start(); 330 if (resurssit.Count > 0) 331 { 332 foreach (GameObject resurssi in resurssit) 294 333 { 295 PlaySound("Hit"); 296 inventory.AddItem(wood, woodItem, RandomGen.SelectOne(5,6,7,8,9,10)); 334 335 if (resurssi == null) return; 336 if (resurssi.Tag.Equals("")) return; 337 if (resurssi.Tag.Equals("Puu")) 338 { 339 PlaySound("Hit"); 340 Tree puu = (Tree)resurssi; 341 342 Slot slotti = tavaraluettelo.LisaaResurssi(wood, RandomGen.SelectOne(1, 2, 3)); 343 puu.ElamaLaskuri.Value--; 344 if (slotti != null) slotti.Image = woodItem; 345 346 347 Slot slotti2 = null; 348 const int OMENAMAHDOLLISUUS = 10; 349 if (RandomGen.NextInt(OMENAMAHDOLLISUUS+1) >= OMENAMAHDOLLISUUS) slotti2 = tavaraluettelo.LisaaResurssi(apple, 1); 350 351 if (slotti2 != null) slotti2.Image = apple.Image; 352 353 354 355 //inventory.AddItem(wood, woodItem, RandomGen.SelectOne(5,6,7,8,9,10)); 356 357 } 358 if (resurssi.Tag.Equals("Kivi")) 359 { 360 PlaySound("Hit"); 361 MessageDisplay.Add("kivi!"); 362 363 Slot slotti = tavaraluettelo.LisaaResurssi(stone, RandomGen.SelectOne(1, 2)); 364 365 if (slotti != null) slotti.Image = stoneitemimg; 366 367 368 369 //inventory.AddItem(wood, woodItem, RandomGen.SelectOne(5,6,7,8,9,10)); 370 371 } 372 297 373 } 298 MessageDisplay.Add("Osui olioon: " + resurssi.Tag.ToString()); 299 } 300 301 } 302 303 } 304 } 305 306 void LuoKivi(double x,double y) 374 } 375 376 } 377 } 378 379 public void HakkaaminenLoppuu(Player player) 380 { 381 ukko.PelaajaHakkaamassa = false; 382 ukko.Animation.Stop(); 383 ukko.Animation = null; 384 ukko.Width = ukko.InitialLeveys; 385 ukko.Image = ukko.PlayerImage; 386 } 387 public void PlayerAnimationHit(Player player) 388 { 389 // MessageDisplay.Clear(); 390 // MessageDisplay.Add("PlayerRight = " + player.PlayerRight + ", direction = " + direction); 391 392 return; 393 if (player.Velocity.X != 0) 394 { 395 //player.PlayerAnimation(direction.X); 396 397 } 398 if (player.Velocity.Y != 0) 399 { 400 if (player.PlayerRight) player.Animation = player.PlayerHitR; 401 else player.Animation = Animation.Mirror(player.PlayerHitR); 402 403 } 404 else player.PlayerAnimation(0); 405 406 //if (direction == 0) player.Animation.Stop(); 407 //else 408 // player.Animation.Start(); 409 410 } 411 412 void LuoKivi(double x, double y) 307 413 { 308 414 Stone stone = new Stone(56, 50); … … 316 422 stone.Restitution = 0; 317 423 stone.Y = y; 318 Add(stone, 1);424 Add(stone, 1); 319 425 objektilista.Add(stone); 320 for (int i = 0; i < objektilista.Count -1; i++)321 { 322 if ((stone.Position - objektilista[i].Position).Magnitude < 120 426 for (int i = 0; i < objektilista.Count - 1; i++) 427 { 428 if ((stone.Position - objektilista[i].Position).Magnitude < 120) 323 429 { 324 430 objektilista.Remove(stone); … … 332 438 for (int i = 0; i < 20; i++) 333 439 { 334 335 double x = RandomGen.NextDouble(Level.Left, Level.Right);440 441 double x = RandomGen.NextDouble(Level.Left, Level.Right); 336 442 double y = RandomGen.NextDouble(Level.Bottom, Level.Top); 337 443 LuoKivi(x, y); … … 348 454 puu.X = x; 349 455 puu.Y = y; 350 Add(puu, 1);456 Add(puu, 1); 351 457 objektilista.Add(puu); 352 458 for (int i = 0; i < objektilista.Count - 1; i++) … … 376 482 public Animation PlayerWalkR; 377 483 public Animation PlayerWalkL; 484 public Animation PlayerHitR; 485 public Animation PlayerHitL; 378 486 public Image PlayerImage; 379 487 public Image PlayerImageRight; 380 488 public Image PlayerImageLeft; 489 public double InitialLeveys; 490 public double HakkaamisLeveys; 491 public bool PelaajaHakkaamassa = false; 492 381 493 382 494 public Player(double leveys, double korkeus) 383 : base (leveys, korkeus) 384 { 495 : base(leveys, korkeus) 496 { 497 InitialLeveys = leveys; 498 HakkaamisLeveys = leveys * 12 / 6; 385 499 //idleRight = Selviytyja.Move(); 386 }500 } 387 501 public void PlayerAnimation(double direction) 388 502 { … … 390 504 if (direction == 0 && PlayerImage == PlayerImageLeft) 391 505 { 392 this.Animation = null;506 393 507 if (PlayerRight) 394 508 { … … 396 510 PlayerImage = (PlayerImageRight); 397 511 } 512 if (PelaajaHakkaamassa) return; 513 this.Animation = null; 398 514 this.Image = (PlayerImage); 515 516 return; 517 } 518 else if (direction == 0 && PlayerImage == PlayerImageRight) 519 { 399 520 400 return;401 }402 else if (direction == 0 && PlayerImage == PlayerImageRight)403 {404 this.Animation = null;405 521 if (PlayerRight == false) 406 522 { … … 408 524 PlayerImage = (PlayerImageLeft); 409 525 } 410 this.Image = (PlayerImage); 411 526 if (PelaajaHakkaamassa) return; 527 this.Animation = null; 528 this.Image = (PlayerImage); 529 412 530 return; 413 531 } … … 416 534 { 417 535 PlayerRight = false; 536 if (PelaajaHakkaamassa) return; 418 537 if (this.Animation.IsPlaying == false) 419 538 { … … 425 544 { 426 545 PlayerRight = true; 546 if (PelaajaHakkaamassa) return; 427 547 if (this.Animation.IsPlaying == false) 428 548 { … … 437 557 438 558 439 559 440 560 } 441 561 … … 446 566 { 447 567 GameObject Lehti; 448 449 public Image TopImage 450 { 451 get { return Lehti.Image; } 452 set { Lehti.Image = value;} 453 } 568 private IntMeter elamaLaskuri = new IntMeter(15, 0, 15); 569 public IntMeter ElamaLaskuri { get { return elamaLaskuri; } } 570 571 public Image TopImage 572 { 573 get { return Lehti.Image; } 574 set { Lehti.Image = value; } 575 } 454 576 455 577 456 578 public Tree(double leveys, double korkeus) 457 : base (leveys, korkeus*0.5) 458 { 579 : base(leveys, korkeus * 0.5) 580 { 581 elamaLaskuri.LowerLimit += delegate { this.Destroy(); }; 582 459 583 this.Y -= korkeus * 0.25; 460 Lehti = new GameObject(leveys *5, korkeus*0.5);584 Lehti = new GameObject(leveys * 5, korkeus * 0.5); 461 585 Lehti.Bottom = this.Top; 462 586 this.Add(Lehti); … … 525 649 } 526 650 } 651 652 class Tavaraluettelo : GameObject 653 { 654 GameObject ruutu; 655 List<GameObject> ruudut = new List<GameObject>(); 656 657 658 double koko = 100; 659 double erotus = 20; 660 public Tavaraluettelo(double leveys, double korkeus, Image kuva) 661 : base(leveys, korkeus) 662 { 663 ruutu = new GameObject(leveys, korkeus); 664 this.Image = kuva; 665 Lisaaruudut(5); 666 } 667 668 void Lisaaruudut(int maara) 669 { 670 for (int i = 0; i < maara; i++) 671 { 672 Slot slot1 = new Slot(koko - erotus, koko - erotus); 673 double xKoord = i * 1.22 * koko - 248; 674 slot1.X = xKoord; 675 slot1.Teksti.Position = slot1.Position; 676 ruudut.Add(slot1); 677 slot1.Color = Color.Transparent; 678 //slot1.IsVisible = false;' 679 slot1.initialpos = slot1.Position; 680 Add(slot1); 681 Add(slot1.Teksti); 682 } 683 } 684 685 public Slot LisaaResurssi(GameObject resurssi, int count) 686 { 687 foreach (Slot slotti in ruudut) 688 { 689 if (slotti.Maara >= slotti.MaxMaara) slotti.Maara = slotti.MaxMaara; 690 if (slotti.Resurssit.Count >= slotti.MaxMaara) slotti.Maara = slotti.MaxMaara; 691 slotti.Teksti.Text = slotti.Maara.ToString(); 692 if (slotti.Resurssit.Count == 0) 693 slotti.Teksti.Text = ""; 694 if (slotti.Resurssit.Count > 0 && slotti.Resurssit[0].Equals(resurssi)) 695 { 696 if (slotti.Maara >= slotti.MaxMaara) continue; 697 for (int i = 0; i < count; i++) 698 { 699 slotti.Resurssit.Add(resurssi); 700 slotti.Maara = slotti.Resurssit.Count; 701 if (slotti.Maara > slotti.MaxMaara) slotti.Maara = slotti.MaxMaara; 702 slotti.Teksti.Text = slotti.Maara.ToString(); 703 } 704 return slotti; 705 } 706 } 707 foreach (Slot slotti in ruudut) 708 { 709 if (slotti.Resurssit.Count == 0) 710 { 711 slotti.Resurssit.Add(resurssi); 712 slotti.Maara++; 713 slotti.Teksti.Text = slotti.Maara.ToString(); 714 slotti.Image = resurssi.Image; 715 return slotti; 716 } 717 } 718 return null; 719 } 720 } 721 722 public class Slot : GameObject 723 { 724 public Label Teksti; 725 public Vector initialpos; 726 public int Maara = 0; 727 public int MaxMaara = 20; 728 public List<GameObject> Resurssit = new List<GameObject>(); 729 public Slot(double leveys, double korkeus) 730 : base(leveys, korkeus) 731 { 732 Teksti = new Label(); 733 //Teksti.Text = Maara.ToString(); 734 } 735 }
Note: See TracChangeset
for help on using the changeset viewer.