hedgewars/GSHandlers.inc
changeset 7733 a1476c09403f
parent 7730 2013733f9ca9
child 7734 b0d8a595875b
equal deleted inserted replaced
7732:fad3408fdcc1 7733:a1476c09403f
  5245 end;
  5245 end;
  5246 
  5246 
  5247 ////////////////////////////////////////////////////////////////////////////////
  5247 ////////////////////////////////////////////////////////////////////////////////
  5248 // Make the knife initial angle based on the hog attack angle, or is that too hard?
  5248 // Make the knife initial angle based on the hog attack angle, or is that too hard?
  5249 procedure doStepKnife(Gear: PGear);
  5249 procedure doStepKnife(Gear: PGear);
  5250 var t, ox, oy, w, h, cx, cy, tx, ty, hx, hy : LongInt;
  5250 var t, 
  5251 begin
  5251     gx, gy, ga,  // gear x,y,angle
  5252     doStepFallingGear(Gear);
  5252     lx, ly, la, // land x,y,angle
       
  5253     ox, oy, // x,y offset
       
  5254     w, h,   // wXh of clip area
       
  5255     tx, ty  // tip position in sprite
       
  5256     : LongInt;
       
  5257     surf: PSDL_Surface;
       
  5258     s: hwFloat;
       
  5259 
       
  5260 begin
       
  5261     Gear^.dY := Gear^.dY + cGravity;
       
  5262     if (GameFlags and gfMoreWind) <> 0 then
       
  5263         Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density;
       
  5264     Gear^.X := Gear^.X + Gear^.dX;
       
  5265     Gear^.Y := Gear^.Y + Gear^.dY;
       
  5266     CheckGearDrowning(Gear);
       
  5267     gx:= hwRound(Gear^.X);
       
  5268     gy:= hwRound(Gear^.Y);
       
  5269     if Gear^.State and gstDrowning <> 0 then exit;
  5253     with Gear^ do
  5270     with Gear^ do
  5254         begin
  5271         begin
  5255         if State and gstCollision <> 0 then
  5272         if CheckLandValue(gx, gy, $FF00) then
  5256             begin
  5273             begin
  5257 (* Yay. More incomplete code.
  5274             t:= Angle + hwRound((hwAbs(dX)+hwAbs(dY)) * _10); 
  5258 This is the set of postions for the knife.
  5275 
  5259 Using FlipSurface and copyToXY the knife can be written to the LandPixels at 32 positions, and an appropriate line drawn in Land.
  5276             if t < 0 then inc(t, 4096)
  5260 0deg
  5277             else if 4095 < t then dec(t, 4096);
  5261 2,5   (x,y offset)
  5278             Angle:= t;
  5262 25,5  (wXh of clip area)
  5279 
  5263 13,2  (centre of mass, relative to the clip)
  5280             DirAngle:= Angle / 4096 * 360
  5264 -13,0 (tip relative to centre of mass)
  5281             end
  5265 11,0  (handle relative to centre of mass)
  5282         else
  5266 
  5283             begin
  5267 11.25deg
  5284 //This is the set of postions for the knife.
  5268 2,15
  5285 //Using FlipSurface and copyToXY the knife can be written to the LandPixels at 32 positions, and an appropriate line drawn in Land.
  5269 24,8
  5286             t:= Angle mod 1024;
  5270 13,4
  5287             case t div 128 of
  5271 -13,3
  5288                 0:  begin
  5272 10,-3
  5289                     ox:=   2; oy:= 5;
  5273 
  5290                     w :=  25;  h:= 5;
  5274 22.5deg
  5291                     tx:=   0; ty:= 2
  5275 2,27
  5292                     end;
  5276 23,12
  5293                 1:  begin
  5277 12,6
  5294                     ox:=   2; oy:= 15;
  5278 -12,5
  5295                      w:=  24;  h:=  8;
  5279 10,-5
  5296                     tx:=   0; ty:=  7
  5280 
  5297                     end;
  5281 33.75deg
  5298                 2:  begin
  5282 2,43
  5299                     ox:=   2; oy:= 27;
  5283 21,15
  5300                      w:=  23;  h:= 12;
  5284 11,7
  5301                     tx:= -12; ty:= -5
  5285 -11,7
  5302                     end;
  5286 9,-6
  5303                 3:  begin
  5287 
  5304                     ox:=   2; oy:= 43;
  5288 45deg
  5305                      w:=  21;  h:= 15;
  5289 29,8
  5306                     tx:=   0; ty:= 14
  5290 19,19
  5307                     end;
  5291 9,9
  5308                 4:  begin
  5292 -9,8
  5309                     ox:= 29; oy:=  8;
  5293 8,-9
  5310                      w:= 19;  h:= 19;
  5294 
  5311                     tx:=  0; ty:= 17 
  5295 56.25deg
  5312                     end;
  5296 29,32
  5313                 5:  begin
  5297 15,21
  5314                     ox:= 29; oy:=  32;
  5298 7,10
  5315                      w:= 15;  h:=  21;
  5299 -7,10
  5316                     tx:=  0; ty:=  20
  5300 7,-10
  5317                     end;
  5301 
  5318                 6:  begin
  5302 67.5deg
  5319                     ox:= 51; oy:=   3;
  5303 51,3
  5320                      w:= 11;  h:=  23;
  5304 11,23
  5321                     tx:=  0; ty:=  22 
  5305 5,11
  5322                     end;
  5306 -5,11
  5323                 7:  begin
  5307 5,-11
  5324                     ox:= 51; oy:=  34;
  5308 
  5325                      w:=  7;  h:=  24;
  5309 78.75deg
  5326                     tx:=  0; ty:=  23
  5310 51,34
  5327                     end
  5311 7,24
  5328                 end;
  5312 2,11
  5329                 
  5313 -2,12
  5330             surf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask);
  5314 4,-11
  5331             copyToXYFromRect(SpritesData[sprKnife].Surface, surf, ox, oy, w, h, 0, 0);
  5315 *)
  5332             // try to make the knife hit point first
       
  5333             lx := 0;
       
  5334             ly := 0;
       
  5335             if CalcSlopeTangent(Gear, gx, gy, lx, ly, 255) then
       
  5336                 begin
       
  5337                 la:= vector2Angle(int2hwFloat(lx), int2hwFloat(ly));
       
  5338                 ga:= vector2Angle(dX, dY);
       
  5339                 // change  to 0 to 4096 forced by LongWord in Gear
       
  5340                 if la < 0 then la:= 4096+la;
       
  5341                 if ga < 0 then ga:= 4096+ga;
       
  5342                 if ((Angle < ga) and (Angle < la)) or ((Angle > ga) and (Angle > la)) then
       
  5343                     begin
       
  5344                     if Angle >= 2048 then dec(Angle, 2048)
       
  5345                     else if Angle < 2048 then inc(Angle, 2048)
       
  5346                     end
       
  5347                 end;
       
  5348             case Angle div 1024 of
       
  5349                 0:  begin 
       
  5350                     flipSurface(surf, true);
       
  5351                     flipSurface(surf, true);
       
  5352                     BlitImageAndGenerateCollisionInfo(hwRound(X)-(w-tx), hwRound(Y)+(w-ty), w, surf)
       
  5353                     end;
       
  5354                 1:  begin
       
  5355                     flipSurface(surf, false);
       
  5356                     BlitImageAndGenerateCollisionInfo(hwRound(X)-(w-tx), hwRound(Y)-ty, w, surf)
       
  5357                     end;
       
  5358                 2:  begin // knife was actually drawn facing this way...
       
  5359                     BlitImageAndGenerateCollisionInfo(hwRound(X)-tx, hwRound(Y)-ty, w, surf)
       
  5360                     end;
       
  5361                 3:  begin
       
  5362                     flipSurface(surf, true);
       
  5363                     BlitImageAndGenerateCollisionInfo(hwRound(X)-tx, hwRound(Y)+(w-ty), w, surf)
       
  5364                     end
       
  5365                 end;
       
  5366             SDL_FreeSurface(surf);
       
  5367             // this needs to calculate actual width/height + land clipping since update texture doesn't.
       
  5368             // i.e. this will crash if you fire near sides of map, but until I get the blit right, not going to put real values
       
  5369             UpdateLandTexture(hwRound(X)-32, 64, hwRound(Y)-32, 64, true);
  5316             DeleteGear(Gear);
  5370             DeleteGear(Gear);
  5317             exit
  5371             exit
  5318             end
  5372             end
  5319         else
  5373         end;
  5320             begin
  5374 end;
  5321             t := hwRound((dX + dY) * _10);
       
  5322             if not dX.isNegative then inc(Angle, t)
       
  5323             else dec(Angle,t);
       
  5324 
       
  5325             if Angle < -2048 then inc(Angle, 4096)
       
  5326             else if 2048 < Angle then dec(Angle, 4096);
       
  5327             DirAngle:= (Angle+2048) / 4096 * 360;
       
  5328             end
       
  5329         end;
       
  5330 end;