hedgewars/GSHandlers.inc
changeset 8592 bb724ef609db
parent 8589 3bb505fc707e
child 8594 8946f98d09a0
equal deleted inserted replaced
8590:c64b758e0412 8592:bb724ef609db
  5125            result := result + 1;
  5125            result := result + 1;
  5126            end;
  5126            end;
  5127         end;
  5127         end;
  5128 end;
  5128 end;
  5129 
  5129 
  5130 
       
  5131 procedure drawIcePixel(x, y:Longint);
       
  5132 var 
       
  5133     iceSurface: PSDL_Surface;
       
  5134     icePixels: PLongwordArray;
       
  5135     pictureX, pictureY: LongInt;
       
  5136     w, c: LongWord;
       
  5137 begin
       
  5138     if Land[y, x] and lfIce <> 0 then exit;
       
  5139 // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
       
  5140     iceSurface:= SpritesData[sprIceTexture].Surface;
       
  5141     pictureX := x mod iceSurface^.w;
       
  5142     pictureY := y mod iceSurface^.h;
       
  5143     icePixels := iceSurface^.pixels;
       
  5144     w:= LandPixels[y, x];
       
  5145     w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
       
  5146           (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
       
  5147           (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
       
  5148     if w < 128 then w:= w+128;
       
  5149     if w > 255 then w:= 255;
       
  5150     w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
       
  5151     //LandPixels[y, x]:= w;
       
  5152     LandPixels[y, x]:= addBgColor(w, IceColor);
       
  5153     LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
       
  5154 
       
  5155     Land[y, x] := Land[y, x] or lfIce;
       
  5156 end;
       
  5157 
       
  5158 procedure DrawIce(x, y: Longint); 
       
  5159     const iceRadius :Longint = 32;
       
  5160 var
       
  5161     i, j: Longint;
       
  5162     weight: Longint;
       
  5163     landRect : TSDL_RECT;
       
  5164 begin
       
  5165     FillRoundInLandWithIce(x, y, iceRadius);
       
  5166     SetAllHHToActive; 
       
  5167     landRect.x := min(max(x - iceRadius, 0), LAND_WIDTH - 1);
       
  5168     landRect.y := min(max(y - iceRadius, 0), LAND_HEIGHT - 1);
       
  5169     landRect.w := min(2*iceRadius, LAND_WIDTH - landRect.x - 1);
       
  5170     landRect.h := min(2*iceRadius, LAND_HEIGHT - landRect.y - 1);
       
  5171     UpdateLandTexture(landRect.x, landRect.w, landRect.y, landRect.h, true);
       
  5172 end;
       
  5173 
       
  5174 
       
  5175 procedure doStepIceGun(Gear: PGear);
  5130 procedure doStepIceGun(Gear: PGear);
  5176 const iceWaitCollision:Longint = 0;
  5131 const iceWaitCollision:Longint = 0;
  5177 const iceCollideWithGround:Longint = 1;
  5132 const iceCollideWithGround:Longint = 1;
  5178 const iceWaitNextTarget:Longint = 2;
  5133 const iceWaitNextTarget:Longint = 2;
  5179 const iceCollideWithHog:Longint = 4;
  5134 const iceCollideWithHog:Longint = 4;
       
  5135 const iceCollideWithWater:Longint = 5;
  5180 const groundFreezingTime:Longint = 1000;
  5136 const groundFreezingTime:Longint = 1000;
       
  5137 const waterFreezingTime:Longint = 500;
       
  5138 const iceRadius:Longint = 32;
  5181 var
  5139 var
  5182     HHGear: PGear;
  5140     HHGear: PGear;
  5183     ndX, ndY: hwFloat;
  5141     ndX, ndY: hwFloat;
  5184     i, t, gX, gY: LongInt;
  5142     i, t, gX, gY: LongInt;
  5185     hogs: PGearArrayS;
  5143     hogs: PGearArrayS;
  5227                     if IceState = iceWaitCollision then
  5185                     if IceState = iceWaitCollision then
  5228                     begin
  5186                     begin
  5229                         IceState := iceCollideWithGround;
  5187                         IceState := iceCollideWithGround;
  5230                         IceTime := GameTicks;                    
  5188                         IceTime := GameTicks;                    
  5231                     end;
  5189                     end;
       
  5190                 end else if (target.y >= cWaterLine) then
       
  5191                 begin
       
  5192                     IceState := iceCollideWithWater;
  5232                 end;
  5193                 end;
  5233 
  5194 
  5234                 if (abs(gX-Target.X) < 2) and (abs(gY-Target.Y) < 2) then
  5195                 if (abs(gX-Target.X) < 2) and (abs(gY-Target.Y) < 2) then
  5235                 begin
  5196                 begin
  5236                     X:= HHGear^.X;
  5197                     X:= HHGear^.X;
  5237                     Y:= HHGear^.Y
  5198                     Y:= HHGear^.Y
  5238                 end;
  5199                 end;
  5239 
  5200 
  5240                 if (IceState = iceCollideWithGround) and ((GameTicks - IceTime) > groundFreezingTime) then
  5201                 if (IceState = iceCollideWithGround) and ((GameTicks - IceTime) > groundFreezingTime) then
  5241                 begin 
  5202                 begin 
  5242                     DrawIce(Target.X, Target.Y);                                        
  5203                     FillRoundInLandWithIce(Target.X, Target.Y, iceRadius);
       
  5204                     SetAllHHToActive; 
  5243                     IceState := iceWaitNextTarget;
  5205                     IceState := iceWaitNextTarget;
  5244                 end;
  5206                 end;
       
  5207 
       
  5208                 if (IceState = iceCollideWithWater) and ((GameTicks - IceTime) > waterFreezingTime) then
       
  5209                 begin 
       
  5210                     DrawSemiRound(Target.X, cWaterLine - 32, 16, iceRadius-5);
       
  5211                     FillRoundInLandWithIce(Target.X,  cWaterLine - 32, iceRadius);
       
  5212                     SetAllHHToActive; 
       
  5213                     IceState := iceWaitNextTarget;
       
  5214                 end;
       
  5215 
  5245 
  5216 
  5246 // freeze nearby hogs
  5217 // freeze nearby hogs
  5247                 hogs := GearsNear(int2hwFloat(Target.X), int2hwFloat(Target.Y), gtHedgehog, Gear^.Radius*2);
  5218                 hogs := GearsNear(int2hwFloat(Target.X), int2hwFloat(Target.Y), gtHedgehog, Gear^.Radius*2);
  5248                 if hogs.size > 0 then
  5219                 if hogs.size > 0 then
  5249                     for i:= 0 to hogs.size - 1 do
  5220                     for i:= 0 to hogs.size - 1 do
  5265                 Target.X:= gX;
  5236                 Target.X:= gX;
  5266                 Target.Y:= gY;
  5237                 Target.Y:= gY;
  5267                 X:= HHGear^.X;
  5238                 X:= HHGear^.X;
  5268                 Y:= HHGear^.Y
  5239                 Y:= HHGear^.Y
  5269             end;
  5240             end;
  5270             {if (gX > max(LAND_WIDTH,4096)*2) or
  5241             if (gX > max(LAND_WIDTH,4096)*2) or
  5271                     (gX < -max(LAND_WIDTH,4096)) or
  5242                     (gX < -max(LAND_WIDTH,4096)) or
  5272                     (gY < -max(LAND_HEIGHT,4096)) or
  5243                     (gY < -max(LAND_HEIGHT,4096)) or
  5273                     (gY > max(LAND_HEIGHT,4096)+512) then
  5244                     (gY > max(LAND_HEIGHT,4096)+512) then
  5274             begin
  5245             begin
  5275                 X:= HHGear^.X;
  5246                 X:= HHGear^.X;
  5276                 Y:= HHGear^.Y
  5247                 Y:= HHGear^.Y
  5277             end}
  5248             end
  5278         end
  5249         end
  5279     end;
  5250     end;
  5280 end;
  5251 end;
  5281 
  5252 
  5282 procedure doStepAddAmmo(Gear: PGear);
  5253 procedure doStepAddAmmo(Gear: PGear);