Changeset 12 for trunk/UCore.pas
- Timestamp:
- Mar 21, 2011, 10:13:45 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r11 r12 11 11 const 12 12 MaxBulletCount = 10; 13 EnergySteps = 40 00;13 EnergySteps = 40; 14 14 ShieldSteps = 40; 15 ExplosionBulletCount = 200; 16 ExplosionRange = 15; 15 17 16 18 type … … 21 23 smPlayer1H, smPlayer1L, smPlayer2H, smPlayer2L, 22 24 smPlayer3H, smPlayer3L, smPlayer4H, smPlayer4L); 25 26 TRealPoint = record 27 X, Y: Real; 28 end; 23 29 24 30 TPlayerKeys = record … … 32 38 TBullet = class 33 39 Player: TPlayer; 34 Position: TPoint; 35 Direction: Integer; 40 Position: TRealPoint; 41 Direction: TRealPoint; 42 MaxDistance: Integer; 43 Distance: Real; 44 StopByDirt: Boolean; 36 45 end; 37 46 … … 68 77 Shield: Real; 69 78 House: TRectangle; 70 procedure BlowUp; 79 Exploded: Boolean; 80 procedure Init; 81 procedure Explosion; 71 82 procedure Control; 83 procedure Tick; 72 84 procedure Paint; 73 85 procedure PlaceHouse; … … 287 299 NewBullet: TBullet; 288 300 I: Integer; 289 begin 301 Pos: TPoint; 302 begin 303 if Exploded then Exit; 304 290 305 Delta.X := 0; 291 306 Delta.Y := 0; … … 324 339 NewBullet := TBullet.Create; 325 340 NewBullet.Player := Self; 326 NewBullet.Position := Point(Position.X + DirectionToDelta[Direction].X * 4, 327 Position.Y + DirectionToDelta[Direction].Y * 4); 328 NewBullet.Direction := Direction; 341 NewBullet.Position.X := Position.X + DirectionToDelta[Direction].X * 4; 342 NewBullet.Position.Y := Position.Y + DirectionToDelta[Direction].Y * 4; 343 NewBullet.Direction.X := DirectionToDelta[Direction].X; 344 NewBullet.Direction.Y := DirectionToDelta[Direction].Y; 345 NewBullet.StopByDirt := True; 329 346 Bullets.Add(NewBullet); 330 347 end; 331 348 end; 349 350 procedure TPlayer.Tick; 351 var 352 I: Integer; 353 Pos: TPoint; 354 begin 332 355 for I := Bullets.Count - 1 downto 0 do 333 356 with TBullet(Bullets[I]) do begin 334 Engine.World.Surface.ItemsXY[Position.X, Position.Y] := Byte(smNothing); 335 336 Position.X := Position.X + DirectionToDelta[Direction].X; 337 Position.Y := Position.Y + DirectionToDelta[Direction].Y; 338 339 if Engine.World.Surface.ItemsXY[Position.X, Position.Y] <> Byte(smNothing) then begin 340 if (Engine.World.Surface.ItemsXY[Position.X, Position.Y] = Byte(smDirt1)) or 341 (Engine.World.Surface.ItemsXY[Position.X, Position.Y] = Byte(smDirt2)) then 342 Engine.World.Surface.ItemsXY[Position.X, Position.Y] := Byte(smNothing); 357 Pos := Point(Trunc(Position.X), Trunc(Position.Y)); 358 Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smNothing); 359 360 Position.X := Position.X + Direction.X; 361 Position.Y := Position.Y + Direction.Y; 362 Distance := Distance + Sqrt(Sqr(Direction.X) + Sqr(Direction.Y)); 363 //ShowMessage(FloatToStr(Distance)); 364 if (Distance > MaxDistance) and (MaxDistance > 0) then begin 343 365 Bullets.Delete(I); 344 end else 366 Continue; 367 end; 368 369 Pos := Point(Trunc(Position.X), Trunc(Position.Y)); 370 371 if Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] <> Byte(smNothing) then begin 372 if (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] = Byte(smDirt1)) or 373 (Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] = Byte(smDirt2)) then begin 374 Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smNothing); 375 if StopByDirt then begin 376 Bullets.Delete(I); 377 Engine.Redraw; 378 Continue; 379 end; 380 end else begin 381 Bullets.Delete(I); 382 Engine.Redraw; 383 Continue; 384 end; 385 end; 386 345 387 with Engine.World.Surface do 346 if (Position.X >= Count.X) or (Position.X < 0) or 347 (Position.Y >= Count.Y) or (Position.Y < 0) then 348 Bullets.Delete(I) else 349 Engine.World.Surface.ItemsXY[Position.X, Position.Y] := Byte(smBullet); 388 if (Pos.X >= Count.X) or (Pos.X < 0) or 389 (Pos.Y >= Count.Y) or (Pos.Y < 0) then begin 390 Bullets.Delete(I); 391 Engine.Redraw; 392 Continue; 393 end; 394 Engine.World.Surface.ItemsXY[Pos.X, Pos.Y] := Byte(smBullet); 350 395 Engine.Redraw; 351 396 end; … … 355 400 if Energy <= 0 then begin 356 401 Energy := 0; 357 BlowUp;402 Explosion; 358 403 end; 359 404 end else begin … … 460 505 end; 461 506 462 procedure TPlayer.BlowUp; 463 begin 464 507 procedure TPlayer.Init; 508 begin 509 with Engine do 510 Position := Point(Round(World.Surface.Count.X * 0.2) + Random(Round(World.Surface.Count.X * 0.6)), 511 Round(World.Surface.Count.Y * 0.2) + Random(Round(World.Surface.Count.Y * 0.6))); 512 Exploded := False; 513 Bullets.Clear; 514 Energy := 1; 515 Shield := 1; 516 PlaceHouse; 517 end; 518 519 procedure TPlayer.Explosion; 520 var 521 NewBullet: TBullet; 522 I: Integer; 523 const 524 BulletMaxSpeed = 1; 525 BulletMinSpeed = 0.5; 526 begin 527 if not Exploded then begin 528 Exploded := True; 529 HideTank; 530 for I := 0 to ExplosionBulletCount - 1 do begin 531 NewBullet := TBullet.Create; 532 NewBullet.Player := Self; 533 NewBullet.Direction.X := (BulletMaxSpeed - BulletMinSpeed) * (Random - 0.5); 534 NewBullet.Direction.Y := (BulletMaxSpeed - BulletMinSpeed) * (Random - 0.5); 535 //NewBullet.Direction.X := NewBullet.Direction.X + BulletMinSpeed * Sign(NewBullet.Direction.X); 536 //NewBullet.Direction.Y := NewBullet.Direction.Y + BulletMinSpeed * Sign(NewBullet.Direction.Y); 537 NewBullet.Position.X := Position.X + NewBullet.Direction.X * 2; 538 NewBullet.Position.Y := Position.Y + NewBullet.Direction.Y * 2; 539 (* if NewBullet.Direction.X < (Speed / 10) then 540 NewBullet.Direction.X := Speed / 10; 541 if NewBullet.Direction.Y < (Speed / 10) then 542 NewBullet.Direction.Y := Speed / 10;*) 543 NewBullet.MaxDistance := Random(ExplosionRange); 544 Bullets.Add(NewBullet); 545 end; 546 end; 465 547 end; 466 548 … … 681 763 for I := 0 to Players.Count - 1 do begin 682 764 TPlayer(Players[I]).Control; 765 TPlayer(Players[I]).Tick; 683 766 end; 684 767 end; … … 788 871 for I := 0 to Players.Count - 1 do 789 872 with TPlayer(Players[I]) do 790 begin 791 // Reset position 792 Position := Point(Round(World.Surface.Count.X * 0.2) + Random(Round(World.Surface.Count.X * 0.6)), 793 Round(World.Surface.Count.Y * 0.2) + Random(Round(World.Surface.Count.Y * 0.6))); 794 795 Energy := 1; 796 Shield := 1; 797 PlaceHouse; 798 end; 873 Init; 799 874 Redraw; 800 875 end;
Note:
See TracChangeset
for help on using the changeset viewer.