hedgewars/uGearsRender.pas
changeset 14994 d9de740e194c
parent 14955 088c1d319612
child 14995 e796e9a88394
equal deleted inserted replaced
14993:fd29c23ff95e 14994:d9de740e194c
    52                                 end;
    52                                 end;
    53                 rounded: array[0..MAXROPEPOINTS + 2] of TVertex2f;
    53                 rounded: array[0..MAXROPEPOINTS + 2] of TVertex2f;
    54                 end;
    54                 end;
    55 
    55 
    56 implementation
    56 implementation
    57 uses uRender, uRenderUtils, uUtils, uVariables, uAmmos, Math, uVisualGearsList;
    57 uses uRender, uRenderUtils, uGearsUtils, uUtils, uVariables, uAmmos, Math, uVisualGearsList;
    58 
    58 
    59 procedure DrawRopeLinesRQ(Gear: PGear);
    59 procedure DrawRopeLinesRQ(Gear: PGear);
    60 var n: LongInt;
    60 var n: LongInt;
    61 begin
    61 begin
    62 with RopePoints do
    62 with RopePoints do
   261 end;
   261 end;
   262 
   262 
   263 // Render some informational GUI next to hedgehog, like fuel and alternate weapon
   263 // Render some informational GUI next to hedgehog, like fuel and alternate weapon
   264 procedure RenderHHGuiExtras(Gear: PGear; ox, oy: LongInt);
   264 procedure RenderHHGuiExtras(Gear: PGear; ox, oy: LongInt);
   265 var HH: PHedgehog;
   265 var HH: PHedgehog;
   266     sx, sy, tx, ty, t, sign, m: LongInt;
   266     sx, sy, tx, ty, t, hogLR: LongInt;
   267     dAngle: real;
   267     dAngle: real;
   268 begin
   268 begin
   269     HH:= Gear^.Hedgehog;
   269     HH:= Gear^.Hedgehog;
   270     sx:= ox + 1; // this offset is very common
   270     sx:= ox + 1; // this offset is very common
   271     sy:= oy - 3;
   271     sy:= oy - 3;
   316         end;
   316         end;
   317 
   317 
   318     // render crosshair
   318     // render crosshair
   319     if (CrosshairGear <> nil) and (Gear = CrosshairGear) then
   319     if (CrosshairGear <> nil) and (Gear = CrosshairGear) then
   320         begin
   320         begin
   321         sign:= hwSign(Gear^.dX);
   321         hogLR:= 1;
   322         m:= 1;
   322         if IsHogFacingLeft(Gear) then
   323         if ((Gear^.State and gstHHHJump) <> 0) and (HH^.Effects[heArtillery] = 0) then
   323             hogLR:= -1;
   324             m:= -1;
       
   325         setTintAdd(true);
   324         setTintAdd(true);
   326         Tint(HH^.Team^.Clan^.Color shl 8 or $FF);
   325         Tint(HH^.Team^.Clan^.Color shl 8 or $FF);
   327         DrawTextureRotated(CrosshairTexture,
   326         DrawTextureRotated(CrosshairTexture,
   328                 12, 12, CrosshairX + WorldDx, CrosshairY + WorldDy, 0,
   327                 12, 12, CrosshairX + WorldDx, CrosshairY + WorldDy, 0,
   329                 sign * m * (Gear^.Angle * 180.0) / cMaxAngle);
   328                 hogLR * (Gear^.Angle * 180.0) / cMaxAngle);
   330         untint;
   329         untint;
   331         setTintAdd(false);
   330         setTintAdd(false);
   332         end;
   331         end;
   333 
   332 
   334     // render gear-related extras: alt weapon, fuel, other
   333     // render gear-related extras: alt weapon, fuel, other
   358 end;
   357 end;
   359 
   358 
   360 procedure DrawHH(Gear: PGear; ox, oy: LongInt);
   359 procedure DrawHH(Gear: PGear; ox, oy: LongInt);
   361 var i, t: LongInt;
   360 var i, t: LongInt;
   362     amt: TAmmoType;
   361     amt: TAmmoType;
   363     sign, hx, hy, tx, ty, sx, sy, m: LongInt;  // hedgehog, crosshair, temp, sprite, direction
   362     sign, hx, hy, tx, ty, sx, sy, hogLR: LongInt;  // hedgehog, crosshair, temp, sprite, direction
   364     dx, dy, ax, ay, aAngle, dAngle, hAngle, lx, ly: real;  // laser, change
   363     dx, dy, ax, ay, aAngle, dAngle, hAngle, lx, ly: real;  // laser, change
   365     wraps: LongWord; // numbe of wraps for laser in world wrap
   364     wraps: LongWord; // numbe of wraps for laser in world wrap
   366     defaultPos, HatVisible, inWorldBounds: boolean;
   365     defaultPos, HatVisible, inWorldBounds: boolean;
   367     HH: PHedgehog;
   366     HH: PHedgehog;
   368     CurWeapon: PAmmo;
   367     CurWeapon: PAmmo;
   375     if HH^.Unplaced then
   374     if HH^.Unplaced then
   376         exit;
   375         exit;
   377     if (HH^.CurAmmoType = amKnife) and (HH = CurrentHedgehog) then
   376     if (HH^.CurAmmoType = amKnife) and (HH = CurrentHedgehog) then
   378          curhat:= ChefHatTexture
   377          curhat:= ChefHatTexture
   379     else curhat:= HH^.HatTex;
   378     else curhat:= HH^.HatTex;
   380     m:= 1;
       
   381     if ((Gear^.State and gstHHHJump) <> 0) and (HH^.Effects[heArtillery] = 0) then
       
   382         m:= -1;
       
   383     sx:= ox + 1; // this offset is very common
   379     sx:= ox + 1; // this offset is very common
   384     sy:= oy - 3;
   380     sy:= oy - 3;
   385     sign:= hwSign(Gear^.dX);
   381     sign:= hwSign(Gear^.dX);
       
   382     if IsHogFacingLeft(Gear) then
       
   383         hogLR:= -1
       
   384     else
       
   385         hogLR:= 1;
   386 
   386 
   387     if (Gear^.State and gstHHDeath) <> 0 then
   387     if (Gear^.State and gstHHDeath) <> 0 then
   388         begin
   388         begin
   389         DrawSprite(sprHHDeath, ox - 16, oy - 26, Gear^.Pos);
   389         DrawSprite(sprHHDeath, ox - 16, oy - 26, Gear^.Pos);
   390         Tint(HH^.Team^.Clan^.Color shl 8 or $FF);
   390         Tint(HH^.Team^.Clan^.Color shl 8 or $FF);
   478     1: I need to draw the laser from weapon origin to nearest land
   478     1: I need to draw the laser from weapon origin to nearest land
   479     2: I need to start the beam outside the hedgie for attractiveness.
   479     2: I need to start the beam outside the hedgie for attractiveness.
   480     3: I need to extend the beam beyond land.
   480     3: I need to extend the beam beyond land.
   481     This routine perhaps should be pushed into uStore or somesuch instead of continuuing the increase in size of this function.
   481     This routine perhaps should be pushed into uStore or somesuch instead of continuuing the increase in size of this function.
   482     *)
   482     *)
   483             dx:= sign * m * Sin(Gear^.Angle * pi / cMaxAngle);
   483             dx:= hogLR * Sin(Gear^.Angle * pi / cMaxAngle);
   484             dy:= -Cos(Gear^.Angle * pi / cMaxAngle);
   484             dy:= -Cos(Gear^.Angle * pi / cMaxAngle);
   485             if cLaserSighting or cLaserSightingSniper then
   485             if cLaserSighting or cLaserSightingSniper then
   486                 begin
   486                 begin
   487                 lx:= GetLaunchX(HH^.CurAmmoType, sign * m, Gear^.Angle);
   487                 lx:= GetLaunchX(HH^.CurAmmoType, hogLR, Gear^.Angle);
   488                 ly:= GetLaunchY(HH^.CurAmmoType, Gear^.Angle);
   488                 ly:= GetLaunchY(HH^.CurAmmoType, Gear^.Angle);
   489 
   489 
   490                 // ensure we start outside the hedgehog (he's solid after all)
   490                 // ensure we start outside the hedgehog (he's solid after all)
   491                 while abs(lx * lx + ly * ly) < (Gear^.radius * Gear^.radius) do
   491                 while abs(lx * lx + ly * ly) < (Gear^.radius * Gear^.radius) do
   492                     begin
   492                     begin
   523                         tx:= round(lx + ax * (max(LAND_WIDTH,4096) div 2));
   523                         tx:= round(lx + ax * (max(LAND_WIDTH,4096) div 2));
   524                         ty:= round(ly + ay * (max(LAND_WIDTH,4096) div 2));
   524                         ty:= round(ly + ay * (max(LAND_WIDTH,4096) div 2));
   525                         break;
   525                         break;
   526                         end;
   526                         end;
   527 
   527 
   528                     if ((sign*m < 0) and (tx < LeftX)) or ((sign*m > 0) and (tx >= RightX)) then
   528                     if ((hogLR < 0) and (tx < LeftX)) or ((hogLR > 0) and (tx >= RightX)) then
   529                         if (WorldEdge = weWrap) then
   529                         if (WorldEdge = weWrap) then
   530                             // wrap beam
   530                             // wrap beam
   531                             begin
   531                             begin
   532                             if (sign*m) < 0 then
   532                             if hogLR < 0 then
   533                                 lx:= RightX - (ax - (lx - LeftX))
   533                                 lx:= RightX - (ax - (lx - LeftX))
   534                             else
   534                             else
   535                                 lx:= LeftX + (ax - (RightX - lx));
   535                                 lx:= LeftX + (ax - (RightX - lx));
   536                             tx:= round(lx);
   536                             tx:= round(lx);
   537                             inc(wraps);
   537                             inc(wraps);
   551                         break;
   551                         break;
   552                         end;
   552                         end;
   553                     inWorldBounds := ((ty and LAND_HEIGHT_MASK) or (tx and LAND_WIDTH_MASK)) = 0;
   553                     inWorldBounds := ((ty and LAND_HEIGHT_MASK) or (tx and LAND_WIDTH_MASK)) = 0;
   554                     end;
   554                     end;
   555 
   555 
   556                 DrawLineWrapped(hx, hy, tx, ty, 1.0, (sign*m) < 0, wraps, $FF, $00, $00, $C0);
   556                 DrawLineWrapped(hx, hy, tx, ty, 1.0, hogLR < 0, wraps, $FF, $00, $00, $C0);
   557                 end;
   557                 end;
   558 
   558 
   559             // calculate crosshair position
   559             // calculate crosshair position
   560             CrosshairX := Round(hwRound(Gear^.X) + dx * 80 + GetLaunchX(HH^.CurAmmoType, sign * m, Gear^.Angle));
   560             CrosshairX := Round(hwRound(Gear^.X) + dx * 80 + GetLaunchX(HH^.CurAmmoType, hogLR, Gear^.Angle));
   561             CrosshairY := Round(hwRound(Gear^.Y) + dy * 80 + GetLaunchY(HH^.CurAmmoType, Gear^.Angle));
   561             CrosshairY := Round(hwRound(Gear^.Y) + dy * 80 + GetLaunchY(HH^.CurAmmoType, Gear^.Angle));
   562             // crosshair will be rendered in RenderHHGuiExtras
   562             // crosshair will be rendered in RenderHHGuiExtras
   563             CrosshairGear := Gear;
   563             CrosshairGear := Gear;
   564             end;
   564             end;
   565 
   565 
   768         end else
   768         end else
   769 
   769 
   770         if ((Gear^.State and gstHHJumping) <> 0) then
   770         if ((Gear^.State and gstHHJumping) <> 0) then
   771         begin
   771         begin
   772         DrawHedgehog(sx, sy,
   772         DrawHedgehog(sx, sy,
   773             sign*m,
   773             hogLR,
   774             1,
   774             1,
   775             1,
   775             1,
   776             0);
   776             0);
   777         HatVisible:= true;
   777         HatVisible:= true;
   778         defaultPos:= false
   778         defaultPos:= false
   996 
   996 
   997 
   997 
   998         if ((Gear^.State and gstHHJumping) <> 0) then
   998         if ((Gear^.State and gstHHJumping) <> 0) then
   999             begin
   999             begin
  1000             DrawHedgehog(sx, sy,
  1000             DrawHedgehog(sx, sy,
  1001                 sign*m,
  1001                 hogLR,
  1002                 1,
  1002                 1,
  1003                 1,
  1003                 1,
  1004                 0);
  1004                 0);
  1005             defaultPos:= false
  1005             defaultPos:= false
  1006             end;
  1006             end;
  1100                 DrawTextureF(curhat,
  1100                 DrawTextureF(curhat,
  1101                     HatVisibility,
  1101                     HatVisibility,
  1102                     sx,
  1102                     sx,
  1103                     sy - 5,
  1103                     sy - 5,
  1104                     0,
  1104                     0,
  1105                     sign*m,
  1105                     hogLR,
  1106                     32,
  1106                     32,
  1107                     32);
  1107                     32);
  1108                 if (curhat^.w > 64) or ((curhat^.w = 64) and (curhat^.h = 32)) then
  1108                 if (curhat^.w > 64) or ((curhat^.w = 64) and (curhat^.h = 32)) then
  1109                     begin
  1109                     begin
  1110                     if ((curhat^.w = 64) and (curhat^.h = 32)) then
  1110                     if ((curhat^.w = 64) and (curhat^.h = 32)) then
  1115                     DrawTextureF(curhat,
  1115                     DrawTextureF(curhat,
  1116                         HatVisibility,
  1116                         HatVisibility,
  1117                         sx,
  1117                         sx,
  1118                         sy - 5,
  1118                         sy - 5,
  1119                         tx,
  1119                         tx,
  1120                         sign*m,
  1120                         hogLR,
  1121                         32,
  1121                         32,
  1122                         32);
  1122                         32);
  1123                     untint
  1123                     untint
  1124                     end
  1124                     end
  1125                 end
  1125                 end