Changeset 2 for trunk/UCore.pas


Ignore:
Timestamp:
Mar 5, 2011, 10:16:19 PM (14 years ago)
Author:
george
Message:
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore set to
      tunneler
      lib
      backup
  • trunk/UCore.pas

    r1 r2  
    66
    77uses
    8   Classes, SysUtils, Contnrs, Graphics;
     8  Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix;
    99
    1010type
    1111  TEngine = class;
     12
     13  TSurfaceMatter = (smNothing, smDirt1, smDirt2, smRock1, smRock2, smHouse1, smHouse2);
    1214
    1315  TPlayerKeys = record
     
    3638  TWorld = class
    3739  private
    38     function GetSize: TPoint;
    39     procedure SetSize(const AValue: TPoint);
     40    function GetSize: TMatrixByteIndex;
     41    procedure SetSize(const AValue: TMatrixByteIndex);
    4042  public
    4143    Engine: TEngine;
    42     Surface: TBitmap;
     44    Surface: TMatrixByte;
    4345    procedure Generate;
    4446    constructor Create;
    4547    destructor Destroy; override;
    46     property Size: TPoint read GetSize write SetSize;
     48    property Size: TMatrixByteIndex read GetSize write SetSize;
    4749  end;
    4850
     
    6769  end;
    6870
     71const
     72  SurfaceMatterColors: array[TSurfaceMatter] of TColor = (clBlack, $0756b0, $2170c3, clGray, clGray + $808080, clGreen, clBlue);
     73
    6974var
    7075  Engine: TEngine;
     
    7479{ TWorld }
    7580
    76 function TWorld.GetSize: TPoint;
    77 begin
    78   Result := Point(Surface.Width, Surface.Height);
    79 end;
    80 
    81 procedure TWorld.SetSize(const AValue: TPoint);
    82 begin
    83   Surface.SetSize(AValue.X, AValue.Y);
     81function TWorld.GetSize: TMatrixByteIndex;
     82begin
     83  Result := Surface.Count;
     84end;
     85
     86procedure TWorld.SetSize(const AValue: TMatrixByteIndex);
     87begin
     88  Surface.Count := AValue;
    8489  Generate;
    8590end;
     
    8994  X, Y: Integer;
    9095begin
    91   for Y := 0 to Surface.Height - 1 do
    92     for X := 0 to Surface.Width - 1 do begin
     96  for Y := 0 to Surface.Count.Y - 1 do
     97    for X := 0 to Surface.Count.X - 1 do begin
    9398      if Random < 0.5 then
    94         Surface.Canvas.Pixels[X, Y] := TColor($0756b0) else
    95         Surface.Canvas.Pixels[X, Y] := TColor($2170c3);
     99        Surface[Y, X] := Byte(smDirt1) else
     100        Surface[Y, X] := Byte(smDirt2);
    96101    end;
    97102end;
    98103
    99104constructor TWorld.Create;
    100 begin
    101   Surface := TBitmap.Create;
    102   Surface.PixelFormat := pf4bit;
    103   Size := Point(500, 100);
     105var
     106  NewSize: TMatrixByteIndex;
     107begin
     108  Surface := TMatrixByte.Create;
     109  NewSize.X := 5000;
     110  NewSize.Y := 500;
     111  Size := NewSize;
    104112end;
    105113
     
    121129
    122130procedure TPlayer.Paint;
     131var
     132  X, Y: Integer;
     133  XX, YY: Integer;
    123134begin
    124135  with Engine.Bitmap.Canvas do begin
    125136    Rectangle(ScreenFrame);
    126     CopyRect(ScreenFrame, Engine.World.Surface.Canvas, Rect(
     137    //FillRect(ScreenFrame);
     138
     139    with Engine.World do
     140    for Y := ScreenFrame.Top to ScreenFrame.Bottom - 1 do
     141      for X := ScreenFrame.Left to ScreenFrame.Right - 1 do begin
     142        XX := X - ScreenFrame.Left - ((ScreenFrame.Right - ScreenFrame.Left) div 2) + Position.X;
     143        YY := Y - ScreenFrame.Top - ((ScreenFrame.Bottom - ScreenFrame.Top) div 2) + Position.Y;
     144        if (YY >= 0) and (YY < Surface.Count.Y) and (XX >= 0) and (XX < Surface.Count.X) then
     145          Pixels[X, Y] := SurfaceMatterColors[TSurfaceMatter(Surface[YY, XX])];
     146      end;
     147    (*CopyRect(ScreenFrame, Engine.World.Surface.Canvas,
     148    Rect(
    127149      Position.X - (ScreenFrame.Right - ScreenFrame.Left) div 2,
    128150      Position.Y - (ScreenFrame.Bottom - ScreenFrame.Top) div 2,
    129151      Position.X + (ScreenFrame.Right - ScreenFrame.Left) div 2,
    130       Position.Y + (ScreenFrame.Bottom - ScreenFrame.Top) div 2));
     152      Position.Y + (ScreenFrame.Bottom - ScreenFrame.Top) div 2));*)
    131153    TextOut(ScreenFrame.Left, ScreenFrame.Top, Name);
     154    //ShowMessage(IntToStr(ScreenFrame.Right - ScreenFrame.Left) + ' ' +
     155    //IntToStr(ScreenFrame.Bottom - ScreenFrame.Top));
    132156  end;
    133157end;
     
    189213begin
    190214  Players := TObjectList.Create;
    191   PlayerCount := 2;
    192   with TPlayer(Players[0]) do begin
    193     Position := Point(100, 100);
    194     Color := TColor($00f805);
    195     Keys.Left := 65;
    196     Keys.Up := 87;
    197     Keys.Right := 68;
    198     Keys.Down := 83;
    199     Keys.Shoot := 69;
    200   end;
    201   with TPlayer(Players[1]) do begin
    202     Position := Point(300, 200);
    203     Color := TColor($00f805);
    204     Keys.Left := 37;
    205     Keys.Up := 38;
    206     Keys.Right := 39;
    207     Keys.Down := 40;
    208     Keys.Shoot := 17;
    209   end;
    210215  World := TWorld.Create;
    211216  World.Engine := Self;
Note: See TracChangeset for help on using the changeset viewer.