Changeset 7 for trunk/UCore.pas


Ignore:
Timestamp:
Mar 12, 2011, 7:27:23 PM (14 years ago)
Author:
george
Message:
  • Modified: Used custom resize function with use of TLazIntfImage.
  • Modified: Internal drawing uses class TBitmapTColor specialized from TGBitmap.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r6 r7  
    66
    77uses
    8   Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList;
     8  Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList,
     9  IntfGraphics, FPImage, LCLType, SpecializedBitmap;
    910
    1011const
     
    9495    FBitmap: TBitmap;
    9596    FRedrawPending: Boolean;
    96     FBitmapLower: TBitmap;
     97    FBitmapLower: TBitmapTColor;
    9798    function GetPlayerCount: Integer;
    9899    procedure SetBitmap(const AValue: TBitmap);
     
    164165    for X := 0 to Surface.Count.X - 1 do begin
    165166      if Random < 0.5 then
    166         Surface.ItemsXY[Y, X] := Byte(smDirt1) else
    167         Surface.ItemsXY[Y, X] := Byte(smDirt2);
     167        Surface.ItemsXY[X, Y] := Byte(smDirt1) else
     168        Surface.ItemsXY[X, Y] := Byte(smDirt2);
    168169    end;
    169170
     
    172173  for Y := 0 to Surface.Count.Y - 1 do begin
    173174    for X := 0 to Round(Distance) - 1 do begin
    174       Surface.ItemsXY[Y, X] := Byte(smRock);
     175      Surface.ItemsXY[X, Y] := Byte(smRock);
    175176    end;
    176177    Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.X) * 2 - 1);
     
    182183  for Y := 0 to Surface.Count.Y - 1 do begin
    183184    for X := 0 to Round(Distance) - 1 do begin
    184       Surface.ItemsXY[Y, Surface.Count.X - 1 - X] := Byte(smRock);
     185      Surface.ItemsXY[Surface.Count.X - 1 - X, Y] := Byte(smRock);
    185186    end;
    186187    Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.X) * 2 - 1);
     
    192193  for X := 0 to Surface.Count.X - 1 do begin
    193194    for Y := 0 to Round(Distance) - 1 do begin
    194       Surface.ItemsXY[Y, X] := Byte(smRock);
     195      Surface.ItemsXY[X, Y] := Byte(smRock);
    195196    end;
    196197    Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.Y) * 2 - 1);
     
    202203  for X := 0 to Surface.Count.X - 1 do begin
    203204    for Y := 0 to Round(Distance) - 1 do begin
    204       Surface.ItemsXY[Surface.Count.Y - 1 - Y, X] := Byte(smRock);
     205      Surface.ItemsXY[X, Surface.Count.Y - 1 - Y] := Byte(smRock);
    205206    end;
    206207    Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.Y) * 2 - 1);
     
    234235    for X := 0 to Bitmap.Width - 1 do
    235236      Bitmap.Canvas.Pixels[X, Y] := SurfaceMatterColors[TSurfaceMatter(
    236         Surface.ItemsXY[Trunc(Y / Bitmap.Height * Surface.Count.Y),
    237         Trunc(X / Bitmap.Width * Surface.Count.X)])];
     237        Surface.ItemsXY[Trunc(X / Bitmap.Width * Surface.Count.X),
     238          Trunc(Y / Bitmap.Height * Surface.Count.Y)])];
    238239  finally
    239240    Bitmap.EndUpdate;
     
    294295  for I := Bullets.Count - 1 downto 0 do
    295296  with TBullet(Bullets[I]) do begin
    296     Engine.World.Surface.ItemsXY[Position.Y, Position.X] := Byte(smNothing);
     297    Engine.World.Surface.ItemsXY[Position.X, Position.Y] := Byte(smNothing);
    297298
    298299    Position.X := Position.X + DirectionToDelta[Direction].X;
    299300    Position.Y := Position.Y + DirectionToDelta[Direction].Y;
    300301
    301     if Engine.World.Surface.ItemsXY[Position.Y, Position.X] <> Byte(smNothing) then begin
    302       if (Engine.World.Surface.ItemsXY[Position.Y, Position.X] = Byte(smDirt1)) or
    303         (Engine.World.Surface.ItemsXY[Position.Y, Position.X] = Byte(smDirt2)) then
    304           Engine.World.Surface.ItemsXY[Position.Y, Position.X] := Byte(smNothing);
     302    if Engine.World.Surface.ItemsXY[Position.X, Position.Y] <> Byte(smNothing) then begin
     303      if (Engine.World.Surface.ItemsXY[Position.X, Position.Y] = Byte(smDirt1)) or
     304        (Engine.World.Surface.ItemsXY[Position.X, Position.Y] = Byte(smDirt2)) then
     305          Engine.World.Surface.ItemsXY[Position.X, Position.Y] := Byte(smNothing);
    305306      Bullets.Delete(I);
    306307    end else
     
    309310      (Position.Y >= Count.Y) or (Position.Y < 0) then
    310311      Bullets.Delete(I) else
    311       Engine.World.Surface.ItemsXY[Position.Y, Position.X] := Byte(smBullet);
     312      Engine.World.Surface.ItemsXY[Position.X, Position.Y] := Byte(smBullet);
    312313    Engine.Redraw;
    313314  end;
     
    319320  XX, YY: Integer;
    320321begin
    321   with Engine.FBitmapLower.Canvas do begin
    322     Brush.Color := SurfaceMatterColors[smRock];
    323     FillRect(ScreenFrame);
     322  with Engine.FBitmapLower do begin
     323//    Brush.Color := SurfaceMatterColors[smRock];
     324//    FillRect(ScreenFrame);
     325    Fill(CreateIndex(ScreenFrame.Left, ScreenFrame.Top),
     326      CreateIndex(ScreenFrame.Right - 1, ScreenFrame.Bottom - 1), SurfaceMatterColors[smRock]);
    324327
    325328    with Engine.World do
     
    329332        YY := Y - ScreenFrame.Top - ((ScreenFrame.Bottom - ScreenFrame.Top) div 2) + Position.Y;
    330333        if (YY >= 0) and (YY < Surface.Count.Y) and (XX >= 0) and (XX < Surface.Count.X) then
    331           Pixels[X, Y] := SurfaceMatterColors[TSurfaceMatter(Surface.ItemsXY[YY, XX])];
     334          ItemsXY[X, Y] := SurfaceMatterColors[TSurfaceMatter(Surface.ItemsXY[XX, YY])];
    332335      end;
    333     Pen.Color := clBlack;
    334     Frame(ScreenFrame);
     336    //Pen.Color := clBlack;
     337    //Frame(ScreenFrame);
    335338
    336339    (*CopyRect(ScreenFrame, Engine.World.Surface.Canvas,
     
    361364      then Matter := Byte(smPlayer1H) + Id * 2
    362365        else Matter := Byte(smNothing);
    363       Engine.World.Surface.ItemsXY[Position.Y - HouseSize div 2 + Y, Position.X - HouseSize div 2 + X] := Matter;
     366      Engine.World.Surface.ItemsXY[Position.X - HouseSize div 2 + X,
     367        Position.Y - HouseSize div 2 + Y] := Matter;
    364368    end;
    365369end;
     
    376380    XX := X + NewPosition.X - Image.Count.X div 2;
    377381    YY := Y + NewPosition.Y - Image.Count.Y div 2;
    378     if (Image.ItemsXY[Y, X] > 0) and
    379     (Surface.ItemsXY[YY, XX] <> Byte(smNothing)) then
     382    if (Image.ItemsXY[X, Y] > 0) and
     383    (Surface.ItemsXY[XX, YY] <> Byte(smNothing)) then
    380384    begin
    381385      Result := smDirt1;
    382       if (Surface.ItemsXY[YY, XX] <> Byte(smDirt1)) and
    383       (Surface.ItemsXY[YY, XX] <> Byte(smDirt2)) then
     386      if (Surface.ItemsXY[XX, YY] <> Byte(smDirt1)) and
     387      (Surface.ItemsXY[XX, YY] <> Byte(smDirt2)) then
    384388      begin
    385         Result := TSurfaceMatter(Surface.ItemsXY[YY, XX]);
     389        Result := TSurfaceMatter(Surface.ItemsXY[XX, YY]);
    386390        Exit;
    387391      end;
     
    428432    Image.Count := Image.CreateIndex(7, 7);
    429433    for I := 0 to 3 do
    430       Image[I, 3] := Byte(smCannon);
     434      Image[3, I] := Byte(smCannon);
    431435    for I := 1 to 6 do begin
    432       Image[I, 1] := Byte(smPlayer1H) + Id * 2;
    433       Image[I, 5] := Byte(smPlayer1H) + Id * 2;
     436      Image[1, I] := Byte(smPlayer1H) + Id * 2;
     437      Image[5, I] := Byte(smPlayer1H) + Id * 2;
    434438    end;
    435439    for I := 2 to 5 do begin
    436       Image[I, 2] := Byte(smPlayer1H) + Id * 2 + 1;
    437       Image[I, 4] := Byte(smPlayer1H) + Id * 2 + 1;
    438     end;
    439     Image[4, 3] := Byte(smPlayer1H) + Id * 2 + 1;
    440     Image[5, 3] := Byte(smPlayer1H) + Id * 2 + 1;
     440      Image[2, I] := Byte(smPlayer1H) + Id * 2 + 1;
     441      Image[4, I] := Byte(smPlayer1H) + Id * 2 + 1;
     442    end;
     443    Image[3, 4] := Byte(smPlayer1H) + Id * 2 + 1;
     444    Image[3, 5] := Byte(smPlayer1H) + Id * 2 + 1;
    441445  end;
    442446  Tanks.Add(NewTank);
     
    446450    Image.Count := Image.CreateIndex(7, 7);
    447451    for I := 0 to 2 do
    448       Image[3 - I, 3 + I] := Byte(smCannon);
     452      Image[3 + I, 3 - I] := Byte(smCannon);
    449453    for I := 0 to 3 do begin
    450       Image[3 - I, I] := Byte(smPlayer1H) + Id * 2;
    451       Image[6 - I, 3 + I] := Byte(smPlayer1H) + Id * 2;
     454      Image[I, 3 - I] := Byte(smPlayer1H) + Id * 2;
     455      Image[3 + I, 6 - I] := Byte(smPlayer1H) + Id * 2;
    452456    end;
    453457    for I := 0 to 2 do begin
    454       Image[3 - I, 1 + I] := Byte(smPlayer1H) + Id * 2 + 1;
    455       Image[5 - I, 3 + I] := Byte(smPlayer1H) + Id * 2 + 1;
    456     end;
     458      Image[1 + I, 3 - I] := Byte(smPlayer1H) + Id * 2 + 1;
     459      Image[3 + I, 5 - I] := Byte(smPlayer1H) + Id * 2 + 1;
     460    end;
     461    Image[3, 2] := Byte(smPlayer1H) + Id * 2 + 1;
    457462    Image[2, 3] := Byte(smPlayer1H) + Id * 2 + 1;
    458     Image[3, 2] := Byte(smPlayer1H) + Id * 2 + 1;
    459     Image[4, 2] := Byte(smPlayer1H) + Id * 2 + 1;
     463    Image[2, 4] := Byte(smPlayer1H) + Id * 2 + 1;
     464    Image[3, 4] := Byte(smPlayer1H) + Id * 2 + 1;
    460465    Image[4, 3] := Byte(smPlayer1H) + Id * 2 + 1;
    461     Image[3, 4] := Byte(smPlayer1H) + Id * 2 + 1;
    462466  end;
    463467  Tanks.Add(NewTank);
     
    572576      HorizFrameCount := 1;
    573577    end;
    574     FBitmapLower.SetSize(80 * HorizFrameCount, 60 * VertFrameCount);
     578    FBitmapLower.Count := FBitmapLower.CreateIndex(80 * HorizFrameCount, 60 * VertFrameCount);
    575579    for I := 0 to Players.Count - 1 do begin
    576580      TPlayer(Players[I]).ScreenFrame := Rect(
    577         (I mod HorizFrameCount) * (FBitmapLower.Width div HorizFrameCount),
    578         (I div HorizFrameCount) * (FBitmapLower.Height div VertFrameCount),
     581        (I mod HorizFrameCount) * (FBitmapLower.Count.X div HorizFrameCount),
     582        (I div HorizFrameCount) * (FBitmapLower.Count.Y div VertFrameCount),
    579583        ((I mod HorizFrameCount) + 1) * (FBitmapLower.Width div HorizFrameCount),
    580584        ((I div HorizFrameCount) + 1) * (FBitmapLower.Height div VertFrameCount));
     
    586590constructor TEngine.Create;
    587591begin
    588   FBitmapLower := TBitmap.Create;
     592  FBitmapLower := TBitmapTColor.Create;
    589593  Players := TObjectList.Create;
    590594  World := TWorld.Create;
     
    612616procedure TEngine.Draw;
    613617var
     618  IntfImage: TLazIntfImage;
    614619  I: Integer;
     620  X, Y: Integer;
     621  H, W: Integer;
     622  Ratio: Single;
    615623begin
    616624  if FRedrawPending then begin
    617     FBitmapLower.Canvas.FillRect(0, 0, FBitmapLower.Width, FBitmapLower.Height);
     625    FBitmapLower.FillAll(0);
    618626    for I := 0 to Players.Count - 1 do begin
    619627      TPlayer(Players[I]).Paint;
    620628    end;
    621629    if Assigned(FBitmap) then begin
    622       FBitmap.Canvas.StretchDraw(Rect(0, 0, FBitmap.Width, FBitmap.Height), FBitmapLower);
     630      //FBitmap.Canvas.StretchDraw(Rect(0, 0, FBitmap.Width, FBitmap.Height), FBitmapLower);
     631      try
     632        IntfImage := FBitmap.CreateIntfImage;
     633        if (FBitmap.Width / FBitmapLower.Width) < (FBitmap.Height / FBitmapLower.Height) then
     634          Ratio := FBitmap.Width / FBitmapLower.Width
     635          else Ratio := FBitmap.Height / FBitmapLower.Height;
     636        for Y := 0 to Trunc(FBitmapLower.Height * Ratio) - 1 do
     637          for X := 0 to Trunc(FBitmapLower.Width * Ratio) - 1 do
     638            IntfImage.Colors[X, Y] := TColorToFPColor(FBitmapLower.Pixels[Trunc(X / Ratio), Trunc(Y / Ratio)]);
     639        FBitmap.LoadFromIntfImage(IntfImage);
     640      finally
     641        IntfImage.Free;
     642      end;
    623643    end;
    624644    FRedrawPending := False;
Note: See TracChangeset for help on using the changeset viewer.