Changeset 92


Ignore:
Timestamp:
May 18, 2024, 7:39:30 PM (7 weeks ago)
Author:
chronos
Message:
  • Fixed: Check player houses minimal distance to not overlap them.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Engine.pas

    r87 r92  
    112112    function HideTankProc(Item1, Item2: Byte): Byte;
    113113    function DigProc(Item1, Item2: Byte): Byte;
     114    function CheckMinStartPositionDistance: Boolean;
    114115  public
    115116    Name: string;
     
    293294
    294295uses
    295   Platform, FastPixel, UITypes2;
     296  Platform, FastPixel, UITypes2, Geometric;
    296297
    297298resourcestring
     
    747748    Position.Y := Position.Y + Direction.Y;
    748749    Distance := Distance + Sqrt(Sqr(Direction.X) + Sqr(Direction.Y));
    749     //ShowMessage(FloatToStr(Distance));
    750750    if (Distance > MaxDistance) and (MaxDistance >= 0) then begin
    751751      Bullets.Delete(I);
     
    917917end;
    918918
     919function TPlayer.CheckMinStartPositionDistance: Boolean;
     920var
     921  I: Integer;
     922  MinDistance: Integer;
     923begin
     924  MinDistance := Trunc(Sqrt(Sqr(2 * PlayerHouseSize) + Sqr(2 * PlayerHouseSize)));
     925  Result := False;
     926  for I := 0 to Engine.Players.Count - 1 do
     927  if Engine.Players[I] <> Self then
     928  if Distance(Engine.Players[I].StartPosition, StartPosition) < MinDistance then begin
     929    Result := True;
     930    Break;
     931  end;
     932end;
     933
    919934procedure TPlayer.ResetTank;
    920935begin
     
    932947
    933948procedure TPlayer.Init;
     949var
     950  I: Integer;
    934951begin
    935952  with Engine do
     953  for I := 0 to 100 do begin
    936954    StartPosition := Point(Round(World.Surface.Count.X * 0.2) + Random(Round(World.Surface.Count.X * 0.6)),
    937955      Round(World.Surface.Count.Y * 0.2) + Random(Round(World.Surface.Count.Y * 0.6)));
     956    if not CheckMinStartPositionDistance then Break;
     957  end;
    938958  Position := StartPosition;
    939959  PlaceHouse;
     
    12901310    end;
    12911311    Inc(PByte(PixelRowPtr), BytePerRow * SubPixelSizeY);
    1292       end;
     1312  end;
    12931313end;
    12941314
Note: See TracChangeset for help on using the changeset viewer.