hedgewars/uGears.pas
changeset 2811 4cad87e11bf6
parent 2802 28cd5b87bce9
child 2813 25213bcab42f
equal deleted inserted replaced
2810:3bc9c723731d 2811:4cad87e11bf6
   108                                   dLen: hwFloat;
   108                                   dLen: hwFloat;
   109                                   b: boolean;
   109                                   b: boolean;
   110                                   end;
   110                                   end;
   111                 rounded: array[0..MAXROPEPOINTS + 2] of TVertex2f;
   111                 rounded: array[0..MAXROPEPOINTS + 2] of TVertex2f;
   112                 end;
   112                 end;
   113     ropeIconSurf: PSDL_Surface;
   113  
   114     ropeIconTex: PTexture;
       
   115     ropeIconIndex: LongInt;
       
   116 
       
   117 procedure DeleteGear(Gear: PGear); forward;
   114 procedure DeleteGear(Gear: PGear); forward;
   118 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward;
   115 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward;
   119 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
   116 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
   120 //procedure AmmoFlameWork(Ammo: PGear); forward;
   117 //procedure AmmoFlameWork(Ammo: PGear); forward;
   121 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward;
   118 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward;
   815 	if t^.Kind = gtHedgehog then t^.Active:= true;
   812 	if t^.Kind = gtHedgehog then t^.Active:= true;
   816 	t:= t^.NextGear
   813 	t:= t^.NextGear
   817 	end
   814 	end
   818 end;
   815 end;
   819 
   816 
   820 procedure RenderAltWeapon(Gear: PGear; sx, sy: LongInt);
   817 procedure DrawAltWeapon(Gear: PGear; sx, sy: LongInt);
   821 var r1, r2: TSDL_Rect;
       
   822 begin
   818 begin
   823 with PHedgehog(Gear^.Hedgehog)^ do
   819 with PHedgehog(Gear^.Hedgehog)^ do
   824 	begin
   820 	begin
   825 	if ropeIconIndex <> ord(Ammo^[CurSlot, CurAmmo].AmmoType) then
   821 	if not (((Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and ((Gear^.State and gstAttacked) = 0)) then
   826 		begin
   822 		exit;
   827 		if ropeIconTex <> nil then
   823 	
   828 			FreeTexture(ropeIconTex);
   824 	//r.x:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) shr 5) * 32;
   829 		r1.x:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) shr 5) * 32;
   825 	//r.y:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) mod 32) * 32;
   830 		r1.y:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) mod 32) * 32;
   826 	//r.w:= 32;
   831 		r1.w:= 32;
   827 	//r.h:= 32;
   832 		r1.h:= 32;
   828 	DrawTexture(sx + 16, sy + 16, ropeIconTex);
   833 		r2.x:= 2;
   829 	//DrawFromRect(sx + 18, sy + 18, @r, SpritesData[sprAMAmmos].Texture);
   834 		r2.y:= 2;
   830 	DrawTextureF(SpritesData[sprAMAmmos].Texture, 0.75, sx + 30, sy + 30, ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1, 1, 32, 32);
   835 		r2.w:= 32;
       
   836 		r2.h:= 32;
       
   837 		SDL_UpperBlit(SpritesData[sprAMAmmos].Surface, @r1, ropeIconSurf, @r2);
       
   838 		ropeIconTex:= Surface2Tex(ropeIconSurf, true);
       
   839 		ropeIconIndex:= ord(Ammo^[CurSlot, CurAmmo].AmmoType)
       
   840 		end;
       
   841 	// render the rope weapon icon (if weapon is alt useable)
       
   842 	if (ropeIconTex <> nil) and ((Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and ((Gear^.State and gstAttacked) = 0) then
       
   843 		DrawTexture(sx + 16, sy + 16, ropeIconTex)
       
   844 	end;
   831 	end;
   845 end;
   832 end;
   846 
   833 
   847 procedure DrawHH(Gear: PGear);
   834 procedure DrawHH(Gear: PGear);
   848 var i, t: LongInt;
   835 var i, t: LongInt;
  1011 						1,
   998 						1,
  1012 						0,
   999 						0,
  1013 						DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX) + dAngle);
  1000 						DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX) + dAngle);
  1014 				with PHedgehog(Gear^.Hedgehog)^ do
  1001 				with PHedgehog(Gear^.Hedgehog)^ do
  1015 					if (HatTex <> nil) then
  1002 					if (HatTex <> nil) then
  1016 						DrawRotatedTextureF(HatTex, 1.0, -1.0, -6.0, sx, sy, 0, i, 32,
  1003 						DrawRotatedTextureF(HatTex, 1.0, -1.0, -6.0, sx, sy, 0, i, 32, 32,
  1017 							i*DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX) + hAngle);
  1004 							i*DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX) + hAngle);
  1018 				
  1005 				
  1019 				RenderAltWeapon(Gear, sx, sy);
  1006 				DrawAltWeapon(Gear, sx, sy);
  1020 				defaultPos:= false
  1007 				defaultPos:= false
  1021 				end;
  1008 				end;
  1022 			gtBlowTorch: begin
  1009 			gtBlowTorch: begin
  1023 				DrawRotated(sprBlowTorch, hx, hy, hwSign(Gear^.dX), aangle);
  1010 				DrawRotated(sprBlowTorch, hx, hy, hwSign(Gear^.dX), aangle);
  1024 				DrawHedgehog(sx, sy,
  1011 				DrawHedgehog(sx, sy,
  1207 						HatVisibility,
  1194 						HatVisibility,
  1208 						sx,
  1195 						sx,
  1209 						hwRound(Gear^.Y) - 8 + WorldDy,
  1196 						hwRound(Gear^.Y) - 8 + WorldDy,
  1210 						0,
  1197 						0,
  1211 						hwSign(Gear^.dX),
  1198 						hwSign(Gear^.dX),
       
  1199 						32,
  1212 						32);
  1200 						32);
  1213 		end;
  1201 		end;
  1214 
  1202 
  1215 		case amt of
  1203 		case amt of
  1216 			amBaseballBat: DrawRotated(sprHandBaseball,
  1204 			amBaseballBat: DrawRotated(sprHandBaseball,
  1273 				HatVisibility,
  1261 				HatVisibility,
  1274 				sx,
  1262 				sx,
  1275 				hwRound(Gear^.Y) - 8 + WorldDy,
  1263 				hwRound(Gear^.Y) - 8 + WorldDy,
  1276 				(RealTicks div 128 + Gear^.Pos) mod 19,
  1264 				(RealTicks div 128 + Gear^.Pos) mod 19,
  1277 				hwSign(Gear^.dX),
  1265 				hwSign(Gear^.dX),
       
  1266 				32,
  1278 				32)
  1267 				32)
  1279 		else
  1268 		else
  1280 			DrawTextureF(HatTex,
  1269 			DrawTextureF(HatTex,
  1281 				HatVisibility,
  1270 				HatVisibility,
  1282 				sx,
  1271 				sx,
  1283 				hwRound(Gear^.Y) - 8 + WorldDy,
  1272 				hwRound(Gear^.Y) - 8 + WorldDy,
  1284 				0,
  1273 				0,
  1285 				hwSign(Gear^.dX)*m,
  1274 				hwSign(Gear^.dX)*m,
       
  1275 				32,
  1286 				32);
  1276 				32);
  1287 	end;
  1277 	end;
  1288 if (Gear^.State and gstHHDriven) <> 0 then
  1278 if (Gear^.State and gstHHDriven) <> 0 then
  1289     begin
  1279     begin
  1290 (*    if (CurAmmoGear = nil) then
  1280 (*    if (CurAmmoGear = nil) then
  1301 	                   DrawSprite(sprJetpack, sx-32, sy-32, 0);
  1291 	                   DrawSprite(sprJetpack, sx-32, sy-32, 0);
  1302 	                   if (CurAmmoGear^.MsgParam and gm_Up) <> 0 then DrawSprite(sprJetpack, sx-32, sy-32, 1);
  1292 	                   if (CurAmmoGear^.MsgParam and gm_Up) <> 0 then DrawSprite(sprJetpack, sx-32, sy-32, 1);
  1303 	                   if (CurAmmoGear^.MsgParam and gm_Left) <> 0 then DrawSprite(sprJetpack, sx-32, sy-32, 2);
  1293 	                   if (CurAmmoGear^.MsgParam and gm_Left) <> 0 then DrawSprite(sprJetpack, sx-32, sy-32, 2);
  1304 	                   if (CurAmmoGear^.MsgParam and gm_Right) <> 0 then DrawSprite(sprJetpack, sx-32, sy-32, 3);
  1294 	                   if (CurAmmoGear^.MsgParam and gm_Right) <> 0 then DrawSprite(sprJetpack, sx-32, sy-32, 3);
  1305                        if CurAmmoGear^.Tex <> nil then DrawCentered(sx, sy - 40, CurAmmoGear^.Tex);
  1295                        if CurAmmoGear^.Tex <> nil then DrawCentered(sx, sy - 40, CurAmmoGear^.Tex);
  1306 					   RenderAltWeapon(Gear, sx, sy)
  1296 					   DrawAltWeapon(Gear, sx, sy)
  1307                        end;
  1297                        end;
  1308             end;
  1298             end;
  1309         end
  1299         end
  1310     end;
  1300     end;
  1311 
  1301 
  1555                                         end;
  1545                                         end;
  1556                          end;
  1546                          end;
  1557         gtDynamite: DrawSprite2(sprDynamite, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, Gear^.Tag and 1, Gear^.Tag shr 1);
  1547         gtDynamite: DrawSprite2(sprDynamite, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, Gear^.Tag and 1, Gear^.Tag shr 1);
  1558      gtClusterBomb: DrawRotated(sprClusterBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle);
  1548      gtClusterBomb: DrawRotated(sprClusterBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle);
  1559          gtCluster: DrawSprite(sprClusterParticle, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, 0);
  1549          gtCluster: DrawSprite(sprClusterParticle, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, 0);
  1560            gtFlame: DrawTextureF(SpritesData[sprFlame].Texture, 1 / (Gear^.Tag mod 3 + 2), hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, (GameTicks div 128 + LongWord(Gear^.Tag)) mod 8, 1, 8);
  1550            gtFlame: DrawTextureF(SpritesData[sprFlame].Texture, 2 / (Gear^.Tag mod 3 + 2), hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, (GameTicks div 128 + LongWord(Gear^.Tag)) mod 8, 1, 16, 16);
  1561        gtParachute: begin
  1551        gtParachute: begin
  1562 					DrawSprite(sprParachute, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 48 + WorldDy, 0);
  1552 					DrawSprite(sprParachute, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 48 + WorldDy, 0);
  1563 					RenderAltWeapon(Gear, hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy)
  1553 					DrawAltWeapon(Gear, hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy)
  1564 					end;
  1554 					end;
  1565        gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 0)
  1555        gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 0)
  1566                                      else DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 1);
  1556                                      else DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 1);
  1567          gtAirBomb: DrawRotated(sprAirBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
  1557          gtAirBomb: DrawRotated(sprAirBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
  1568         gtTeleport: begin
  1558         gtTeleport: begin
  2145 	gear:= gear^.NextGear
  2135 	gear:= gear^.NextGear
  2146 	end
  2136 	end
  2147 end;
  2137 end;
  2148 
  2138 
  2149 procedure init_uGears;
  2139 procedure init_uGears;
  2150 var r: TSDL_Rect;
       
  2151 begin
  2140 begin
  2152 	CurAmmoGear:= nil;
  2141 	CurAmmoGear:= nil;
  2153 	GearsList:= nil;
  2142 	GearsList:= nil;
  2154 	KilledHHs:= 0;
  2143 	KilledHHs:= 0;
  2155 	SuddenDeathDmg:= false;
  2144 	SuddenDeathDmg:= false;
  2157 	TrainingTargetGear:= nil;
  2146 	TrainingTargetGear:= nil;
  2158 	skipFlag:= false;
  2147 	skipFlag:= false;
  2159 	
  2148 	
  2160 	AllInactive:= false;
  2149 	AllInactive:= false;
  2161 	PrvInactive:= false;
  2150 	PrvInactive:= false;
  2162 	
       
  2163 	ropeIconSurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 36, 36, 32, RMask, GMask, BMask, AMask);
       
  2164 	r.x:= 0;
       
  2165 	r.y:= 0;
       
  2166 	r.w:= 36;
       
  2167 	r.h:= 36;
       
  2168 	DrawRoundRect(@r, cWhiteColor, cNearBlackColor, ropeIconSurf, true);
       
  2169 end;
  2151 end;
  2170 
  2152 
  2171 procedure free_uGears;
  2153 procedure free_uGears;
  2172 begin
  2154 begin
  2173 	FreeGearsList();
  2155 	FreeGearsList();
  2174 	if ropeIconTex <> nil then
       
  2175 		FreeTexture(ropeIconTex);
       
  2176 	if ropeIconSurf <> nil then
       
  2177 		SDL_FreeSurface(ropeIconSurf);
       
  2178 end;
  2156 end;
  2179 
  2157 
  2180 end.
  2158 end.