hedgewars/uGearsHandlersMess.pas
changeset 15927 046182f1080b
parent 15873 9bb85e43e492
child 15929 128ace913837
child 15938 4c0f8dbf6c13
equal deleted inserted replaced
15926:7f3d7f015aa5 15927:046182f1080b
   832 var xx, yy, px, py, rx, ry, lx, ly: LongInt;
   832 var xx, yy, px, py, rx, ry, lx, ly: LongInt;
   833     move, draw, allpx, gun: Boolean;
   833     move, draw, allpx, gun: Boolean;
   834     s: PSDL_Surface;
   834     s: PSDL_Surface;
   835     p: PLongwordArray;
   835     p: PLongwordArray;
   836     lf: LongWord;
   836     lf: LongWord;
   837 begin
   837     oldY: hwFloat;
   838 inc(Gear^.Pos);
   838 begin
   839 gun:= (Gear^.State and gstTmpFlag) <> 0;
   839 gun:= (Gear^.State and gstTmpFlag) <> 0;
   840 move:= false;
   840 move:= false;
   841 draw:= false;
   841 draw:= false;
   842 if gun then
   842 if gun then
   843     begin
   843     begin
       
   844     inc(Gear^.Pos);
   844     Gear^.State:= Gear^.State and (not gstInvisible);
   845     Gear^.State:= Gear^.State and (not gstInvisible);
   845     doStepFallingGear(Gear);
   846     doStepFallingGear(Gear);
   846     CheckCollision(Gear);
   847     CheckCollision(Gear);
   847     if ((Gear^.State and gstCollision) <> 0) or ((Gear^.State and gstMoving) = 0) then
   848     if ((Gear^.State and gstCollision) <> 0) or ((Gear^.State and gstMoving) = 0) then
   848         draw:= true;
   849         draw:= true;
   855         else xx:= leftX+3;
   856         else xx:= leftX+3;
   856         Gear^.X:= int2hwFloat(xx)
   857         Gear^.X:= int2hwFloat(xx)
   857         end
   858         end
   858     end
   859     end
   859 else if GameTicks and $7 = 0 then
   860 else if GameTicks and $7 = 0 then
   860     begin
       
   861     with Gear^ do
   861     with Gear^ do
   862         begin
   862         begin
       
   863         inc(Pos, 8);
   863         State:= State and (not gstInvisible);
   864         State:= State and (not gstInvisible);
       
   865         oldY:= Y;
   864         X:= X + cWindSpeed * 3200 + dX;
   866         X:= X + cWindSpeed * 3200 + dX;
   865         Y:= Y + dY + cGravity * vobFallSpeed * 8;  // using same value as flakes to try and get similar results
   867         Y:= Y + dY + cGravity * (vobFallSpeed * 8);  // using same value as flakes to try and get similar results
   866         xx:= hwRound(X);
   868         xx:= hwRound(X);
   867         yy:= hwRound(Y);
   869         yy:= hwRound(Y);
   868         if vobVelocity <> 0 then
   870         if vobVelocity <> 0 then
   869             begin
   871             begin
   870             DirAngle := DirAngle + (Damage / 1000);
   872             DirAngle := DirAngle + (Damage / 1000);
   876     // move back to cloud layer
   878     // move back to cloud layer
   877         if CheckCoordInWater(xx, yy) then
   879         if CheckCoordInWater(xx, yy) then
   878             move:= true
   880             move:= true
   879         else if (xx > snowRight) or (xx < snowLeft) then
   881         else if (xx > snowRight) or (xx < snowLeft) then
   880             move:=true
   882             move:=true
   881         else if (cGravity < _0) and (yy < LAND_HEIGHT-1200) then
   883         else if (cGravity.isNegative) and (yy < LAND_HEIGHT-1200) then
   882             move:=true
   884             move:=true
   883         // Solid pixel encountered
   885         // Solid pixel encountered
   884         else if ((yy and LAND_HEIGHT_MASK) = 0) and ((xx and LAND_WIDTH_MASK) = 0) and (Land[yy, xx] <> 0) then
   886         else if ((yy and LAND_HEIGHT_MASK) = 0) and ((xx and LAND_WIDTH_MASK) = 0) and (Land[yy, xx] <> 0) then
   885             begin
   887             begin
   886             lf:= Land[yy, xx] and (lfObject or lfBasic or lfIndestructible);
   888             lf:= Land[yy, xx] and (lfObject or lfBasic or lfIndestructible);
   889             if (((yy-1) and LAND_HEIGHT_MASK) = 0) and (Land[yy-1, xx] = 0) then
   891             if (((yy-1) and LAND_HEIGHT_MASK) = 0) and (Land[yy-1, xx] = 0) then
   890                 begin
   892                 begin
   891                 X:= X - cWindSpeed * 1600 - dX;
   893                 X:= X - cWindSpeed * 1600 - dX;
   892                 end
   894                 end
   893             // If there's room below, on the sides, fill the gaps
   895             // If there's room below, on the sides, fill the gaps
   894             else if (((yy-1) and LAND_HEIGHT_MASK) = 0) and (((xx-(1*hwSign(cWindSpeed))) and LAND_WIDTH_MASK) = 0) and (Land[yy-1, (xx-(1*hwSign(cWindSpeed)))] = 0) then
   896             else if (((yy-1) and LAND_HEIGHT_MASK) = 0) then 
   895                 begin
   897 		    begin
   896                 X:= X - _0_8 * hwSign(cWindSpeed);
   898 		    if (((xx - 1) and LAND_WIDTH_MASK) = 0) and (Land[yy - 1, (xx - 1)] = 0) then
   897                 Y:= Y - dY - cGravity * vobFallSpeed * 8;
   899 		        begin
   898                 end
   900 		        X:= X - _0_8;
   899             else if (((yy-1) and LAND_HEIGHT_MASK) = 0) and (((xx-(2*hwSign(cWindSpeed))) and LAND_WIDTH_MASK) = 0) and (Land[yy-1, (xx-(2*hwSign(cWindSpeed)))] = 0) then
   901 		        Y:= oldY;
   900                 begin
   902 		        end
   901                 X:= X - _0_8 * 2 * hwSign(cWindSpeed);
   903 		    else if (((xx - 2) and LAND_WIDTH_MASK) = 0) and (Land[yy - 1, (xx - 2)] = 0) then
   902                 Y:= Y - dY - cGravity * vobFallSpeed * 8;
   904 		        begin
   903                 end
   905 		        X:= X - _1_6;
   904             else if (((yy-1) and LAND_HEIGHT_MASK) = 0) and (((xx+(1*hwSign(cWindSpeed))) and LAND_WIDTH_MASK) = 0) and (Land[yy-1, (xx+(1*hwSign(cWindSpeed)))] = 0) then
   906 		        Y:= oldY;
   905                 begin
   907 		        end
   906                 X:= X + _0_8 * hwSign(cWindSpeed);
   908 		    else if (((xx + 1) and LAND_WIDTH_MASK) = 0) and (Land[yy - 1, (xx + 1)] = 0) then
   907                 Y:= Y - dY - cGravity * vobFallSpeed * 8;
   909 		        begin
   908                 end
   910 		        X:= X + _0_8;
   909             else if (((yy-1) and LAND_HEIGHT_MASK) = 0) and (((xx+(2*hwSign(cWindSpeed))) and LAND_WIDTH_MASK) = 0) and (Land[yy-1, (xx+(2*hwSign(cWindSpeed)))] = 0) then
   911 		        Y:= oldY;
   910                 begin
   912 		        end
   911                 X:= X + _0_8 * 2 * hwSign(cWindSpeed);
   913 		    else if (((xx + 2) and LAND_WIDTH_MASK) = 0) and (Land[yy - 1, (xx + 2)] = 0) then
   912                 Y:= Y - dY - cGravity * vobFallSpeed * 8;
   914 		        begin
   913                 end
   915 		        X:= X + _1_6;
       
   916 		        Y:= oldY;
       
   917 		        end else
       
   918 		    if ((((yy+1) and LAND_HEIGHT_MASK) = 0) and ((Land[yy + 1, xx] and $FF) <> 0)) then 
       
   919 		       move:=true 
       
   920 		    else 
       
   921 		       draw:= true
       
   922 		    end
   914             // if there's an hog/object below do nothing
   923             // if there's an hog/object below do nothing
   915             else if ((((yy+1) and LAND_HEIGHT_MASK) = 0) and ((Land[yy+1, xx] and $FF) <> 0))
   924             else if ((((yy+1) and LAND_HEIGHT_MASK) = 0) and ((Land[yy+1, xx] and $FF) <> 0))
   916                 then move:=true
   925                 then move:=true
   917             else draw:= true
   926             else draw:= true
   918             end
   927             end
   919         end
   928         end;
   920     end;
   929 
   921 if draw then
   930 if draw then
   922     with Gear^ do
   931     with Gear^ do
   923         begin
   932         begin
   924         // we've collided with land. draw some stuff and get back into the clouds
   933         // we've collided with land. draw some stuff and get back into the clouds
   925         move:= true;
   934         move:= true;
   926         if (Pos > 20) and ((CurAmmoGear = nil)
   935         if (Pos > 20) and ((CurAmmoGear = nil)
   927         or (CurAmmoGear^.Kind <> gtRope)) then
   936         or (CurAmmoGear^.Kind <> gtRope)) then
   928             begin
   937             begin
   929 ////////////////////////////////// TODO - ASK UNC0RR FOR A GOOD HOME FOR THIS ////////////////////////////////////
       
   930             if not gun then
   938             if not gun then
   931                 begin
   939                 begin
   932                 dec(yy,3);
   940                 dec(yy,3);
   933                 dec(xx,1)
   941                 dec(xx,1)
   934                 end;
   942                 end;
   967                     else allpx:= false
   975                     else allpx:= false
   968                     end;
   976                     end;
   969                 p:= PLongWordArray(@(p^[s^.pitch shr 2]))
   977                 p:= PLongWordArray(@(p^[s^.pitch shr 2]))
   970                 end;
   978                 end;
   971 
   979 
   972             // Why is this here.  For one thing, there's no test on +1 being safe.
       
   973             //Land[py, px+1]:= lfBasic;
       
   974 
       
   975             if allpx then
   980             if allpx then
   976                 UpdateLandTexture(xx, Pred(s^.h), yy, Pred(s^.w), true)
   981                 UpdateLandTexture(xx, Pred(s^.h), yy, Pred(s^.w), true)
   977             else
   982             else
   978                 begin
   983                 begin
   979                 UpdateLandTexture(
   984                 UpdateLandTexture(
   981                     min(LAND_WIDTH - xx, Pred(s^.w)),
   986                     min(LAND_WIDTH - xx, Pred(s^.w)),
   982                     max(0, min(LAND_WIDTH, yy)),
   987                     max(0, min(LAND_WIDTH, yy)),
   983                     min(LAND_HEIGHT - yy, Pred(s^.h)), false // could this be true without unnecessarily creating blanks?
   988                     min(LAND_HEIGHT - yy, Pred(s^.h)), false // could this be true without unnecessarily creating blanks?
   984                 );
   989                 );
   985                 end;
   990                 end;
   986 ////////////////////////////////// TODO - ASK UNC0RR FOR A GOOD HOME FOR THIS ////////////////////////////////////
       
   987             end
   991             end
   988         end;
   992         end;
   989 
   993 
   990 if move then
   994 if move then
   991     begin
   995     begin
   994         DeleteGear(Gear);
   998         DeleteGear(Gear);
   995         exit
   999         exit
   996         end;
  1000         end;
   997     Gear^.Pos:= 0;
  1001     Gear^.Pos:= 0;
   998     Gear^.X:= int2hwFloat(LongInt(GetRandom(snowRight - snowLeft)) + snowLeft);
  1002     Gear^.X:= int2hwFloat(LongInt(GetRandom(snowRight - snowLeft)) + snowLeft);
   999     if (cGravity < _0) and (yy < LAND_HEIGHT-1200) then
  1003     if (cGravity.isNegative) and (yy < LAND_HEIGHT-1200) then
  1000          Gear^.Y:= int2hwFloat(LAND_HEIGHT - 50 - LongInt(GetRandom(50)))
  1004          Gear^.Y:= int2hwFloat(LAND_HEIGHT - 50 - LongInt(GetRandom(50)))
  1001     else Gear^.Y:= int2hwFloat(LAND_HEIGHT + LongInt(GetRandom(50)) - 1250);
  1005     else Gear^.Y:= int2hwFloat(LAND_HEIGHT + LongInt(GetRandom(50)) - 1250);
  1002     Gear^.State:= Gear^.State or gstInvisible;
  1006     Gear^.State:= Gear^.State or gstInvisible;
  1003     end
  1007     end
  1004 end;
  1008 end;