hedgewars/uGears.pas
changeset 10 edf56dca1587
parent 9 4cbf854ad095
child 14 81f125629b25
equal deleted inserted replaced
9:4cbf854ad095 10:edf56dca1587
    66 procedure ProcessGears;
    66 procedure ProcessGears;
    67 procedure SetAllToActive;
    67 procedure SetAllToActive;
    68 procedure SetAllHHToActive;
    68 procedure SetAllHHToActive;
    69 procedure DrawGears(Surface: PSDL_Surface);
    69 procedure DrawGears(Surface: PSDL_Surface);
    70 procedure FreeGearsList;
    70 procedure FreeGearsList;
    71 procedure InitGears;
    71 procedure AddMiscGears;
    72 procedure AssignHHCoords;
    72 procedure AssignHHCoords;
    73 
    73 
    74 var CurAmmoGear: PGear = nil;
    74 var CurAmmoGear: PGear = nil;
    75 
    75 
    76 implementation
    76 implementation
    86                                   end;
    86                                   end;
    87                  end;
    87                  end;
    88 
    88 
    89 procedure DeleteGear(Gear: PGear); forward;
    89 procedure DeleteGear(Gear: PGear); forward;
    90 procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward;
    90 procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward;
       
    91 function  isGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): boolean; forward;
    91 
    92 
    92 {$INCLUDE GSHandlers.inc}
    93 {$INCLUDE GSHandlers.inc}
    93 {$INCLUDE HHHandlers.inc}
    94 {$INCLUDE HHHandlers.inc}
    94 
    95 
    95 const doStepHandlers: array[TGearType] of TGearStepProcedure = (
    96 const doStepHandlers: array[TGearType] of TGearStepProcedure = (
   103                                                                doStepShotgunShot,
   104                                                                doStepShotgunShot,
   104                                                                doStepActionTimer,
   105                                                                doStepActionTimer,
   105                                                                doStepPickHammer,
   106                                                                doStepPickHammer,
   106                                                                doStepRope,
   107                                                                doStepRope,
   107                                                                doStepSmokeTrace,
   108                                                                doStepSmokeTrace,
   108                                                                doStepExplosion
   109                                                                doStepExplosion,
       
   110                                                                doStepMine
   109                                                                );
   111                                                                );
   110 
   112 
   111 function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear;
   113 function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear;
   112 begin
   114 begin
   113 {$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+')');{$ENDIF}
   115 {$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+')');{$ENDIF}
   182                 RopePoints.Count:= 0;
   184                 RopePoints.Count:= 0;
   183                 end;
   185                 end;
   184    gtExplosion: begin
   186    gtExplosion: begin
   185                 Result.X:= Result.X - 25;
   187                 Result.X:= Result.X - 25;
   186                 Result.Y:= Result.Y - 25;
   188                 Result.Y:= Result.Y - 25;
       
   189                 end;
       
   190         gtMine: begin
       
   191                 Result.HalfWidth:= 3;
       
   192                 Result.HalfHeight:= 3;
       
   193                 Result.Elasticity:= 0.55;
       
   194                 Result.Friction:= 0.995;
       
   195                 Result.Timer:= 3000;
   187                 end;
   196                 end;
   188      end;
   197      end;
   189 if GearsList = nil then GearsList:= Result
   198 if GearsList = nil then GearsList:= Result
   190                    else begin
   199                    else begin
   191                    GearsList.PrevGear:= Result;
   200                    GearsList.PrevGear:= Result;
   431                        DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface);
   440                        DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface);
   432                        end else
   441                        end else
   433                        DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface);
   442                        DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface);
   434                     end;
   443                     end;
   435        gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface);
   444        gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface);
       
   445             gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420)
       
   446                        then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface)
       
   447                        else DrawSprite(sprMineOn  , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface);
   436               end;
   448               end;
   437       Gear:= Gear.NextGear
   449       Gear:= Gear.NextGear
   438       end;
   450       end;
   439 end;
   451 end;
   440 
   452 
   451       Dispose(t)
   463       Dispose(t)
   452       except OutError(errmsgDynamicVar) end;
   464       except OutError(errmsgDynamicVar) end;
   453       end;
   465       end;
   454 end;
   466 end;
   455 
   467 
   456 procedure InitGears;
   468 procedure AddMiscGears;
   457 var i: integer;
   469 var i, x, y: integer;
   458 begin
   470 begin
   459 for i:= 0 to cCloudsNumber do AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -128, gtCloud, random(4), (0.5-random)*0.01);
   471 for i:= 0 to cCloudsNumber do AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -128, gtCloud, random(4), (0.5-random)*0.01);
   460 AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3;
   472 AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3;
       
   473 for i:= 0 to 3 do
       
   474     begin
       
   475     GetHHPoint(x, y);
       
   476     AddGear(X, Y + 9, gtMine, 0);
       
   477     end;
   461 end;
   478 end;
   462 
   479 
   463 procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord);
   480 procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord);
   464 var Gear: PGear;
   481 var Gear: PGear;
   465     dmg: integer;
   482     dmg: integer;
   477       dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y)));
   494       dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y)));
   478       if dmg > 0 then
   495       if dmg > 0 then
   479          begin
   496          begin
   480          dmg:= dmg shr 1;
   497          dmg:= dmg shr 1;
   481          case Gear.Kind of
   498          case Gear.Kind of
   482               gtHedgehog: begin
   499               gtHedgehog,
       
   500                   gtMine: begin
   483                           inc(Gear.Damage, dmg);
   501                           inc(Gear.Damage, dmg);
   484                           Gear.dX:= Gear.dX + dmg / 200 * sign(Gear.X - X);
   502                           Gear.dX:= Gear.dX + dmg / 200 * sign(Gear.X - X);
   485                           Gear.dY:= Gear.dY + dmg / 200 * sign(Gear.Y - Y);
   503                           Gear.dY:= Gear.dY + dmg / 200 * sign(Gear.Y - Y);
   486                           FollowGear:= Gear
   504                           FollowGear:= Gear
   487                           end;
   505                           end;
   507          end;
   525          end;
   508       Gear:= Gear.NextGear
   526       Gear:= Gear.NextGear
   509       end
   527       end
   510 end;
   528 end;
   511 
   529 
       
   530 function isGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): boolean;
       
   531 var t: PGear;
       
   532 begin
       
   533 t:= GearsList;
       
   534 rX:= sqr(rX);
       
   535 rY:= sqr(rY);
       
   536 while t <> nil do
       
   537       begin
       
   538       if (t <> Gear) and (t.Kind = Kind) then
       
   539          if sqr(Gear.X - t.X) / rX + sqr(Gear.Y - t.Y) / rY <= 1 then
       
   540             begin
       
   541             Result:= true;
       
   542             exit
       
   543             end;
       
   544       t:= t.NextGear
       
   545       end;
       
   546 Result:= false
       
   547 end;
       
   548 
   512 initialization
   549 initialization
   513 
   550 
   514 finalization
   551 finalization
   515 FreeGearsList
   552 FreeGearsList
   516 
   553