Changeset 11 for trunk/UCore.pas


Ignore:
Timestamp:
Mar 20, 2011, 11:25:50 PM (14 years ago)
Author:
george
Message:
  • Added: Decreasing and increasing tank energy.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r10 r11  
    77uses
    88  Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList,
    9   IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math;
     9  IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math, URectangle;
    1010
    1111const
    1212  MaxBulletCount = 10;
     13  EnergySteps = 4000;
     14  ShieldSteps = 40;
    1315
    1416type
     
    5759    Position: TPoint;
    5860    Direction: Integer;
    59     ScreenFrame: TRect;
     61    ScreenFrame: TRectangle;
    6062    Name: string;
    6163    Keys: TPlayerKeys;
    6264    Tanks: TListObject;
    6365    Bullets: TListObject;
     66    Energy: Real;
     67    LastEnergy: Real;
     68    Shield: Real;
     69    House: TRectangle;
     70    procedure BlowUp;
    6471    procedure Control;
    6572    procedure Paint;
     
    101108    procedure SetPlayerCount(const AValue: Integer);
    102109    procedure Redraw;
     110    function IsInsideHouses(Pos: TPoint): Boolean;
    103111  public
    104112    KeyState: array[0..High(Word)] of Boolean;
     
    261269          Surface.ItemsXY[Trunc(X / Bitmap.Width * Surface.Count.X),
    262270            Trunc(Y / Bitmap.Height * Surface.Count.Y)])];
    263         PixelPtr^ := ((P and $ff) shl 16) or (P and $00ff00) or ((P shr 16) and $ff);
     271        PixelPtr^ := SwapBRComponent(P);
    264272        Inc(PByte(PixelPtr), BytePerPixel);
    265273      end;
     
    342350    Engine.Redraw;
    343351  end;
     352
     353  if not Engine.IsInsideHouses(Position) then begin
     354    Energy := Energy - 1 / EnergySteps;
     355    if Energy <= 0 then begin
     356      Energy := 0;
     357      BlowUp;
     358    end;
     359  end else begin
     360    Energy := Energy + 5 * 1 / EnergySteps;
     361    if Energy > 1 then Energy := 1;
     362  end;
     363  if LastEnergy <> Energy then begin
     364    LastEnergy := Energy;
     365    Engine.Redraw;
     366  end;
    344367end;
    345368
     
    348371  X, Y: Integer;
    349372  XX, YY: Integer;
     373  I: Integer;
    350374begin
    351375  with Engine.FBitmapLower do begin
     
    363387          ItemsXY[X, Y] := SurfaceMatterColors[TSurfaceMatter(Surface.ItemsXY[XX, YY])];
    364388      end;
    365     //Pen.Color := clBlack;
    366     //Frame(ScreenFrame);
    367 
    368     (*CopyRect(ScreenFrame, Engine.World.Surface.Canvas,
    369     Rect(
    370       Position.X - (ScreenFrame.Right - ScreenFrame.Left) div 2,
    371       Position.Y - (ScreenFrame.Bottom - ScreenFrame.Top) div 2,
    372       Position.X + (ScreenFrame.Right - ScreenFrame.Left) div 2,
    373       Position.Y + (ScreenFrame.Bottom - ScreenFrame.Top) div 2));*)
    374     //TextOut(ScreenFrame.Left, ScreenFrame.Top, Name);
    375     //ShowMessage(IntToStr(ScreenFrame.Right - ScreenFrame.Left) + ' ' +
    376     //IntToStr(ScreenFrame.Bottom - ScreenFrame.Top));
     389
     390    for I := 1 to ScreenFrame.Width - 2 do
     391      if Energy < I / (ScreenFrame.Width - 2) then
     392        ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := clBlack
     393        else ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := clYellow;
    377394  end;
    378395end;
     
    386403  Matter: Byte;
    387404begin
     405  House.AsTRect := Rect(Position.X - HouseSize div 2, Position.Y - HouseSize div 2,
     406    Position.X + HouseSize div 2, Position.Y + HouseSize div 2);
    388407  for Y := 0 to HouseSize - 1 do
    389408    for X := 0 to HouseSize - 1 do begin
     
    393412      then Matter := Byte(smPlayer1H) + Id * 2
    394413        else Matter := Byte(smNothing);
    395       Engine.World.Surface.ItemsXY[Position.X - HouseSize div 2 + X,
    396         Position.Y - HouseSize div 2 + Y] := Matter;
     414      Engine.World.Surface.ItemsXY[House.Left + X,
     415        House.Top + Y] := Matter;
    397416    end;
    398417end;
     
    441460end;
    442461
     462procedure TPlayer.BlowUp;
     463begin
     464
     465end;
     466
    443467procedure TPlayer.HideTank;
    444468begin
     
    541565  Tanks := TListObject.Create;
    542566  Bullets := TListObject.Create;
     567  House := TRectangle.Create;
     568  ScreenFrame := TRectangle.Create;
    543569end;
    544570
    545571destructor TPlayer.Destroy;
    546572begin
     573  ScreenFrame.Free;
     574  House.Free;
    547575  Bullets.Free;
    548576  Tanks.Free;
     
    590618end;
    591619
     620function TEngine.IsInsideHouses(Pos: TPoint): Boolean;
     621var
     622  I: Integer;
     623begin
     624  Result := False;
     625  for I := 0 to Players.Count - 1 do
     626    if TPlayer(Players[I]).House.IsInside(Pos) then begin
     627      Result := True;
     628    end;
     629end;
     630
    592631procedure TEngine.ResizePlayerFrames;
    593632var
     
    607646    FBitmapLower.Count := FBitmapLower.CreateIndex(80 * HorizFrameCount, 60 * VertFrameCount);
    608647    for I := 0 to Players.Count - 1 do begin
    609       TPlayer(Players[I]).ScreenFrame := Rect(
     648      TPlayer(Players[I]).ScreenFrame.AsTRect := Rect(
    610649        (I mod HorizFrameCount) * (FBitmapLower.Count.X div HorizFrameCount),
    611650        (I div HorizFrameCount) * (FBitmapLower.Count.Y div VertFrameCount),
     
    754793      Round(World.Surface.Count.Y * 0.2) + Random(Round(World.Surface.Count.Y * 0.6)));
    755794
     795    Energy := 1;
     796    Shield := 1;
    756797    PlaceHouse;
    757798  end;
Note: See TracChangeset for help on using the changeset viewer.