Changeset 22 for trunk/UCore.pas
- Timestamp:
- Sep 28, 2011, 3:10:01 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r21 r22 24 24 TPlayer = class; 25 25 26 TSurfaceMatter = (smNothing, smDirt1, smDirt2, smRock, smCannon,27 smBullet1, smBullet2,28 smPlayer1H, smPlayer1L, smPlayer2H, smPlayer2L,29 smPlayer3H, smPlayer3L, smPlayer4H, smPlayer4L);30 31 26 TRealPoint = record 32 27 X, Y: Real; … … 61 56 destructor Destroy; override; 62 57 end; 58 59 TMatterIndex = (miSpace, miDirt1, miDirt2, miRock, miBullet1, miBullet2, 60 miPlayer1Cannon, miPlayer1Home, miPlayer1TankBody, miPlayer1TankBody2, 61 miPlayer2Cannon, miPlayer2Home, miPlayer2TankBody, miPlayer2TankBody2, 62 miPlayer3Cannon, miPlayer3Home, miPlayer3TankBody, miPlayer3TankBody2, 63 miPlayer4Cannon, miPlayer4Home, miPlayer4TankBody, miPlayer4TankBody2, 64 miPlayer5Cannon, miPlayer5Home, miPlayer5TankBody, miPlayer5TankBody2, 65 miPlayer6Cannon, miPlayer6Home, miPlayer6TankBody, miPlayer6TankBody2, 66 miPlayer7Cannon, miPlayer7Home, miPlayer7TankBody, miPlayer7TankBody2, 67 miPlayer8Cannon, miPlayer8Home, miPlayer8TankBody, miPlayer8TankBody2); 68 69 TMatterKind = (mkSpace, mkDirt, mkRock, mkCannon, mkBullet, mkTankBody, 70 mkHome); 63 71 64 72 { TPlayer } … … 96 104 procedure Paint; 97 105 procedure PlaceHouse; 98 function CheckColision: T SurfaceMatter;106 function CheckColision: TMatterIndex; 99 107 procedure ShowTank; 100 108 procedure HideTank; … … 105 113 end; 106 114 115 { TMatter } 116 117 TMatter = class 118 Kind: TMatterKind; 119 Player: Integer; 120 Color: TColor; 121 end; 122 107 123 { TWorld } 108 124 … … 111 127 function GetSize: TMatrixByteIndex; 112 128 procedure SetSize(const AValue: TMatrixByteIndex); 129 procedure InitMatter; 113 130 public 114 131 Engine: TEngine; 115 132 Surface: TMatrixByte; 133 Matter: TListObject; // TListObject<TMatter> 116 134 procedure Generate; 117 135 constructor Create; … … 183 201 184 202 const 185 SurfaceMatterColors: array[TSurfaceMatter] of TColor = (clBlack, $0756b0,186 $2170c3, TColor($9a9a9a), clYellow, clRed, clRed,187 TColor($00ff00), TColor($00a000), TColor($ff2c2c), TColor($b60000),188 TColor($0000ff), TColor($0000a0), TColor($ff2cff), TColor($b600b6));189 203 DirectionToDelta: array[0..7] of TPoint = 190 204 ((X: 0; Y: -1), (X: 1; Y: -1), (X: 1; Y: 0), (X: 1; Y: 1), … … 273 287 end; 274 288 289 procedure TWorld.InitMatter; 290 begin 291 // Space 292 with TMatter(Matter.AddNew(TMatter.Create)) do begin 293 Kind := mkSpace; 294 Color := clBlack; 295 Player := -1; 296 end; 297 // Dirt1 298 with TMatter(Matter.AddNew(TMatter.Create)) do begin 299 Kind := mkDirt; 300 Color := $0756b0; 301 Player := -1; 302 end; 303 // Dirt2 304 with TMatter(Matter.AddNew(TMatter.Create)) do begin 305 Kind := mkDirt; 306 Color := $2170c3; 307 Player := -1; 308 end; 309 // Rock 310 with TMatter(Matter.AddNew(TMatter.Create)) do begin 311 Kind := mkRock; 312 Color := TColor($9a9a9a); 313 Player := -1; 314 end; 315 // Bullet1 316 with TMatter(Matter.AddNew(TMatter.Create)) do begin 317 Kind := mkBullet; 318 Color := clRed; 319 Player := -1; 320 end; 321 // Bullet2 322 with TMatter(Matter.AddNew(TMatter.Create)) do begin 323 Kind := mkBullet; 324 Color := clRed; 325 Player := -1; 326 end; 327 328 // Player 1 cannon 329 with TMatter(Matter.AddNew(TMatter.Create)) do begin 330 Kind := mkCannon; 331 Color := clYellow; 332 Player := 0; 333 end; 334 // Player 1 home 335 with TMatter(Matter.AddNew(TMatter.Create)) do begin 336 Kind := mkHome; 337 Color := TColor($00ff00); 338 Player := 0; 339 end; 340 // Player 1 body1 341 with TMatter(Matter.AddNew(TMatter.Create)) do begin 342 Kind := mkTankBody; 343 Color := TColor($00ff00); 344 Player := 0; 345 end; 346 // Player 1 body2 347 with TMatter(Matter.AddNew(TMatter.Create)) do begin 348 Kind := mkTankBody; 349 Color := TColor($00a000); 350 Player := 0; 351 end; 352 353 // Player 2 cannon 354 with TMatter(Matter.AddNew(TMatter.Create)) do begin 355 Kind := mkCannon; 356 Color := clYellow; 357 Player := 1; 358 end; 359 // Player 2 home 360 with TMatter(Matter.AddNew(TMatter.Create)) do begin 361 Kind := mkHome; 362 Color := TColor($ff2c2c); 363 Player := 1; 364 end; 365 // Player 2 body1 366 with TMatter(Matter.AddNew(TMatter.Create)) do begin 367 Kind := mkTankBody; 368 Color := TColor($ff2c2c); 369 Player := 1; 370 end; 371 // Player 2 body2 372 with TMatter(Matter.AddNew(TMatter.Create)) do begin 373 Kind := mkTankBody; 374 Color := TColor($b60000); 375 Player := 1; 376 end; 377 378 // Player 3 cannon 379 with TMatter(Matter.AddNew(TMatter.Create)) do begin 380 Kind := mkCannon; 381 Color := clYellow; 382 Player := 2; 383 end; 384 // Player 3 home 385 with TMatter(Matter.AddNew(TMatter.Create)) do begin 386 Kind := mkHome; 387 Color := TColor($0000ff); 388 Player := 2; 389 end; 390 // Player 3 body1 391 with TMatter(Matter.AddNew(TMatter.Create)) do begin 392 Kind := mkTankBody; 393 Color := TColor($0000ff); 394 Player := 2; 395 end; 396 // Player 3 body2 397 with TMatter(Matter.AddNew(TMatter.Create)) do begin 398 Kind := mkTankBody; 399 Color := TColor($0000a0); 400 Player := 2; 401 end; 402 403 // Player 4 cannon 404 with TMatter(Matter.AddNew(TMatter.Create)) do begin 405 Kind := mkCannon; 406 Color := clYellow; 407 Player := 3; 408 end; 409 // Player 4 home 410 with TMatter(Matter.AddNew(TMatter.Create)) do begin 411 Kind := mkHome; 412 Color := TColor($ff2cff); 413 Player := 3; 414 end; 415 // Player 4 body1 416 with TMatter(Matter.AddNew(TMatter.Create)) do begin 417 Kind := mkTankBody; 418 Color := TColor($ff2cff); 419 Player := 3; 420 end; 421 // Player 4 body2 422 with TMatter(Matter.AddNew(TMatter.Create)) do begin 423 Kind := mkTankBody; 424 Color := TColor($b600b6); 425 Player := 3; 426 end; 427 end; 428 275 429 procedure TWorld.Generate; 276 430 var … … 282 436 for X := 0 to Surface.Count.X - 1 do begin 283 437 if Random < 0.5 then 284 Surface.ItemsXY[X, Y] := Byte( smDirt1) else285 Surface.ItemsXY[X, Y] := Byte( smDirt2);438 Surface.ItemsXY[X, Y] := Byte(miDirt1) else 439 Surface.ItemsXY[X, Y] := Byte(miDirt2); 286 440 end; 287 441 … … 290 444 for Y := 0 to Surface.Count.Y - 1 do begin 291 445 for X := 0 to Round(Distance) - 1 do begin 292 Surface.ItemsXY[X, Y] := Byte( smRock);446 Surface.ItemsXY[X, Y] := Byte(miRock); 293 447 end; 294 448 Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.X) * 2 - 1); … … 300 454 for Y := 0 to Surface.Count.Y - 1 do begin 301 455 for X := 0 to Round(Distance) - 1 do begin 302 Surface.ItemsXY[Surface.Count.X - 1 - X, Y] := Byte( smRock);456 Surface.ItemsXY[Surface.Count.X - 1 - X, Y] := Byte(miRock); 303 457 end; 304 458 Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.X) * 2 - 1); … … 310 464 for X := 0 to Surface.Count.X - 1 do begin 311 465 for Y := 0 to Round(Distance) - 1 do begin 312 Surface.ItemsXY[X, Y] := Byte( smRock);466 Surface.ItemsXY[X, Y] := Byte(miRock); 313 467 end; 314 468 Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.Y) * 2 - 1); … … 320 474 for X := 0 to Surface.Count.X - 1 do begin 321 475 for Y := 0 to Round(Distance) - 1 do begin 322 Surface.ItemsXY[X, Surface.Count.Y - 1 - Y] := Byte( smRock);476 Surface.ItemsXY[X, Surface.Count.Y - 1 - Y] := Byte(miRock); 323 477 end; 324 478 Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.Y) * 2 - 1); … … 331 485 NewSize: TMatrixByteIndex; 332 486 begin 487 Matter := TListObject.Create; 488 InitMatter; 333 489 Surface := TMatrixByte.Create; 334 490 NewSize.X := 800; … … 340 496 begin 341 497 Surface.Free; 498 Matter.Free; 342 499 inherited Destroy; 343 500 end; … … 360 517 PixelPtr := PixelRowPtr; 361 518 for X := 0 to Bitmap.Width - 1 do begin 362 P := SurfaceMatterColors[TSurfaceMatter( 363 Surface.ItemsXY[Trunc(X / Bitmap.Width * Surface.Count.X), 364 Trunc(Y / Bitmap.Height * Surface.Count.Y)])]; 519 P := TMatter(Matter[Surface.ItemsXY[Trunc(X / Bitmap.Width * Surface.Count.X), 520 Trunc(Y / Bitmap.Height * Surface.Count.Y)]]).Color; 365 521 PixelPtr^ := SwapBRComponent(P); 366 522 Inc(PByte(PixelPtr), BytePerPixel); … … 378 534 var 379 535 Delta: TPoint; 380 Matter: T SurfaceMatter;536 Matter: TMatterIndex; 381 537 NewBullet: TBullet; 382 538 I: Integer; … … 408 564 HideTank; 409 565 Matter := CheckColision; 410 if (Matter = smDirt1) then Dig := not Dig;411 if (Matter = smNothing) or ((Matter = smDirt1) and (not Dig)) then begin566 if (Matter = miDirt1) then Dig := not Dig; 567 if (Matter = miSpace) or ((Matter = miDirt1) and (not Dig)) then begin 412 568 Position := NewPosition; 413 569 Direction := NewDirection; … … 474 630 with TBullet(Bullets[I]), Engine.World.Surface do begin 475 631 Pos := Point(Trunc(Position.X), Trunc(Position.Y)); 476 if (ItemsXY[LastPos.X, LastPos.Y] = Byte( smBullet1)) or477 (ItemsXY[LastPos.X, LastPos.Y] = Byte( smBullet2)) then478 ItemsXY[LastPos.X, LastPos.Y] := Byte( smNothing);632 if (ItemsXY[LastPos.X, LastPos.Y] = Byte(miBullet1)) or 633 (ItemsXY[LastPos.X, LastPos.Y] = Byte(miBullet2)) then 634 ItemsXY[LastPos.X, LastPos.Y] := Byte(miSpace); 479 635 LastPos := Pos; 480 636 … … 491 647 Pos := Point(Trunc(Position.X), Trunc(Position.Y)); 492 648 493 if (ItemsXY[Pos.X, Pos.Y] <> Byte( smNothing)) and494 (ItemsXY[Pos.X, Pos.Y] <> Byte( smBullet1)) and495 (ItemsXY[Pos.X, Pos.Y] <> Byte( smBullet2)) then begin496 if (ItemsXY[Pos.X, Pos.Y] = Byte( smDirt1)) or497 (ItemsXY[Pos.X, Pos.Y] = Byte( smDirt2)) then begin498 ItemsXY[Pos.X, Pos.Y] := Byte( smNothing);649 if (ItemsXY[Pos.X, Pos.Y] <> Byte(miSpace)) and 650 (ItemsXY[Pos.X, Pos.Y] <> Byte(miBullet1)) and 651 (ItemsXY[Pos.X, Pos.Y] <> Byte(miBullet2)) then begin 652 if (ItemsXY[Pos.X, Pos.Y] = Byte(miDirt1)) or 653 (ItemsXY[Pos.X, Pos.Y] = Byte(miDirt2)) then begin 654 ItemsXY[Pos.X, Pos.Y] := Byte(miSpace); 499 655 if StopByDirt then begin 500 656 Explosion(LastPos, BulletExplosionRange); … … 504 660 end; 505 661 end else begin 506 if (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer1L)) or (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer1H)) then 662 if (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer1TankBody)) or 663 (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer1TankBody2)) then 507 664 with TPlayer(Engine.Players[0]) do begin 508 665 Shield := Shield - 1 / ShieldSteps; 509 666 end; 510 if (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer2L)) or (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer2H)) then 667 if (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer2Tankbody)) or 668 (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer2TankBody2)) then 511 669 with TPlayer(Engine.Players[1]) do begin 512 670 Shield := Shield - 1 / ShieldSteps; 513 671 end; 514 if (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer3L)) or (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer3H)) then 672 if (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer3TankBody)) or 673 (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer3TankBody2)) then 515 674 with TPlayer(Engine.Players[2]) do begin 516 675 Shield := Shield - 1 / ShieldSteps; 517 676 end; 518 if (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer4L)) or (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer4H)) then 677 if (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer4TankBody)) or 678 (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer4TankBody2)) then 519 679 with TPlayer(Engine.Players[3]) do begin 520 680 Shield := Shield - 1 / ShieldSteps; … … 534 694 Continue; 535 695 end; 536 ItemsXY[Pos.X, Pos.Y] := Byte( smBullet1);696 ItemsXY[Pos.X, Pos.Y] := Byte(miBullet1); 537 697 //Engine.World.Surface.ItemsXY[LastPos.X, LastPos.Y] := Byte(smBullet2); 538 698 Engine.Redraw; … … 552 712 // FillRect(ScreenFrame); 553 713 Fill(CreateIndex(ScreenFrame.Left, ScreenFrame.Top), 554 CreateIndex(ScreenFrame.Right - 1, ScreenFrame.Bottom - 1), SurfaceMatterColors[smRock]); 714 CreateIndex(ScreenFrame.Right - 1, ScreenFrame.Bottom - 1), 715 TMatter(Engine.World.Matter[Integer(miRock)]).Color); 555 716 556 717 with Engine.World do … … 560 721 YY := Y - ScreenFrame.Top - ((ScreenFrame.Bottom - ScreenFrame.Top) div 2) + Position.Y; 561 722 if (YY >= 0) and (YY < Surface.Count.Y) and (XX >= 0) and (XX < Surface.Count.X) then 562 ItemsXY[X, Y] := SurfaceMatterColors[TSurfaceMatter(Surface.ItemsXY[XX, YY])];723 ItemsXY[X, Y] := TMatter(Engine.World.Matter[Surface.ItemsXY[XX, YY]]).Color; 563 724 end; 564 725 … … 592 753 not (((Y = 0) or (Y = (HouseSize - 1))) and (X > ((HouseSize - DoorSize) div 2)) and 593 754 (X < ((HouseSize - 1 + DoorSize) div 2))) 594 then Matter := Byte( smPlayer1H) + Id * 2595 else Matter := Byte( smNothing);755 then Matter := Byte(miPlayer1Cannon) + Id * 4 756 else Matter := Byte(miSpace); 596 757 Engine.World.Surface.ItemsXY[House.Left + X, 597 758 House.Top + Y] := Matter; … … 599 760 end; 600 761 601 function TPlayer.CheckColision: T SurfaceMatter;762 function TPlayer.CheckColision: TMatterIndex; 602 763 var 603 764 X, Y: Integer; 604 765 XX, YY: Integer; 605 766 begin 606 Result := smNothing;767 Result := miSpace; 607 768 with Engine.World, TTank(Tanks[NewDirection]) do 608 769 for Y := 0 to Image.Count.Y - 1 do … … 611 772 YY := Y + NewPosition.Y - Image.Count.Y div 2; 612 773 if (Image.ItemsXY[X, Y] > 0) and 613 (Surface.ItemsXY[XX, YY] <> Byte( smNothing)) then774 (Surface.ItemsXY[XX, YY] <> Byte(miSpace)) then 614 775 begin 615 Result := smDirt1;616 if (Surface.ItemsXY[XX, YY] <> Byte( smDirt1)) and617 (Surface.ItemsXY[XX, YY] <> Byte( smDirt2)) then776 Result := miDirt1; 777 if (Surface.ItemsXY[XX, YY] <> Byte(miDirt1)) and 778 (Surface.ItemsXY[XX, YY] <> Byte(miDirt2)) then 618 779 begin 619 Result := T SurfaceMatter(Surface.ItemsXY[XX, YY]);780 Result := TMatterIndex(Surface.ItemsXY[XX, YY]); 620 781 Exit; 621 782 end; … … 709 870 Image.Count := Image.CreateIndex(7, 7); 710 871 for I := 0 to 3 do 711 Image[3, I] := Byte( smCannon);872 Image[3, I] := Byte(miPlayer1Cannon) + Id * 4; 712 873 for I := 1 to 6 do begin 713 Image[1, I] := Byte( smPlayer1H) + Id * 2;714 Image[5, I] := Byte( smPlayer1H) + Id * 2;874 Image[1, I] := Byte(miPlayer1TankBody) + Id * 4; 875 Image[5, I] := Byte(miPlayer1TankBody) + Id * 4; 715 876 end; 716 877 for I := 2 to 5 do begin 717 Image[2, I] := Byte( smPlayer1H) + Id * 2 + 1;718 Image[4, I] := Byte( smPlayer1H) + Id * 2 + 1;719 end; 720 Image[3, 4] := Byte( smPlayer1H) + Id * 2 + 1;721 Image[3, 5] := Byte( smPlayer1H) + Id * 2 + 1;878 Image[2, I] := Byte(miPlayer1TankBody2) + Id * 4; 879 Image[4, I] := Byte(miPlayer1TankBody2) + Id * 4; 880 end; 881 Image[3, 4] := Byte(miPlayer1TankBody2) + Id * 4; 882 Image[3, 5] := Byte(miPlayer1TankBody2) + Id * 4; 722 883 end; 723 884 Tanks.Add(NewTank); … … 727 888 Image.Count := Image.CreateIndex(7, 7); 728 889 for I := 0 to 2 do 729 Image[3 + I, 3 - I] := Byte( smCannon);890 Image[3 + I, 3 - I] := Byte(miPlayer1Cannon) + Id * 4; 730 891 for I := 0 to 3 do begin 731 Image[I, 3 - I] := Byte( smPlayer1H) + Id * 2;732 Image[3 + I, 6 - I] := Byte( smPlayer1H) + Id * 2;892 Image[I, 3 - I] := Byte(miPlayer1TankBody) + Id * 4; 893 Image[3 + I, 6 - I] := Byte(miPlayer1TankBody) + Id * 4; 733 894 end; 734 895 for I := 0 to 2 do begin 735 Image[1 + I, 3 - I] := Byte( smPlayer1H) + Id * 2 + 1;736 Image[3 + I, 5 - I] := Byte( smPlayer1H) + Id * 2 + 1;737 end; 738 Image[3, 2] := Byte( smPlayer1H) + Id * 2 + 1;739 Image[2, 3] := Byte( smPlayer1H) + Id * 2 + 1;740 Image[2, 4] := Byte( smPlayer1H) + Id * 2 + 1;741 Image[3, 4] := Byte( smPlayer1H) + Id * 2 + 1;742 Image[4, 3] := Byte( smPlayer1H) + Id * 2 + 1;896 Image[1 + I, 3 - I] := Byte(miPlayer1TankBody2) + Id * 4; 897 Image[3 + I, 5 - I] := Byte(miPlayer1TankBody2) + Id * 4; 898 end; 899 Image[3, 2] := Byte(miPlayer1TankBody2) + Id * 4; 900 Image[2, 3] := Byte(miPlayer1TankBody2) + Id * 4; 901 Image[2, 4] := Byte(miPlayer1TankBody2) + Id * 4; 902 Image[3, 4] := Byte(miPlayer1TankBody2) + Id * 4; 903 Image[4, 3] := Byte(miPlayer1TankBody2) + Id * 4; 743 904 end; 744 905 Tanks.Add(NewTank);
Note:
See TracChangeset
for help on using the changeset viewer.