Changeset 15 for trunk/UCore.pas


Ignore:
Timestamp:
Mar 22, 2011, 7:22:46 PM (14 years ago)
Author:
george
Message:
  • Added: Shield and tank destruction.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r14 r15  
    1111const
    1212  MaxBulletCount = 10;
    13   EnergySteps = 400;
    14   ShieldSteps = 400;
     13  EnergySteps = 4000;
     14  ShieldSteps = 40;
    1515  ExplosionBulletCount = 100;
    1616  ExplosionRange = 20;
    1717  ExplosionBulletMaxSpeed = 0.5;
    1818  ExplosionBulletMinSpeed = 0.2;
     19  BulletExplosionRange = 3;
    1920
    2021type
     
    2223  TPlayer = class;
    2324
    24   TSurfaceMatter = (smNothing, smDirt1, smDirt2, smRock, smCannon, smBullet,
     25  TSurfaceMatter = (smNothing, smDirt1, smDirt2, smRock, smCannon,
     26    smBullet1, smBullet2,
    2527    smPlayer1H, smPlayer1L, smPlayer2H, smPlayer2L,
    2628    smPlayer3H, smPlayer3L, smPlayer4H, smPlayer4L);
     
    6365  TPlayer = class
    6466  private
     67    FExploded: Boolean;
    6568    NewDirection: Integer;
    6669    NewPosition: TPoint;
    6770    Dig: Boolean;
     71    LastPos: TPoint;
     72    procedure SetExploded(const AValue: Boolean);
    6873    function ShowTankProc(Item1, Item2: Byte): Byte;
    6974    function HideTankProc(Item1, Item2: Byte): Byte;
     
    7782    Keys: TPlayerKeys;
    7883    Tanks: TListObject;
    79     Bullets: TListObject;
     84    Bullets: TListObject; // TList<TBullet>
    8085    Energy: Real;
    8186    LastEnergy: Real;
    8287    Shield: Real;
     88    LastShield: Real;
    8389    House: TRectangle;
    84     Exploded: Boolean;
    8590    procedure Init;
    86     procedure Explosion;
     91    procedure Explosion(Position: TPoint; Distance: Integer);
    8792    procedure Control;
    8893    procedure Tick;
     
    95100    constructor Create;
    96101    destructor Destroy; override;
     102    property Exploded: Boolean read FExploded write SetExploded;
    97103  end;
    98104
     
    153159const
    154160  SurfaceMatterColors: array[TSurfaceMatter] of TColor = (clBlack, $0756b0,
    155     $2170c3, TColor($9a9a9a), clYellow, clRed,
     161    $2170c3, TColor($9a9a9a), clYellow, clRed, clRed,
    156162    TColor($00ff00), TColor($00a000), TColor($ff2c2c), TColor($b60000),
    157163    TColor($0000ff), TColor($0000a0), TColor($ff2cff), TColor($b600b6));
     
    389395    if Energy <= 0 then begin
    390396      Energy := 0;
    391       Explosion;
     397      Explosion(Position, ExplosionRange);
     398      Exploded := True;
    392399    end;
    393400  end else begin
     
    400407  end;
    401408
     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
    402424  // Bullet movement
    403425  for I := Bullets.Count - 1 downto 0 do
    404   with TBullet(Bullets[I]) do begin
     426  with TBullet(Bullets[I]), Engine.World.Surface do begin
    405427    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;
    407432
    408433    Position.X := Position.X + Direction.X;
     
    418443    Pos := Point(Trunc(Position.X), Trunc(Position.Y));
    419444
    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);
    425451          if StopByDirt then begin
     452            Explosion(LastPos, BulletExplosionRange);
    426453            Bullets.Delete(I);
    427454            Engine.Redraw;
     
    429456          end;
    430457        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);
    431475          Bullets.Delete(I);
    432476          Engine.Redraw;
     
    442486        Continue;
    443487      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);
    445490    Engine.Redraw;
    446491  end;
     492
     493  if not Exploded then ShowTank;
    447494end;
    448495
     
    468515      end;
    469516
     517    // Energy bar
    470518    for I := 1 to ScreenFrame.Width - 2 do
    471519      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
    472526        ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := clBlack
    473         else ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := clYellow;
     527        else ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := clAqua;
    474528  end;
    475529end;
     
    527581end;
    528582
     583procedure TPlayer.SetExploded(const AValue: Boolean);
     584begin
     585  if FExploded = AValue then Exit;
     586  FExploded := AValue;
     587  if FExploded then HideTank else ShowTank;
     588end;
     589
    529590procedure TPlayer.ShowTank;
    530591begin
     
    553614end;
    554615
    555 procedure TPlayer.Explosion;
     616procedure TPlayer.Explosion(Position: TPoint; Distance: Integer);
    556617var
    557618  NewBullet: TBullet;
     
    561622begin
    562623  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
    566625      NewBullet := TBullet.Create;
    567626      NewBullet.Player := Self;
     
    570629      NewBullet.Direction.X := Sin(Angle) * Speed;
    571630      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);
    575634      Bullets.Add(NewBullet);
    576635    end;
Note: See TracChangeset for help on using the changeset viewer.