Changeset 12 for trunk/UCore.pas


Ignore:
Timestamp:
Mar 21, 2011, 10:13:45 PM (13 years ago)
Author:
george
Message:
  • Added: Tank explosion on energy exhaustion.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r11 r12  
    1111const
    1212  MaxBulletCount = 10;
    13   EnergySteps = 4000;
     13  EnergySteps = 40;
    1414  ShieldSteps = 40;
     15  ExplosionBulletCount = 200;
     16  ExplosionRange = 15;
    1517
    1618type
     
    2123    smPlayer1H, smPlayer1L, smPlayer2H, smPlayer2L,
    2224    smPlayer3H, smPlayer3L, smPlayer4H, smPlayer4L);
     25
     26  TRealPoint = record
     27    X, Y: Real;
     28  end;
    2329
    2430  TPlayerKeys = record
     
    3238  TBullet = class
    3339    Player: TPlayer;
    34     Position: TPoint;
    35     Direction: Integer;
     40    Position: TRealPoint;
     41    Direction: TRealPoint;
     42    MaxDistance: Integer;
     43    Distance: Real;
     44    StopByDirt: Boolean;
    3645  end;
    3746
     
    6877    Shield: Real;
    6978    House: TRectangle;
    70     procedure BlowUp;
     79    Exploded: Boolean;
     80    procedure Init;
     81    procedure Explosion;
    7182    procedure Control;
     83    procedure Tick;
    7284    procedure Paint;
    7385    procedure PlaceHouse;
     
    287299  NewBullet: TBullet;
    288300  I: Integer;
    289 begin
     301  Pos: TPoint;
     302begin
     303  if Exploded then Exit;
     304
    290305  Delta.X := 0;
    291306  Delta.Y := 0;
     
    324339      NewBullet := TBullet.Create;
    325340      NewBullet.Player := Self;
    326       NewBullet.Position := Point(Position.X + DirectionToDelta[Direction].X * 4,
    327         Position.Y + DirectionToDelta[Direction].Y * 4);
    328       NewBullet.Direction := Direction;
     341      NewBullet.Position.X := Position.X + DirectionToDelta[Direction].X * 4;
     342      NewBullet.Position.Y := Position.Y + DirectionToDelta[Direction].Y * 4;
     343      NewBullet.Direction.X := DirectionToDelta[Direction].X;
     344      NewBullet.Direction.Y := DirectionToDelta[Direction].Y;
     345      NewBullet.StopByDirt := True;
    329346      Bullets.Add(NewBullet);
    330347    end;
    331 
     348end;
     349
     350procedure TPlayer.Tick;
     351var
     352  I: Integer;
     353  Pos: TPoint;
     354begin
    332355  for I := Bullets.Count - 1 downto 0 do
    333356  with TBullet(Bullets[I]) do begin
    334     Engine.World.Surface.ItemsXY[Position.X, Position.Y] := Byte(smNothing);
    335 
    336     Position.X := Position.X + DirectionToDelta[Direction].X;
    337     Position.Y := Position.Y + DirectionToDelta[Direction].Y;
    338 
    339     if Engine.World.Surface.ItemsXY[Position.X, Position.Y] <> Byte(smNothing) then begin
    340       if (Engine.World.Surface.ItemsXY[Position.X, Position.Y] = Byte(smDirt1)) or
    341         (Engine.World.Surface.ItemsXY[Position.X, Position.Y] = Byte(smDirt2)) then
    342           Engine.World.Surface.ItemsXY[Position.X, Position.Y] := Byte(smNothing);
     357    Pos := Point(Trunc(Position.X), Trunc(Position.Y));
     358    Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smNothing);
     359
     360    Position.X := Position.X + Direction.X;
     361    Position.Y := Position.Y + Direction.Y;
     362    Distance := Distance + Sqrt(Sqr(Direction.X) + Sqr(Direction.Y));
     363    //ShowMessage(FloatToStr(Distance));
     364    if (Distance > MaxDistance) and (MaxDistance > 0) then begin
    343365      Bullets.Delete(I);
    344     end else
     366      Continue;
     367    end;
     368
     369    Pos := Point(Trunc(Position.X), Trunc(Position.Y));
     370
     371    if Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] <> Byte(smNothing) then begin
     372      if (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] = Byte(smDirt1)) or
     373        (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] = Byte(smDirt2)) then begin
     374          Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smNothing);
     375          if StopByDirt then begin
     376            Bullets.Delete(I);
     377            Engine.Redraw;
     378            Continue;
     379          end;
     380        end else begin
     381          Bullets.Delete(I);
     382          Engine.Redraw;
     383          Continue;
     384        end;
     385    end;
     386
    345387    with Engine.World.Surface do
    346     if (Position.X >= Count.X) or (Position.X < 0) or
    347       (Position.Y >= Count.Y) or (Position.Y < 0) then
    348       Bullets.Delete(I) else
    349       Engine.World.Surface.ItemsXY[Position.X, Position.Y] := Byte(smBullet);
     388    if (Pos.X >= Count.X) or (Pos.X < 0) or
     389      (Pos.Y >= Count.Y) or (Pos.Y < 0) then begin
     390        Bullets.Delete(I);
     391        Engine.Redraw;
     392        Continue;
     393      end;
     394    Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smBullet);
    350395    Engine.Redraw;
    351396  end;
     
    355400    if Energy <= 0 then begin
    356401      Energy := 0;
    357       BlowUp;
     402      Explosion;
    358403    end;
    359404  end else begin
     
    460505end;
    461506
    462 procedure TPlayer.BlowUp;
    463 begin
    464 
     507procedure TPlayer.Init;
     508begin
     509  with Engine do
     510    Position := Point(Round(World.Surface.Count.X * 0.2) + Random(Round(World.Surface.Count.X * 0.6)),
     511      Round(World.Surface.Count.Y * 0.2) + Random(Round(World.Surface.Count.Y * 0.6)));
     512  Exploded := False;
     513  Bullets.Clear;
     514  Energy := 1;
     515  Shield := 1;
     516  PlaceHouse;
     517end;
     518
     519procedure TPlayer.Explosion;
     520var
     521  NewBullet: TBullet;
     522  I: Integer;
     523const
     524  BulletMaxSpeed = 1;
     525  BulletMinSpeed = 0.5;
     526begin
     527  if not Exploded then begin
     528    Exploded := True;
     529    HideTank;
     530    for I := 0 to ExplosionBulletCount - 1 do begin
     531      NewBullet := TBullet.Create;
     532      NewBullet.Player := Self;
     533      NewBullet.Direction.X := (BulletMaxSpeed - BulletMinSpeed) * (Random - 0.5);
     534      NewBullet.Direction.Y := (BulletMaxSpeed - BulletMinSpeed) * (Random - 0.5);
     535      //NewBullet.Direction.X := NewBullet.Direction.X + BulletMinSpeed * Sign(NewBullet.Direction.X);
     536      //NewBullet.Direction.Y := NewBullet.Direction.Y + BulletMinSpeed * Sign(NewBullet.Direction.Y);
     537      NewBullet.Position.X := Position.X + NewBullet.Direction.X * 2;
     538      NewBullet.Position.Y := Position.Y + NewBullet.Direction.Y * 2;
     539(*      if NewBullet.Direction.X < (Speed / 10) then
     540        NewBullet.Direction.X := Speed / 10;
     541      if NewBullet.Direction.Y < (Speed / 10) then
     542        NewBullet.Direction.Y := Speed / 10;*)
     543      NewBullet.MaxDistance := Random(ExplosionRange);
     544      Bullets.Add(NewBullet);
     545    end;
     546  end;
    465547end;
    466548
     
    681763  for I := 0 to Players.Count - 1 do begin
    682764    TPlayer(Players[I]).Control;
     765    TPlayer(Players[I]).Tick;
    683766  end;
    684767end;
     
    788871  for I := 0 to Players.Count - 1 do
    789872  with TPlayer(Players[I]) do
    790   begin
    791     // Reset position
    792     Position := Point(Round(World.Surface.Count.X * 0.2) + Random(Round(World.Surface.Count.X * 0.6)),
    793       Round(World.Surface.Count.Y * 0.2) + Random(Round(World.Surface.Count.Y * 0.6)));
    794 
    795     Energy := 1;
    796     Shield := 1;
    797     PlaceHouse;
    798   end;
     873    Init;
    799874  Redraw;
    800875end;
Note: See TracChangeset for help on using the changeset viewer.