Changeset 27 for trunk/UCore.pas
- Timestamp:
- Sep 29, 2011, 11:10:27 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r26 r27 14 14 EnergySteps = 4000; 15 15 EnergyDecreaseDig = 0.001; 16 EnergyDecreaseShoot = 0.005; 16 17 ShieldSteps = 40; 17 18 ExplosionBulletCount = 100; … … 19 20 ExplosionBulletMaxSpeed = 0.5; 20 21 ExplosionBulletMinSpeed = 0.2; 21 BulletExplosionRange = 3;22 ShootDelay = 0. 2; // seconds22 BulletExplosionRange = 4; 23 ShootDelay = 0.1; // seconds 23 24 DigDelay = 0.2; // seconds 24 ShootDigDelay = 0.0 05; // seconds25 ShootEnergyDecrease = 0.01;25 ShootDigDelay = 0.05; // seconds 26 MoveDelay = 0.05; // seconds 26 27 PlayerFrameWidth = 80; 27 28 PlayerFrameHeight = 80; … … 78 79 TMatterKind = (mkSpace, mkDirt, mkRock, mkBullet, mkTankBody, 79 80 mkHome, mkBorder); 81 82 TColisionState = record 83 Blocking: Boolean; 84 Diggable: Boolean; 85 end; 80 86 81 87 { TPlayer } … … 105 111 LastShootTime: TDateTime; 106 112 LastDigTime: TDateTime; 113 LastMoveTime: TDateTime; 107 114 Energy: Real; 108 115 LastEnergy: Real; … … 113 120 procedure Explosion(Position: TPoint; Distance: Integer); 114 121 procedure Control; 122 function CheckNewDestination: Boolean; 115 123 procedure Tick; 116 124 procedure Paint; 117 125 procedure PlaceHouse; 118 function CheckColision: T MatterIndex;126 function CheckColision: TColisionState; 119 127 procedure ShowTank; 120 128 procedure HideTank; … … 131 139 Player: Integer; 132 140 Color: TColor; 141 Diggable: Boolean; 142 Blocking: Boolean; 133 143 end; 134 144 … … 241 251 repeat 242 252 Engine.Tick; 243 Sleep( 50);253 Sleep(10); 244 254 until Terminated; 245 255 end; … … 314 324 Color := $0756b0; 315 325 Player := -1; 326 Diggable := True; 316 327 end; 317 328 // Dirt2 … … 320 331 Color := $2170c3; 321 332 Player := -1; 333 Diggable := True; 322 334 end; 323 335 // Rock … … 326 338 Color := TColor($9a9a9a); 327 339 Player := -1; 340 Blocking := True; 328 341 end; 329 342 // Bullet1 … … 351 364 Color := clYellow; 352 365 Player := 0; 366 Blocking := True; 353 367 end; 354 368 // Player 1 home … … 357 371 Color := TColor($00ff00); 358 372 Player := 0; 373 Blocking := True; 359 374 end; 360 375 // Player 1 body1 … … 363 378 Color := TColor($00ff00); 364 379 Player := 0; 380 Blocking := True; 365 381 end; 366 382 // Player 1 body2 … … 369 385 Color := TColor($00a000); 370 386 Player := 0; 387 Blocking := True; 371 388 end; 372 389 … … 376 393 Color := clYellow; 377 394 Player := 1; 395 Blocking := True; 378 396 end; 379 397 // Player 2 home … … 382 400 Color := TColor($ff2c2c); 383 401 Player := 1; 402 Blocking := True; 384 403 end; 385 404 // Player 2 body1 … … 388 407 Color := TColor($ff2c2c); 389 408 Player := 1; 409 Blocking := True; 390 410 end; 391 411 // Player 2 body2 … … 394 414 Color := TColor($b60000); 395 415 Player := 1; 416 Blocking := True; 396 417 end; 397 418 … … 401 422 Color := clYellow; 402 423 Player := 2; 424 Blocking := True; 403 425 end; 404 426 // Player 3 home … … 407 429 Color := TColor($0000ff); 408 430 Player := 2; 431 Blocking := True; 409 432 end; 410 433 // Player 3 body1 … … 413 436 Color := TColor($0000ff); 414 437 Player := 2; 438 Blocking := True; 415 439 end; 416 440 // Player 3 body2 … … 419 443 Color := TColor($0000a0); 420 444 Player := 2; 445 Blocking := True; 421 446 end; 422 447 … … 426 451 Color := clYellow; 427 452 Player := 3; 453 Blocking := True; 428 454 end; 429 455 // Player 4 home … … 432 458 Color := TColor($ff2cff); 433 459 Player := 3; 460 Blocking := True; 434 461 end; 435 462 // Player 4 body1 … … 438 465 Color := TColor($ff2cff); 439 466 Player := 3; 467 Blocking := True; 440 468 end; 441 469 // Player 4 body2 … … 444 472 Color := TColor($b600b6); 445 473 Player := 3; 474 Blocking := True; 446 475 end; 447 476 … … 451 480 Color := clYellow; 452 481 Player := 4; 482 Blocking := True; 453 483 end; 454 484 // Player 5 home … … 457 487 Color := TColor($ffff2c); 458 488 Player := 4; 489 Blocking := True; 459 490 end; 460 491 // Player 5 body1 … … 463 494 Color := TColor($ffff2c); 464 495 Player := 4; 496 Blocking := True; 465 497 end; 466 498 // Player 5 body2 … … 469 501 Color := TColor($b6b600); 470 502 Player := 4; 503 Blocking := True; 471 504 end; 472 505 … … 476 509 Color := clYellow; 477 510 Player := 5; 511 Blocking := True; 478 512 end; 479 513 // Player 6 home … … 482 516 Color := TColor($2cffff); 483 517 Player := 5; 518 Blocking := True; 484 519 end; 485 520 // Player 6 body1 … … 488 523 Color := TColor($2cffff); 489 524 Player := 5; 525 Blocking := True; 490 526 end; 491 527 // Player 6 body2 … … 494 530 Color := TColor($00b6b6); 495 531 Player := 5; 532 Blocking := True; 496 533 end; 497 534 … … 501 538 Color := clYellow; 502 539 Player := 6; 540 Blocking := True; 503 541 end; 504 542 // Player 7 home … … 507 545 Color := TColor($008cff); 508 546 Player := 6; 547 Blocking := True; 509 548 end; 510 549 // Player 7 body1 … … 513 552 Color := TColor($008cff); 514 553 Player := 6; 554 Blocking := True; 515 555 end; 516 556 // Player 7 body2 … … 519 559 Color := TColor($002da0); 520 560 Player := 6; 561 Blocking := True; 521 562 end; 522 563 … … 526 567 Color := clYellow; 527 568 Player := 7; 569 Blocking := True; 528 570 end; 529 571 // Player 8 home … … 532 574 Color := TColor($d0d0d0); 533 575 Player := 7; 576 Blocking := True; 534 577 end; 535 578 // Player 8 body1 … … 538 581 Color := TColor($d0d0d0); 539 582 Player := 7; 583 Blocking := True; 540 584 end; 541 585 // Player 8 body2 … … 544 588 Color := TColor($707070); 545 589 Player := 7; 590 Blocking := True; 546 591 end; 547 592 end; … … 658 703 I: Integer; 659 704 Pos: TPoint; 705 ColisionState: TColisionState; 660 706 begin 661 707 if Exploded then Exit; … … 679 725 else if (Delta.X = -1) and (Delta.Y = -1) then NewDirection := 7; 680 726 681 if NewDirection = Direction then 682 NewPosition := Point(Position.X + Delta.X, Position.Y + Delta.Y) 683 else NewPosition := Position; 684 HideTank; 685 Matter := CheckColision; 686 if (Matter = miDirt1) and ( 687 (Engine.KeyBoard.KeyState[Ord(Keys.Shoot)] and 688 ((Now - LastDigTime) > ShootDigDelay * OneSecond)) or 689 (not Engine.KeyBoard.KeyState[Ord(Keys.Shoot)] and 690 ((Now - LastDigTime) > DigDelay * OneSecond))) then begin 691 Dig := not Dig; 692 with Engine, World do 693 Surface.Merge(Surface.CreateIndex( 694 Position.X - TMatrixByte(DigMasks[Direction]).Count.X div 2, 695 Position.Y - TMatrixByte(DigMasks[Direction]).Count.Y div 2), 696 TMatrixByte(DigMasks[Direction]), DigProc); 697 Energy := Energy - EnergyDecreaseDig; 698 if Energy < 0 then Energy := 0; 699 Engine.Redraw; 700 LastDigTime := Now; 701 Direction := NewDirection; 702 end; 703 if (Matter = miSpace) then begin 704 Position := NewPosition; 705 Direction := NewDirection; 706 Engine.Redraw; 707 end; 708 ShowTank; 727 if NewDirection = Direction then begin 728 NewPosition := Point(Position.X + Delta.X, Position.Y + Delta.Y); 729 CheckNewDestination; 730 end else begin 731 NewPosition := Position; 732 if not CheckNewDestination then begin 733 // if direction is changed then try to check movement plus one step 734 // to prevent tank block 735 NewPosition := Point(Position.X + Delta.X, Position.Y + Delta.Y); 736 CheckNewDestination; 737 end; 738 end; 709 739 end; 710 740 … … 722 752 LastShootTime := Now; 723 753 724 Energy := Energy - ShootEnergyDecrease;754 Energy := Energy - EnergyDecreaseShoot; 725 755 if Energy < 0 then Energy := 0; 726 end; 756 757 // Do not imedietelly clear dirt by bullet in front of tank 758 //with Engine, World do 759 //if TMatter(Matter[Surface.Items[Position]]).Diggable ; 760 end; 761 end; 762 763 function TPlayer.CheckNewDestination: Boolean; 764 var 765 ColisionState: TColisionState; 766 begin 767 Result := False; 768 HideTank; 769 ColisionState := CheckColision; 770 if not ColisionState.Blocking then begin 771 if ColisionState.Diggable then begin 772 if (Engine.KeyBoard.KeyState[Ord(Keys.Shoot)] and 773 ((Now - LastDigTime) > ShootDigDelay * OneSecond)) or 774 (not Engine.KeyBoard.KeyState[Ord(Keys.Shoot)] and 775 ((Now - LastDigTime) > DigDelay * OneSecond)) then begin 776 Dig := not Dig; 777 with Engine, World do 778 Surface.Merge(Surface.CreateIndex( 779 Position.X - TMatrixByte(DigMasks[Direction]).Count.X div 2, 780 Position.Y - TMatrixByte(DigMasks[Direction]).Count.Y div 2), 781 TMatrixByte(DigMasks[Direction]), DigProc); 782 Energy := Energy - EnergyDecreaseDig; 783 if Energy < 0 then Energy := 0; 784 Engine.Redraw; 785 LastDigTime := Now; 786 Direction := NewDirection; 787 Result := True; 788 end; 789 end else begin 790 if ((Now - LastMoveTime) > MoveDelay * OneSecond) then begin 791 Position := NewPosition; 792 Direction := NewDirection; 793 Result := True; 794 Engine.Redraw; 795 LastMoveTime := Now; 796 end; 797 end; 798 end; 799 ShowTank; 727 800 end; 728 801 … … 776 849 ItemsXY[LastPos.X, LastPos.Y] := Byte(miSpace); 777 850 LastPos := Pos; 851 P := Trunc(Direction.Y); 778 852 779 853 Position.X := Position.X + Direction.X; … … 794 868 if (ItemsXY[Pos.X, Pos.Y] = Byte(miDirt1)) or 795 869 (ItemsXY[Pos.X, Pos.Y] = Byte(miDirt2)) then begin 796 ItemsXY[Pos.X, Pos.Y] := Byte(miSpace);870 //ItemsXY[Pos.X, Pos.Y] := Byte(miSpace); 797 871 if StopByDirt then begin 798 872 Explosion(LastPos, BulletExplosionRange); … … 804 878 for P := 0 to Engine.Players.Count - 1 do 805 879 with TPlayer(Engine.Players[P]) do 806 if ( Id <> P) and880 if (Self.Id <> P) and 807 881 (TMatter(Engine.World.Matter[ItemsXY[Pos.X, Pos.Y]]).Kind = mkTankBody) and 808 882 (TMatter(Engine.World.Matter[ItemsXY[Pos.X, Pos.Y]]).Player = P) then … … 815 889 end; 816 890 891 // Max position limit checking 817 892 with Engine.World.Surface do 818 893 if (Pos.X >= Count.X) or (Pos.X < 0) or … … 823 898 end; 824 899 ItemsXY[Pos.X, Pos.Y] := Byte(miBullet1); 825 //Engine.World.Surface.ItemsXY[LastPos.X, LastPos.Y] := Byte(smBullet2);900 ItemsXY[LastPos.X, LastPos.Y] := Byte(miBullet2); 826 901 Engine.Redraw; 827 902 end; … … 885 960 end; 886 961 887 function TPlayer.CheckColision: T MatterIndex;962 function TPlayer.CheckColision: TColisionState; 888 963 var 889 964 X, Y: Integer; 890 965 XX, YY: Integer; 891 966 begin 892 Result := miSpace; 893 with Engine.World, TTank(Tanks[NewDirection]) do 967 Result.Diggable := False; 968 Result.Blocking := False; 969 with Engine, World, TTank(Tanks[NewDirection]) do 894 970 for Y := 0 to Image.Count.Y - 1 do 895 971 for X := 0 to Image.Count.X - 1 do begin 896 972 XX := X + NewPosition.X - Image.Count.X div 2; 897 973 YY := Y + NewPosition.Y - Image.Count.Y div 2; 898 if (Image.ItemsXY[X, Y] > 0) and 899 (Surface.ItemsXY[XX, YY] <> Byte(miSpace)) then 900 begin 901 Result := miDirt1; 902 if (Surface.ItemsXY[XX, YY] <> Byte(miDirt1)) and 903 (Surface.ItemsXY[XX, YY] <> Byte(miDirt2)) then 904 begin 905 Result := TMatterIndex(Surface.ItemsXY[XX, YY]); 906 Exit; 907 end; 974 if Image.ItemsXY[X, Y] > 0 then begin 975 if TMatter(Matter[Surface.ItemsXY[XX, YY]]).Blocking then 976 Result.Blocking := True; 977 if TMatter(Matter[Surface.ItemsXY[XX, YY]]).Diggable then 978 Result.Diggable := True; 908 979 end; 909 980 end; … … 966 1037 begin 967 1038 if not Exploded then begin 968 for I := 0 to Distance * 2 - 1 do begin1039 for I := 0 to Distance * 2 - 1 do begin 969 1040 NewBullet := TBullet.Create; 970 1041 NewBullet.Player := Self;
Note:
See TracChangeset
for help on using the changeset viewer.