Changeset 11 for trunk/UCore.pas
- Timestamp:
- Mar 20, 2011, 11:25:50 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r10 r11 7 7 uses 8 8 Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList, 9 IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math ;9 IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math, URectangle; 10 10 11 11 const 12 12 MaxBulletCount = 10; 13 EnergySteps = 4000; 14 ShieldSteps = 40; 13 15 14 16 type … … 57 59 Position: TPoint; 58 60 Direction: Integer; 59 ScreenFrame: TRect ;61 ScreenFrame: TRectangle; 60 62 Name: string; 61 63 Keys: TPlayerKeys; 62 64 Tanks: TListObject; 63 65 Bullets: TListObject; 66 Energy: Real; 67 LastEnergy: Real; 68 Shield: Real; 69 House: TRectangle; 70 procedure BlowUp; 64 71 procedure Control; 65 72 procedure Paint; … … 101 108 procedure SetPlayerCount(const AValue: Integer); 102 109 procedure Redraw; 110 function IsInsideHouses(Pos: TPoint): Boolean; 103 111 public 104 112 KeyState: array[0..High(Word)] of Boolean; … … 261 269 Surface.ItemsXY[Trunc(X / Bitmap.Width * Surface.Count.X), 262 270 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); 264 272 Inc(PByte(PixelPtr), BytePerPixel); 265 273 end; … … 342 350 Engine.Redraw; 343 351 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; 344 367 end; 345 368 … … 348 371 X, Y: Integer; 349 372 XX, YY: Integer; 373 I: Integer; 350 374 begin 351 375 with Engine.FBitmapLower do begin … … 363 387 ItemsXY[X, Y] := SurfaceMatterColors[TSurfaceMatter(Surface.ItemsXY[XX, YY])]; 364 388 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; 377 394 end; 378 395 end; … … 386 403 Matter: Byte; 387 404 begin 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); 388 407 for Y := 0 to HouseSize - 1 do 389 408 for X := 0 to HouseSize - 1 do begin … … 393 412 then Matter := Byte(smPlayer1H) + Id * 2 394 413 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; 397 416 end; 398 417 end; … … 441 460 end; 442 461 462 procedure TPlayer.BlowUp; 463 begin 464 465 end; 466 443 467 procedure TPlayer.HideTank; 444 468 begin … … 541 565 Tanks := TListObject.Create; 542 566 Bullets := TListObject.Create; 567 House := TRectangle.Create; 568 ScreenFrame := TRectangle.Create; 543 569 end; 544 570 545 571 destructor TPlayer.Destroy; 546 572 begin 573 ScreenFrame.Free; 574 House.Free; 547 575 Bullets.Free; 548 576 Tanks.Free; … … 590 618 end; 591 619 620 function TEngine.IsInsideHouses(Pos: TPoint): Boolean; 621 var 622 I: Integer; 623 begin 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; 629 end; 630 592 631 procedure TEngine.ResizePlayerFrames; 593 632 var … … 607 646 FBitmapLower.Count := FBitmapLower.CreateIndex(80 * HorizFrameCount, 60 * VertFrameCount); 608 647 for I := 0 to Players.Count - 1 do begin 609 TPlayer(Players[I]).ScreenFrame := Rect(648 TPlayer(Players[I]).ScreenFrame.AsTRect := Rect( 610 649 (I mod HorizFrameCount) * (FBitmapLower.Count.X div HorizFrameCount), 611 650 (I div HorizFrameCount) * (FBitmapLower.Count.Y div VertFrameCount), … … 754 793 Round(World.Surface.Count.Y * 0.2) + Random(Round(World.Surface.Count.Y * 0.6))); 755 794 795 Energy := 1; 796 Shield := 1; 756 797 PlaceHouse; 757 798 end;
Note:
See TracChangeset
for help on using the changeset viewer.