Changeset 13 for trunk/UCore.pas


Ignore:
Timestamp:
Mar 22, 2011, 5:24:11 PM (14 years ago)
Author:
george
Message:
  • Fixed: Tank explosion effect.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r12 r13  
    1111const
    1212  MaxBulletCount = 10;
    13   EnergySteps = 40;
    14   ShieldSteps = 40;
    15   ExplosionBulletCount = 200;
    16   ExplosionRange = 15;
     13  EnergySteps = 400;
     14  ShieldSteps = 400;
     15  ExplosionBulletCount = 100;
     16  ExplosionRange = 20;
     17  ExplosionBulletMaxSpeed = 0.5;
     18  ExplosionBulletMinSpeed = 0.2;
    1719
    1820type
     
    3537    Shoot: Word;
    3638  end;
     39
     40  { TBullet }
    3741
    3842  TBullet = class
     
    4347    Distance: Real;
    4448    StopByDirt: Boolean;
     49    constructor Create;
    4550  end;
    4651
     
    163168end;
    164169
     170{ TBullet }
     171
     172constructor TBullet.Create;
     173begin
     174  MaxDistance := -1;
     175  Distance := 0;
     176end;
     177
    165178{ TTank }
    166179
     
    352365  I: Integer;
    353366  Pos: TPoint;
    354 begin
     367  D: Real;
     368begin
     369  // Check energy
     370  if not Engine.IsInsideHouses(Position) then begin
     371    Energy := Energy - 1 / EnergySteps;
     372    if Energy <= 0 then begin
     373      Energy := 0;
     374      Explosion;
     375    end;
     376  end else begin
     377    Energy := Energy + 5 * 1 / EnergySteps;
     378    if Energy > 1 then Energy := 1;
     379  end;
     380  if LastEnergy <> Energy then begin
     381    LastEnergy := Energy;
     382    Engine.Redraw;
     383  end;
     384
     385  // Bullet movement
    355386  for I := Bullets.Count - 1 downto 0 do
    356387  with TBullet(Bullets[I]) do begin
     
    362393    Distance := Distance + Sqrt(Sqr(Direction.X) + Sqr(Direction.Y));
    363394    //ShowMessage(FloatToStr(Distance));
    364     if (Distance > MaxDistance) and (MaxDistance > 0) then begin
     395    if (Distance > MaxDistance) and (MaxDistance >= 0) then begin
    365396      Bullets.Delete(I);
     397      Engine.Redraw;
    366398      Continue;
    367399    end;
     
    369401    Pos := Point(Trunc(Position.X), Trunc(Position.Y));
    370402
    371     if Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] <> Byte(smNothing) then begin
     403    if (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] <> Byte(smNothing)) and
     404    (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] <> Byte(smBullet)) then begin
    372405      if (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] = Byte(smDirt1)) or
    373406        (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] = Byte(smDirt2)) then begin
     
    393426      end;
    394427    Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smBullet);
    395     Engine.Redraw;
    396   end;
    397 
    398   if not Engine.IsInsideHouses(Position) then begin
    399     Energy := Energy - 1 / EnergySteps;
    400     if Energy <= 0 then begin
    401       Energy := 0;
    402       Explosion;
    403     end;
    404   end else begin
    405     Energy := Energy + 5 * 1 / EnergySteps;
    406     if Energy > 1 then Energy := 1;
    407   end;
    408   if LastEnergy <> Energy then begin
    409     LastEnergy := Energy;
    410428    Engine.Redraw;
    411429  end;
     
    521539  NewBullet: TBullet;
    522540  I: Integer;
    523 const
    524   BulletMaxSpeed = 1;
    525   BulletMinSpeed = 0.5;
     541  Speed: Real;
     542  Angle: Real;
    526543begin
    527544  if not Exploded then begin
     
    531548      NewBullet := TBullet.Create;
    532549      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;*)
     550      Speed := ExplosionBulletMinSpeed + (ExplosionBulletMaxSpeed - ExplosionBulletMinSpeed) * Random;
     551      Angle := Random * 2 * Pi;
     552      NewBullet.Direction.X := Sin(Angle) * Speed;
     553      NewBullet.Direction.Y := Cos(Angle) * Speed;
     554      NewBullet.Position.X := Position.X + NewBullet.Direction.X * 3;
     555      NewBullet.Position.Y := Position.Y + NewBullet.Direction.Y * 3;
    543556      NewBullet.MaxDistance := Random(ExplosionRange);
    544557      Bullets.Add(NewBullet);
Note: See TracChangeset for help on using the changeset viewer.