hedgewars/uGearsHandlersMess.pas
changeset 10657 f2507005be87
parent 10652 4456836514ed
child 10659 79e466c393f7
equal deleted inserted replaced
10656:2093cf51eea1 10657:f2507005be87
  4572 ////////////////////////////////////////////////////////////////////////////////
  4572 ////////////////////////////////////////////////////////////////////////////////
  4573 procedure doStepSineGunShotWork(Gear: PGear);
  4573 procedure doStepSineGunShotWork(Gear: PGear);
  4574 var
  4574 var
  4575     x, y, rX, rY, t, tmp, initHealth: LongInt;
  4575     x, y, rX, rY, t, tmp, initHealth: LongInt;
  4576     oX, oY, ldX, ldY, sdX, sdY, sine, lx, ly, amp: hwFloat;
  4576     oX, oY, ldX, ldY, sdX, sdY, sine, lx, ly, amp: hwFloat;
  4577     justCollided: boolean;
  4577     justCollided, justBounced: boolean;
  4578 begin
  4578 begin
  4579     AllInactive := false;
  4579     AllInactive := false;
  4580     initHealth := Gear^.Health;
  4580     initHealth := Gear^.Health;
  4581     lX := Gear^.X;
  4581     lX := Gear^.X;
  4582     lY := Gear^.Y;
  4582     lY := Gear^.Y;
  4595     t := getRandom(4096);
  4595     t := getRandom(4096);
  4596 
  4596 
  4597 
  4597 
  4598     // used for a work-around detection of area that is within land array, but outside borders
  4598     // used for a work-around detection of area that is within land array, but outside borders
  4599     justCollided := false;
  4599     justCollided := false;
       
  4600     // this variable is just to ensure we don't run in infinite loop due to precision errors
       
  4601     justBounced:= false;
  4600 
  4602 
  4601     repeat
  4603     repeat
  4602         lX := lX + ldX;
  4604         lX := lX + ldX;
  4603         lY := lY + ldY;
  4605         lY := lY + ldY;
  4604         oX := Gear^.X;
  4606         oX := Gear^.X;
  4607         rY := hwRound(oY);
  4609         rY := hwRound(oY);
  4608         tmp := t mod 4096;
  4610         tmp := t mod 4096;
  4609         amp := _128 * (_1 - hwSqr(int2hwFloat(Gear^.Health)/initHealth));
  4611         amp := _128 * (_1 - hwSqr(int2hwFloat(Gear^.Health)/initHealth));
  4610         sine := amp * AngleSin(tmp mod 2048);
  4612         sine := amp * AngleSin(tmp mod 2048);
  4611         sine.isNegative := (tmp < 2048);
  4613         sine.isNegative := (tmp < 2048);
  4612         inc(t,Gear^.Health div 313);
       
  4613         Gear^.X := lX + (sine * sdX);
  4614         Gear^.X := lX + (sine * sdX);
  4614         Gear^.Y := ly + (sine * sdY);
  4615         Gear^.Y := ly + (sine * sdY);
  4615         Gear^.dX := Gear^.X - oX;
  4616         Gear^.dX := Gear^.X - oX;
  4616         Gear^.dY := Gear^.Y - oY;
  4617         Gear^.dY := Gear^.Y - oY;
  4617 
  4618 
  4628             else if x < LongInt(leftX) then
  4629             else if x < LongInt(leftX) then
  4629                 repeat;
  4630                 repeat;
  4630                 inc(x,  playWidth);
  4631                 inc(x,  playWidth);
  4631                 inc(rx, playWidth);
  4632                 inc(rx, playWidth);
  4632                 until x >= LongInt(leftX);
  4633                 until x >= LongInt(leftX);
  4633             end;
  4634             end
       
  4635         else if (WorldEdge = weBounce) then
       
  4636             begin
       
  4637             if (not justBounced) and ((x > LongInt(rightX)) or (x < LongInt(leftX))) then
       
  4638                 begin
       
  4639                 // reflect
       
  4640                 lX:= lX - ldX + ((oX - lX) * 2);
       
  4641                 lY:= lY - ldY;
       
  4642                 Gear^.X:= oX;
       
  4643                 Gear^.Y:= oY;
       
  4644                 ldX.isNegative:= (not ldX.isNegative);
       
  4645                 sdX.isNegative:= (not sdX.isNegative);
       
  4646                 justBounced:= true;
       
  4647                 continue;
       
  4648                 end
       
  4649             else
       
  4650                 justBounced:= false;
       
  4651             end;
       
  4652 
       
  4653 
       
  4654         inc(t,Gear^.Health div 313);
  4634 
  4655 
  4635         // if borders are on, stop outside land array
  4656         // if borders are on, stop outside land array
  4636         if hasBorder and (((x and LAND_WIDTH_MASK) <> 0) or ((y and LAND_HEIGHT_MASK) <> 0)) then
  4657         if hasBorder and (((x and LAND_WIDTH_MASK) <> 0) or ((y and LAND_HEIGHT_MASK) <> 0)) then
  4637             begin
  4658             begin
  4638             Gear^.Damage := 0;
  4659             Gear^.Damage := 0;