Changeset 15 for trunk/UCore.pas
- Timestamp:
- Mar 22, 2011, 7:22:46 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r14 r15 11 11 const 12 12 MaxBulletCount = 10; 13 EnergySteps = 400 ;14 ShieldSteps = 40 0;13 EnergySteps = 4000; 14 ShieldSteps = 40; 15 15 ExplosionBulletCount = 100; 16 16 ExplosionRange = 20; 17 17 ExplosionBulletMaxSpeed = 0.5; 18 18 ExplosionBulletMinSpeed = 0.2; 19 BulletExplosionRange = 3; 19 20 20 21 type … … 22 23 TPlayer = class; 23 24 24 TSurfaceMatter = (smNothing, smDirt1, smDirt2, smRock, smCannon, smBullet, 25 TSurfaceMatter = (smNothing, smDirt1, smDirt2, smRock, smCannon, 26 smBullet1, smBullet2, 25 27 smPlayer1H, smPlayer1L, smPlayer2H, smPlayer2L, 26 28 smPlayer3H, smPlayer3L, smPlayer4H, smPlayer4L); … … 63 65 TPlayer = class 64 66 private 67 FExploded: Boolean; 65 68 NewDirection: Integer; 66 69 NewPosition: TPoint; 67 70 Dig: Boolean; 71 LastPos: TPoint; 72 procedure SetExploded(const AValue: Boolean); 68 73 function ShowTankProc(Item1, Item2: Byte): Byte; 69 74 function HideTankProc(Item1, Item2: Byte): Byte; … … 77 82 Keys: TPlayerKeys; 78 83 Tanks: TListObject; 79 Bullets: TListObject; 84 Bullets: TListObject; // TList<TBullet> 80 85 Energy: Real; 81 86 LastEnergy: Real; 82 87 Shield: Real; 88 LastShield: Real; 83 89 House: TRectangle; 84 Exploded: Boolean;85 90 procedure Init; 86 procedure Explosion ;91 procedure Explosion(Position: TPoint; Distance: Integer); 87 92 procedure Control; 88 93 procedure Tick; … … 95 100 constructor Create; 96 101 destructor Destroy; override; 102 property Exploded: Boolean read FExploded write SetExploded; 97 103 end; 98 104 … … 153 159 const 154 160 SurfaceMatterColors: array[TSurfaceMatter] of TColor = (clBlack, $0756b0, 155 $2170c3, TColor($9a9a9a), clYellow, clRed, 161 $2170c3, TColor($9a9a9a), clYellow, clRed, clRed, 156 162 TColor($00ff00), TColor($00a000), TColor($ff2c2c), TColor($b60000), 157 163 TColor($0000ff), TColor($0000a0), TColor($ff2cff), TColor($b600b6)); … … 389 395 if Energy <= 0 then begin 390 396 Energy := 0; 391 Explosion; 397 Explosion(Position, ExplosionRange); 398 Exploded := True; 392 399 end; 393 400 end else begin … … 400 407 end; 401 408 409 // Check shield 410 if House.IsInside(Position) then begin 411 Shield := Shield + 1 / ShieldSteps; 412 if Shield > 1 then Shield := 1; 413 end; 414 if LastShield <> Shield then begin 415 LastShield := Shield; 416 Engine.Redraw; 417 end; 418 if Shield <= 0 then begin 419 Shield := 0; 420 Explosion(Position, ExplosionRange); 421 Exploded := True; 422 end; 423 402 424 // Bullet movement 403 425 for I := Bullets.Count - 1 downto 0 do 404 with TBullet(Bullets[I]) do begin426 with TBullet(Bullets[I]), Engine.World.Surface do begin 405 427 Pos := Point(Trunc(Position.X), Trunc(Position.Y)); 406 Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smNothing); 428 if (ItemsXY[LastPos.X, LastPos.Y] = Byte(smBullet1)) or 429 (ItemsXY[LastPos.X, LastPos.Y] = Byte(smBullet2)) then 430 ItemsXY[LastPos.X, LastPos.Y] := Byte(smNothing); 431 LastPos := Pos; 407 432 408 433 Position.X := Position.X + Direction.X; … … 418 443 Pos := Point(Trunc(Position.X), Trunc(Position.Y)); 419 444 420 if (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] <> Byte(smNothing)) and 421 (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] <> Byte(smBullet)) then begin 422 if (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] = Byte(smDirt1)) or 423 (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] = Byte(smDirt2)) then begin 424 Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smNothing); 445 if (ItemsXY[Pos.X, Pos.Y] <> Byte(smNothing)) and 446 (ItemsXY[Pos.X, Pos.Y] <> Byte(smBullet1)) and 447 (ItemsXY[Pos.X, Pos.Y] <> Byte(smBullet2)) then begin 448 if (ItemsXY[Pos.X, Pos.Y] = Byte(smDirt1)) or 449 (ItemsXY[Pos.X, Pos.Y] = Byte(smDirt2)) then begin 450 ItemsXY[Pos.X, Pos.Y] := Byte(smNothing); 425 451 if StopByDirt then begin 452 Explosion(LastPos, BulletExplosionRange); 426 453 Bullets.Delete(I); 427 454 Engine.Redraw; … … 429 456 end; 430 457 end else begin 458 if (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer1L)) or (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer1H)) then 459 with TPlayer(Engine.Players[0]) do begin 460 Shield := Shield - 1 / ShieldSteps; 461 end; 462 if (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer2L)) or (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer2H)) then 463 with TPlayer(Engine.Players[1]) do begin 464 Shield := Shield - 1 / ShieldSteps; 465 end; 466 if (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer3L)) or (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer3H)) then 467 with TPlayer(Engine.Players[2]) do begin 468 Shield := Shield - 1 / ShieldSteps; 469 end; 470 if (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer4L)) or (ItemsXY[Pos.X, Pos.Y] = Byte(smPlayer4H)) then 471 with TPlayer(Engine.Players[3]) do begin 472 Shield := Shield - 1 / ShieldSteps; 473 end; 474 if StopByDirt then Explosion(LastPos, BulletExplosionRange); 431 475 Bullets.Delete(I); 432 476 Engine.Redraw; … … 442 486 Continue; 443 487 end; 444 Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smBullet); 488 ItemsXY[Pos.X, Pos.Y] := Byte(smBullet1); 489 //Engine.World.Surface.ItemsXY[LastPos.X, LastPos.Y] := Byte(smBullet2); 445 490 Engine.Redraw; 446 491 end; 492 493 if not Exploded then ShowTank; 447 494 end; 448 495 … … 468 515 end; 469 516 517 // Energy bar 470 518 for I := 1 to ScreenFrame.Width - 2 do 471 519 if Energy < I / (ScreenFrame.Width - 2) then 520 ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 2] := clBlack 521 else ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 2] := clYellow; 522 523 // Shield bar 524 for I := 1 to ScreenFrame.Width - 2 do 525 if Shield < I / (ScreenFrame.Width - 2) then 472 526 ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := clBlack 473 else ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := cl Yellow;527 else ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := clAqua; 474 528 end; 475 529 end; … … 527 581 end; 528 582 583 procedure TPlayer.SetExploded(const AValue: Boolean); 584 begin 585 if FExploded = AValue then Exit; 586 FExploded := AValue; 587 if FExploded then HideTank else ShowTank; 588 end; 589 529 590 procedure TPlayer.ShowTank; 530 591 begin … … 553 614 end; 554 615 555 procedure TPlayer.Explosion ;616 procedure TPlayer.Explosion(Position: TPoint; Distance: Integer); 556 617 var 557 618 NewBullet: TBullet; … … 561 622 begin 562 623 if not Exploded then begin 563 Exploded := True; 564 HideTank; 565 for I := 0 to ExplosionBulletCount - 1 do begin 624 for I := 0 to Distance - 1 do begin 566 625 NewBullet := TBullet.Create; 567 626 NewBullet.Player := Self; … … 570 629 NewBullet.Direction.X := Sin(Angle) * Speed; 571 630 NewBullet.Direction.Y := Cos(Angle) * Speed; 572 NewBullet.Position.X := Position.X + NewBullet.Direction.X * 3;573 NewBullet.Position.Y := Position.Y + NewBullet.Direction.Y * 3;574 NewBullet.MaxDistance := Random( ExplosionRange);631 NewBullet.Position.X := Position.X; // + NewBullet.Direction.X * 3; 632 NewBullet.Position.Y := Position.Y; // + NewBullet.Direction.Y * 3; 633 NewBullet.MaxDistance := Random(Distance); 575 634 Bullets.Add(NewBullet); 576 635 end;
Note:
See TracChangeset
for help on using the changeset viewer.