Changeset 25 for trunk/UCore.pas


Ignore:
Timestamp:
Sep 29, 2011, 6:03:28 PM (13 years ago)
Author:
george
Message:
  • Added: Decrease tank energy on bullet fire.
  • Fixed: Do not hit self by own bullets.
  • Fixed: Shoot bullets in minimum interval.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r24 r25  
    88  Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList,
    99  IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math, URectangle,
    10   Syncobjs, UThreading, Forms;
     10  Syncobjs, UThreading, Forms, DateUtils;
    1111
    1212const
     
    1919  ExplosionBulletMinSpeed = 0.2;
    2020  BulletExplosionRange = 3;
     21  ShootDelay = 0.2; // seconds
     22  ShootEnergyDecrease = 0.01;
    2123
    2224type
     
    6769    miPlayer8Cannon, miPlayer8Home, miPlayer8TankBody, miPlayer8TankBody2);
    6870
    69   TMatterKind = (mkSpace, mkDirt, mkRock, mkCannon, mkBullet, mkTankBody,
     71  TMatterKind = (mkSpace, mkDirt, mkRock, mkBullet, mkTankBody,
    7072    mkHome);
    7173
     
    9395    Tanks: TListObject; // TListObject<TTank>
    9496    Bullets: TListObject; // TListObject<TBullet>
     97    LastShootTime: TDateTime;
    9598    Energy: Real;
    9699    LastEnergy: Real;
     
    328331  // Player 1 cannon
    329332  with TMatter(Matter.AddNew(TMatter.Create)) do begin
    330     Kind := mkCannon;
     333    Kind := mkTankBody;
    331334    Color := clYellow;
    332335    Player := 0;
     
    353356  // Player 2 cannon
    354357  with TMatter(Matter.AddNew(TMatter.Create)) do begin
    355     Kind := mkCannon;
     358    Kind := mkTankBody;
    356359    Color := clYellow;
    357360    Player := 1;
     
    378381  // Player 3 cannon
    379382  with TMatter(Matter.AddNew(TMatter.Create)) do begin
    380     Kind := mkCannon;
     383    Kind := mkTankBody;
    381384    Color := clYellow;
    382385    Player := 2;
     
    403406  // Player 4 cannon
    404407  with TMatter(Matter.AddNew(TMatter.Create)) do begin
    405     Kind := mkCannon;
     408    Kind := mkTankBody;
    406409    Color := clYellow;
    407410    Player := 3;
     
    428431  // Player 5 cannon
    429432  with TMatter(Matter.AddNew(TMatter.Create)) do begin
    430     Kind := mkCannon;
     433    Kind := mkTankBody;
    431434    Color := clYellow;
    432435    Player := 4;
     
    453456  // Player 6 cannon
    454457  with TMatter(Matter.AddNew(TMatter.Create)) do begin
    455     Kind := mkCannon;
     458    Kind := mkTankBody;
    456459    Color := clYellow;
    457460    Player := 5;
     
    478481  // Player 7 cannon
    479482  with TMatter(Matter.AddNew(TMatter.Create)) do begin
    480     Kind := mkCannon;
     483    Kind := mkTankBody;
    481484    Color := clYellow;
    482485    Player := 6;
     
    503506  // Player 8 cannon
    504507  with TMatter(Matter.AddNew(TMatter.Create)) do begin
    505     Kind := mkCannon;
     508    Kind := mkTankBody;
    506509    Color := clYellow;
    507510    Player := 7;
     
    674677
    675678  if Engine.KeyBoard.KeyState[Ord(Keys.Shoot)] then
    676     if Bullets.Count < MaxBulletCount then begin
     679    if (Bullets.Count < MaxBulletCount) and
     680    ((Now - LastShootTime) > ShootDelay * OneSecond) then begin
    677681      NewBullet := TBullet.Create;
    678682      NewBullet.Player := Self;
     
    683687      NewBullet.StopByDirt := True;
    684688      Bullets.Add(NewBullet);
     689      LastShootTime := Now;
     690
     691      Energy := Energy - ShootEnergyDecrease;
     692      if Energy < 0 then Energy := 0;
    685693    end;
    686694end;
     
    763771          for P := 0 to Engine.Players.Count - 1 do
    764772          with TPlayer(Engine.Players[P]) do
    765           if (TMatter(Engine.World.Matter[ItemsXY[Pos.X, Pos.Y]]).Kind = mkTankBody) and
     773          if (Id <> P) and
     774            (TMatter(Engine.World.Matter[ItemsXY[Pos.X, Pos.Y]]).Kind = mkTankBody) and
    766775            (TMatter(Engine.World.Matter[ItemsXY[Pos.X, Pos.Y]]).Player = P) then
    767776            Shield := Shield - 1 / ShieldSteps;
Note: See TracChangeset for help on using the changeset viewer.