Changeset 7 for trunk/UCore.pas
- Timestamp:
- Mar 12, 2011, 7:27:23 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r6 r7 6 6 7 7 uses 8 Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList; 8 Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList, 9 IntfGraphics, FPImage, LCLType, SpecializedBitmap; 9 10 10 11 const … … 94 95 FBitmap: TBitmap; 95 96 FRedrawPending: Boolean; 96 FBitmapLower: TBitmap ;97 FBitmapLower: TBitmapTColor; 97 98 function GetPlayerCount: Integer; 98 99 procedure SetBitmap(const AValue: TBitmap); … … 164 165 for X := 0 to Surface.Count.X - 1 do begin 165 166 if Random < 0.5 then 166 Surface.ItemsXY[ Y, X] := Byte(smDirt1) else167 Surface.ItemsXY[ Y, X] := Byte(smDirt2);167 Surface.ItemsXY[X, Y] := Byte(smDirt1) else 168 Surface.ItemsXY[X, Y] := Byte(smDirt2); 168 169 end; 169 170 … … 172 173 for Y := 0 to Surface.Count.Y - 1 do begin 173 174 for X := 0 to Round(Distance) - 1 do begin 174 Surface.ItemsXY[ Y, X] := Byte(smRock);175 Surface.ItemsXY[X, Y] := Byte(smRock); 175 176 end; 176 177 Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.X) * 2 - 1); … … 182 183 for Y := 0 to Surface.Count.Y - 1 do begin 183 184 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); 185 186 end; 186 187 Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.X) * 2 - 1); … … 192 193 for X := 0 to Surface.Count.X - 1 do begin 193 194 for Y := 0 to Round(Distance) - 1 do begin 194 Surface.ItemsXY[ Y, X] := Byte(smRock);195 Surface.ItemsXY[X, Y] := Byte(smRock); 195 196 end; 196 197 Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.Y) * 2 - 1); … … 202 203 for X := 0 to Surface.Count.X - 1 do begin 203 204 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); 205 206 end; 206 207 Delta := (Random * 2 - 1) * 3 - (Distance / (0.1 * Surface.Count.Y) * 2 - 1); … … 234 235 for X := 0 to Bitmap.Width - 1 do 235 236 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)])]; 238 239 finally 239 240 Bitmap.EndUpdate; … … 294 295 for I := Bullets.Count - 1 downto 0 do 295 296 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); 297 298 298 299 Position.X := Position.X + DirectionToDelta[Direction].X; 299 300 Position.Y := Position.Y + DirectionToDelta[Direction].Y; 300 301 301 if Engine.World.Surface.ItemsXY[Position. Y, Position.X] <> Byte(smNothing) then begin302 if (Engine.World.Surface.ItemsXY[Position. Y, Position.X] = Byte(smDirt1)) or303 (Engine.World.Surface.ItemsXY[Position. Y, Position.X] = Byte(smDirt2)) then304 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); 305 306 Bullets.Delete(I); 306 307 end else … … 309 310 (Position.Y >= Count.Y) or (Position.Y < 0) then 310 311 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); 312 313 Engine.Redraw; 313 314 end; … … 319 320 XX, YY: Integer; 320 321 begin 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]); 324 327 325 328 with Engine.World do … … 329 332 YY := Y - ScreenFrame.Top - ((ScreenFrame.Bottom - ScreenFrame.Top) div 2) + Position.Y; 330 333 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])]; 332 335 end; 333 Pen.Color := clBlack;334 Frame(ScreenFrame);336 //Pen.Color := clBlack; 337 //Frame(ScreenFrame); 335 338 336 339 (*CopyRect(ScreenFrame, Engine.World.Surface.Canvas, … … 361 364 then Matter := Byte(smPlayer1H) + Id * 2 362 365 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; 364 368 end; 365 369 end; … … 376 380 XX := X + NewPosition.X - Image.Count.X div 2; 377 381 YY := Y + NewPosition.Y - Image.Count.Y div 2; 378 if (Image.ItemsXY[ Y, X] > 0) and379 (Surface.ItemsXY[ YY, XX] <> Byte(smNothing)) then382 if (Image.ItemsXY[X, Y] > 0) and 383 (Surface.ItemsXY[XX, YY] <> Byte(smNothing)) then 380 384 begin 381 385 Result := smDirt1; 382 if (Surface.ItemsXY[ YY, XX] <> Byte(smDirt1)) and383 (Surface.ItemsXY[ YY, XX] <> Byte(smDirt2)) then386 if (Surface.ItemsXY[XX, YY] <> Byte(smDirt1)) and 387 (Surface.ItemsXY[XX, YY] <> Byte(smDirt2)) then 384 388 begin 385 Result := TSurfaceMatter(Surface.ItemsXY[ YY, XX]);389 Result := TSurfaceMatter(Surface.ItemsXY[XX, YY]); 386 390 Exit; 387 391 end; … … 428 432 Image.Count := Image.CreateIndex(7, 7); 429 433 for I := 0 to 3 do 430 Image[ I, 3] := Byte(smCannon);434 Image[3, I] := Byte(smCannon); 431 435 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; 434 438 end; 435 439 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; 441 445 end; 442 446 Tanks.Add(NewTank); … … 446 450 Image.Count := Image.CreateIndex(7, 7); 447 451 for I := 0 to 2 do 448 Image[3 - I, 3 +I] := Byte(smCannon);452 Image[3 + I, 3 - I] := Byte(smCannon); 449 453 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; 452 456 end; 453 457 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; 457 462 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; 460 465 Image[4, 3] := Byte(smPlayer1H) + Id * 2 + 1; 461 Image[3, 4] := Byte(smPlayer1H) + Id * 2 + 1;462 466 end; 463 467 Tanks.Add(NewTank); … … 572 576 HorizFrameCount := 1; 573 577 end; 574 FBitmapLower. SetSize(80 * HorizFrameCount, 60 * VertFrameCount);578 FBitmapLower.Count := FBitmapLower.CreateIndex(80 * HorizFrameCount, 60 * VertFrameCount); 575 579 for I := 0 to Players.Count - 1 do begin 576 580 TPlayer(Players[I]).ScreenFrame := Rect( 577 (I mod HorizFrameCount) * (FBitmapLower. Widthdiv HorizFrameCount),578 (I div HorizFrameCount) * (FBitmapLower. Heightdiv VertFrameCount),581 (I mod HorizFrameCount) * (FBitmapLower.Count.X div HorizFrameCount), 582 (I div HorizFrameCount) * (FBitmapLower.Count.Y div VertFrameCount), 579 583 ((I mod HorizFrameCount) + 1) * (FBitmapLower.Width div HorizFrameCount), 580 584 ((I div HorizFrameCount) + 1) * (FBitmapLower.Height div VertFrameCount)); … … 586 590 constructor TEngine.Create; 587 591 begin 588 FBitmapLower := TBitmap .Create;592 FBitmapLower := TBitmapTColor.Create; 589 593 Players := TObjectList.Create; 590 594 World := TWorld.Create; … … 612 616 procedure TEngine.Draw; 613 617 var 618 IntfImage: TLazIntfImage; 614 619 I: Integer; 620 X, Y: Integer; 621 H, W: Integer; 622 Ratio: Single; 615 623 begin 616 624 if FRedrawPending then begin 617 FBitmapLower. Canvas.FillRect(0, 0, FBitmapLower.Width, FBitmapLower.Height);625 FBitmapLower.FillAll(0); 618 626 for I := 0 to Players.Count - 1 do begin 619 627 TPlayer(Players[I]).Paint; 620 628 end; 621 629 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; 623 643 end; 624 644 FRedrawPending := False;
Note:
See TracChangeset
for help on using the changeset viewer.