Changeset 2 for trunk/UCore.pas
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:ignore
set to
tunneler
lib
backup
-
Property svn:ignore
set to
-
trunk/UCore.pas
r1 r2 6 6 7 7 uses 8 Classes, SysUtils, Contnrs, Graphics;8 Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix; 9 9 10 10 type 11 11 TEngine = class; 12 13 TSurfaceMatter = (smNothing, smDirt1, smDirt2, smRock1, smRock2, smHouse1, smHouse2); 12 14 13 15 TPlayerKeys = record … … 36 38 TWorld = class 37 39 private 38 function GetSize: T Point;39 procedure SetSize(const AValue: T Point);40 function GetSize: TMatrixByteIndex; 41 procedure SetSize(const AValue: TMatrixByteIndex); 40 42 public 41 43 Engine: TEngine; 42 Surface: T Bitmap;44 Surface: TMatrixByte; 43 45 procedure Generate; 44 46 constructor Create; 45 47 destructor Destroy; override; 46 property Size: T Pointread GetSize write SetSize;48 property Size: TMatrixByteIndex read GetSize write SetSize; 47 49 end; 48 50 … … 67 69 end; 68 70 71 const 72 SurfaceMatterColors: array[TSurfaceMatter] of TColor = (clBlack, $0756b0, $2170c3, clGray, clGray + $808080, clGreen, clBlue); 73 69 74 var 70 75 Engine: TEngine; … … 74 79 { TWorld } 75 80 76 function TWorld.GetSize: T Point;77 begin 78 Result := Point(Surface.Width, Surface.Height);79 end; 80 81 procedure TWorld.SetSize(const AValue: T Point);82 begin 83 Surface. SetSize(AValue.X, AValue.Y);81 function TWorld.GetSize: TMatrixByteIndex; 82 begin 83 Result := Surface.Count; 84 end; 85 86 procedure TWorld.SetSize(const AValue: TMatrixByteIndex); 87 begin 88 Surface.Count := AValue; 84 89 Generate; 85 90 end; … … 89 94 X, Y: Integer; 90 95 begin 91 for Y := 0 to Surface. Height- 1 do92 for X := 0 to Surface. Width- 1 do begin96 for Y := 0 to Surface.Count.Y - 1 do 97 for X := 0 to Surface.Count.X - 1 do begin 93 98 if Random < 0.5 then 94 Surface .Canvas.Pixels[X, Y] := TColor($0756b0) else95 Surface .Canvas.Pixels[X, Y] := TColor($2170c3);99 Surface[Y, X] := Byte(smDirt1) else 100 Surface[Y, X] := Byte(smDirt2); 96 101 end; 97 102 end; 98 103 99 104 constructor TWorld.Create; 100 begin 101 Surface := TBitmap.Create; 102 Surface.PixelFormat := pf4bit; 103 Size := Point(500, 100); 105 var 106 NewSize: TMatrixByteIndex; 107 begin 108 Surface := TMatrixByte.Create; 109 NewSize.X := 5000; 110 NewSize.Y := 500; 111 Size := NewSize; 104 112 end; 105 113 … … 121 129 122 130 procedure TPlayer.Paint; 131 var 132 X, Y: Integer; 133 XX, YY: Integer; 123 134 begin 124 135 with Engine.Bitmap.Canvas do begin 125 136 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( 127 149 Position.X - (ScreenFrame.Right - ScreenFrame.Left) div 2, 128 150 Position.Y - (ScreenFrame.Bottom - ScreenFrame.Top) div 2, 129 151 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));*) 131 153 TextOut(ScreenFrame.Left, ScreenFrame.Top, Name); 154 //ShowMessage(IntToStr(ScreenFrame.Right - ScreenFrame.Left) + ' ' + 155 //IntToStr(ScreenFrame.Bottom - ScreenFrame.Top)); 132 156 end; 133 157 end; … … 189 213 begin 190 214 Players := TObjectList.Create; 191 PlayerCount := 2;192 with TPlayer(Players[0]) do begin193 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 begin202 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;210 215 World := TWorld.Create; 211 216 World.Engine := Self;
Note:
See TracChangeset
for help on using the changeset viewer.