Changeset 12


Ignore:
Timestamp:
Mar 21, 2011, 10:13:45 PM (14 years ago)
Author:
george
Message:
  • Added: Tank explosion on energy exhaustion.
Location:
trunk
Files:
2 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;
  • trunk/tunneler.lpi

    r11 r12  
    4949        <WindowIndex Value="0"/>
    5050        <TopLine Value="1"/>
    51         <CursorPos X="62" Y="19"/>
    52         <UsageCount Value="77"/>
     51        <CursorPos X="15" Y="4"/>
     52        <UsageCount Value="78"/>
    5353      </Unit0>
    5454      <Unit1>
     
    5858        <ResourceBaseClass Value="Form"/>
    5959        <UnitName Value="UMainForm"/>
    60         <EditorIndex Value="6"/>
     60        <EditorIndex Value="8"/>
    6161        <WindowIndex Value="0"/>
    6262        <TopLine Value="96"/>
    6363        <CursorPos X="6" Y="101"/>
    64         <UsageCount Value="77"/>
     64        <UsageCount Value="78"/>
    6565        <Loaded Value="True"/>
    6666        <LoadedDesigner Value="True"/>
     
    7373        <EditorIndex Value="0"/>
    7474        <WindowIndex Value="0"/>
    75         <TopLine Value="1"/>
    76         <CursorPos X="19" Y="13"/>
    77         <UsageCount Value="77"/>
     75        <TopLine Value="518"/>
     76        <CursorPos X="9" Y="535"/>
     77        <UsageCount Value="78"/>
    7878        <Loaded Value="True"/>
    7979      </Unit2>
     
    104104      <Unit6>
    105105        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/objpas/classes/classesh.inc"/>
    106         <WindowIndex Value="0"/>
    107         <TopLine Value="1769"/>
    108         <CursorPos X="10" Y="1786"/>
    109         <UsageCount Value="10"/>
     106        <EditorIndex Value="2"/>
     107        <WindowIndex Value="0"/>
     108        <TopLine Value="19"/>
     109        <CursorPos X="4" Y="36"/>
     110        <UsageCount Value="11"/>
     111        <Loaded Value="True"/>
    110112      </Unit6>
    111113      <Unit7>
     
    141143      <Unit11>
    142144        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericMatrix.inc"/>
    143         <WindowIndex Value="0"/>
    144         <TopLine Value="141"/>
    145         <CursorPos X="1" Y="158"/>
     145        <EditorIndex Value="1"/>
     146        <WindowIndex Value="0"/>
     147        <TopLine Value="157"/>
     148        <CursorPos X="44" Y="171"/>
    146149        <UsageCount Value="31"/>
     150        <Loaded Value="True"/>
    147151      </Unit11>
    148152      <Unit12>
     
    261265        <ResourceBaseClass Value="Form"/>
    262266        <UnitName Value="UMapForm"/>
    263         <EditorIndex Value="5"/>
     267        <EditorIndex Value="7"/>
    264268        <WindowIndex Value="0"/>
    265269        <TopLine Value="1"/>
    266270        <CursorPos X="20" Y="39"/>
    267         <UsageCount Value="56"/>
     271        <UsageCount Value="57"/>
    268272        <Loaded Value="True"/>
    269273      </Unit27>
     
    299303        <Filename Value="../../../lazarus/lcl/intfgraphics.pas"/>
    300304        <UnitName Value="IntfGraphics"/>
    301         <EditorIndex Value="4"/>
     305        <EditorIndex Value="6"/>
    302306        <WindowIndex Value="0"/>
    303307        <TopLine Value="3131"/>
    304308        <CursorPos X="42" Y="3148"/>
    305         <UsageCount Value="13"/>
     309        <UsageCount Value="14"/>
    306310        <Loaded Value="True"/>
    307311      </Unit32>
     
    331335      <Unit36>
    332336        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericBitmap.inc"/>
    333         <EditorIndex Value="2"/>
     337        <EditorIndex Value="4"/>
    334338        <WindowIndex Value="0"/>
    335339        <TopLine Value="25"/>
    336340        <CursorPos X="14" Y="25"/>
    337         <UsageCount Value="17"/>
     341        <UsageCount Value="18"/>
    338342        <Loaded Value="True"/>
    339343      </Unit36>
     
    396400        <IsPartOfProject Value="True"/>
    397401        <UnitName Value="UPlatform"/>
    398         <UsageCount Value="36"/>
     402        <UsageCount Value="37"/>
    399403      </Unit44>
    400404      <Unit45>
     
    424428      <Unit48>
    425429        <Filename Value="../../../lazarus/lcl/include/custombitmap.inc"/>
    426         <EditorIndex Value="3"/>
     430        <EditorIndex Value="5"/>
    427431        <WindowIndex Value="0"/>
    428432        <TopLine Value="330"/>
    429433        <CursorPos X="35" Y="338"/>
    430         <UsageCount Value="13"/>
     434        <UsageCount Value="14"/>
    431435        <Loaded Value="True"/>
    432436      </Unit48>
     
    443447        <IsPartOfProject Value="True"/>
    444448        <UnitName Value="URectangle"/>
    445         <EditorIndex Value="1"/>
     449        <EditorIndex Value="3"/>
    446450        <WindowIndex Value="0"/>
    447451        <TopLine Value="120"/>
    448452        <CursorPos X="44" Y="150"/>
    449         <UsageCount Value="21"/>
     453        <UsageCount Value="22"/>
    450454        <Loaded Value="True"/>
    451455      </Unit50>
    452456    </Units>
    453     <JumpHistory Count="30" HistoryIndex="29">
     457    <JumpHistory Count="30" HistoryIndex="28">
    454458      <Position1>
    455459        <Filename Value="UCore.pas"/>
    456         <Caret Line="466" Column="1" TopLine="452"/>
     460        <Caret Line="348" Column="1" TopLine="331"/>
    457461      </Position1>
    458462      <Position2>
    459463        <Filename Value="UCore.pas"/>
    460         <Caret Line="373" Column="19" TopLine="361"/>
     464        <Caret Line="349" Column="1" TopLine="331"/>
    461465      </Position2>
    462466      <Position3>
    463467        <Filename Value="UCore.pas"/>
    464         <Caret Line="561" Column="19" TopLine="551"/>
     468        <Caret Line="336" Column="35" TopLine="321"/>
    465469      </Position3>
    466470      <Position4>
    467471        <Filename Value="UCore.pas"/>
    468         <Caret Line="385" Column="82" TopLine="364"/>
     472        <Caret Line="334" Column="1" TopLine="321"/>
    469473      </Position4>
    470474      <Position5>
    471475        <Filename Value="UCore.pas"/>
    472         <Caret Line="386" Column="1" TopLine="371"/>
     476        <Caret Line="335" Column="1" TopLine="321"/>
    473477      </Position5>
    474478      <Position6>
    475479        <Filename Value="UCore.pas"/>
    476         <Caret Line="346" Column="38" TopLine="331"/>
     480        <Caret Line="336" Column="1" TopLine="321"/>
    477481      </Position6>
    478482      <Position7>
    479483        <Filename Value="UCore.pas"/>
    480         <Caret Line="352" Column="1" TopLine="331"/>
     484        <Caret Line="337" Column="1" TopLine="321"/>
    481485      </Position7>
    482486      <Position8>
    483487        <Filename Value="UCore.pas"/>
    484         <Caret Line="356" Column="1" TopLine="331"/>
     488        <Caret Line="338" Column="1" TopLine="321"/>
    485489      </Position8>
    486490      <Position9>
    487491        <Filename Value="UCore.pas"/>
    488         <Caret Line="352" Column="1" TopLine="331"/>
     492        <Caret Line="339" Column="1" TopLine="321"/>
    489493      </Position9>
    490494      <Position10>
    491495        <Filename Value="UCore.pas"/>
    492         <Caret Line="616" Column="1" TopLine="599"/>
     496        <Caret Line="340" Column="1" TopLine="321"/>
    493497      </Position10>
    494498      <Position11>
    495499        <Filename Value="UCore.pas"/>
    496         <Caret Line="617" Column="1" TopLine="599"/>
     500        <Caret Line="343" Column="1" TopLine="321"/>
    497501      </Position11>
    498502      <Position12>
    499503        <Filename Value="UCore.pas"/>
    500         <Caret Line="620" Column="1" TopLine="599"/>
     504        <Caret Line="344" Column="1" TopLine="321"/>
    501505      </Position12>
    502506      <Position13>
    503507        <Filename Value="UCore.pas"/>
    504         <Caret Line="352" Column="10" TopLine="335"/>
     508        <Caret Line="345" Column="1" TopLine="321"/>
    505509      </Position13>
    506510      <Position14>
    507511        <Filename Value="UCore.pas"/>
    508         <Caret Line="353" Column="14" TopLine="336"/>
     512        <Caret Line="346" Column="1" TopLine="321"/>
    509513      </Position14>
    510514      <Position15>
    511515        <Filename Value="UCore.pas"/>
    512         <Caret Line="356" Column="17" TopLine="339"/>
     516        <Caret Line="348" Column="1" TopLine="321"/>
    513517      </Position15>
    514518      <Position16>
    515519        <Filename Value="UCore.pas"/>
    516         <Caret Line="359" Column="22" TopLine="339"/>
     520        <Caret Line="349" Column="1" TopLine="321"/>
    517521      </Position16>
    518522      <Position17>
    519523        <Filename Value="UCore.pas"/>
    520         <Caret Line="358" Column="1" TopLine="333"/>
     524        <Caret Line="350" Column="1" TopLine="322"/>
    521525      </Position17>
    522526      <Position18>
    523527        <Filename Value="UCore.pas"/>
    524         <Caret Line="354" Column="1" TopLine="333"/>
     528        <Caret Line="351" Column="39" TopLine="324"/>
    525529      </Position18>
    526530      <Position19>
    527531        <Filename Value="UCore.pas"/>
    528         <Caret Line="355" Column="1" TopLine="333"/>
     532        <Caret Line="334" Column="1" TopLine="324"/>
    529533      </Position19>
    530534      <Position20>
    531535        <Filename Value="UCore.pas"/>
    532         <Caret Line="356" Column="1" TopLine="333"/>
     536        <Caret Line="378" Column="9" TopLine="364"/>
    533537      </Position20>
    534538      <Position21>
    535539        <Filename Value="UCore.pas"/>
    536         <Caret Line="357" Column="1" TopLine="333"/>
     540        <Caret Line="81" Column="20" TopLine="63"/>
    537541      </Position21>
    538542      <Position22>
    539543        <Filename Value="UCore.pas"/>
    540         <Caret Line="363" Column="1" TopLine="335"/>
     544        <Caret Line="394" Column="1" TopLine="362"/>
    541545      </Position22>
    542546      <Position23>
    543547        <Filename Value="UCore.pas"/>
    544         <Caret Line="353" Column="3" TopLine="343"/>
     548        <Caret Line="349" Column="14" TopLine="332"/>
    545549      </Position23>
    546550      <Position24>
    547551        <Filename Value="UCore.pas"/>
    548         <Caret Line="354" Column="1" TopLine="343"/>
     552        <Caret Line="741" Column="27" TopLine="735"/>
    549553      </Position24>
    550554      <Position25>
    551555        <Filename Value="UCore.pas"/>
    552         <Caret Line="355" Column="1" TopLine="343"/>
     556        <Caret Line="514" Column="32" TopLine="504"/>
    553557      </Position25>
    554558      <Position26>
    555559        <Filename Value="UCore.pas"/>
    556         <Caret Line="363" Column="1" TopLine="343"/>
     560        <Caret Line="344" Column="18" TopLine="328"/>
    557561      </Position26>
    558562      <Position27>
    559563        <Filename Value="UCore.pas"/>
    560         <Caret Line="364" Column="1" TopLine="343"/>
     564        <Caret Line="376" Column="22" TopLine="360"/>
    561565      </Position27>
    562566      <Position28>
    563567        <Filename Value="UCore.pas"/>
    564         <Caret Line="365" Column="1" TopLine="343"/>
     568        <Caret Line="528" Column="31" TopLine="518"/>
    565569      </Position28>
    566570      <Position29>
    567571        <Filename Value="UCore.pas"/>
    568         <Caret Line="382" Column="29" TopLine="333"/>
     572        <Caret Line="530" Column="26" TopLine="518"/>
    569573      </Position29>
    570574      <Position30>
    571575        <Filename Value="UCore.pas"/>
    572         <Caret Line="390" Column="1" TopLine="373"/>
     576        <Caret Line="15" Column="27" TopLine="1"/>
    573577      </Position30>
    574578    </JumpHistory>
Note: See TracChangeset for help on using the changeset viewer.