hedgewars/uGearsHandlersMess.pas
changeset 12382 efa13b925cd8
parent 12311 cdd884397760
child 12573 494d3e1c4810
equal deleted inserted replaced
12381:c80c51f59a98 12382:efa13b925cd8
    45 procedure doStepGrave(Gear: PGear);
    45 procedure doStepGrave(Gear: PGear);
    46 procedure doStepBeeWork(Gear: PGear);
    46 procedure doStepBeeWork(Gear: PGear);
    47 procedure doStepBee(Gear: PGear);
    47 procedure doStepBee(Gear: PGear);
    48 procedure doStepShotIdle(Gear: PGear);
    48 procedure doStepShotIdle(Gear: PGear);
    49 procedure doStepShotgunShot(Gear: PGear);
    49 procedure doStepShotgunShot(Gear: PGear);
    50 procedure spawnBulletTrail(Bullet: PGear);
    50 procedure spawnBulletTrail(Bullet: PGear; bulletX, bulletY: hwFloat);
    51 procedure doStepBulletWork(Gear: PGear);
    51 procedure doStepBulletWork(Gear: PGear);
    52 procedure doStepDEagleShot(Gear: PGear);
    52 procedure doStepDEagleShot(Gear: PGear);
    53 procedure doStepSniperRifleShot(Gear: PGear);
    53 procedure doStepSniperRifleShot(Gear: PGear);
    54 procedure doStepActionTimer(Gear: PGear);
    54 procedure doStepActionTimer(Gear: PGear);
    55 procedure doStepPickHammerWork(Gear: PGear);
    55 procedure doStepPickHammerWork(Gear: PGear);
  1188     if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
  1188     if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
  1189         Gear^.doStep := @doStepShotIdle
  1189         Gear^.doStep := @doStepShotIdle
  1190 end;
  1190 end;
  1191 
  1191 
  1192 ////////////////////////////////////////////////////////////////////////////////
  1192 ////////////////////////////////////////////////////////////////////////////////
  1193 procedure spawnBulletTrail(Bullet: PGear);
  1193 procedure spawnBulletTrail(Bullet: PGear; bulletX, bulletY: hwFloat);
  1194 var oX, oY: hwFloat;
  1194 var oX, oY: hwFloat;
  1195     VGear: PVisualGear;
  1195     VGear: PVisualGear;
  1196 begin
  1196 begin
  1197     if Bullet^.PortalCounter = 0 then
  1197     if Bullet^.PortalCounter = 0 then
  1198         begin
  1198         begin
  1210 
  1210 
  1211         if VGear <> nil then
  1211         if VGear <> nil then
  1212             begin
  1212             begin
  1213             VGear^.X:= hwFloat2Float(ox);
  1213             VGear^.X:= hwFloat2Float(ox);
  1214             VGear^.Y:= hwFloat2Float(oy);
  1214             VGear^.Y:= hwFloat2Float(oy);
  1215             VGear^.dX:= hwFloat2Float(Bullet^.X);
  1215             VGear^.dX:= hwFloat2Float(bulletX);
  1216             VGear^.dY:= hwFloat2Float(Bullet^.Y);
  1216             VGear^.dY:= hwFloat2Float(bulletY);
  1217 
  1217 
  1218             // reached edge of land. assume infinite beam. Extend it way out past camera
  1218             // reached edge of land. assume infinite beam. Extend it way out past camera
  1219             if (hwRound(Bullet^.X) and LAND_WIDTH_MASK <> 0)
  1219             if (hwRound(bulletX) and LAND_WIDTH_MASK <> 0)
  1220             or (hwRound(Bullet^.Y) and LAND_HEIGHT_MASK <> 0) then
  1220             or (hwRound(bulletY) and LAND_HEIGHT_MASK <> 0) then
  1221                     // only extend if not under water
  1221                     // only extend if not under water
  1222                     if not CheckCoordInWater(hwRound(Bullet^.X), hwRound(Bullet^.Y)) then
  1222                     if not CheckCoordInWater(hwRound(bulletX), hwRound(bulletY)) then
  1223                         begin
  1223                         begin
  1224                         VGear^.dX := VGear^.dX + max(LAND_WIDTH,4096) * (VGear^.dX - VGear^.X);
  1224                         VGear^.dX := VGear^.dX + max(LAND_WIDTH,4096) * (VGear^.dX - VGear^.X);
  1225                         VGear^.dY := VGear^.dY + max(LAND_WIDTH,4096) * (VGear^.dY - VGear^.Y);
  1225                         VGear^.dY := VGear^.dY + max(LAND_WIDTH,4096) * (VGear^.dY - VGear^.Y);
  1226                         end;
  1226                         end;
  1227 
  1227 
  1229             end;
  1229             end;
  1230 end;
  1230 end;
  1231 
  1231 
  1232 procedure doStepBulletWork(Gear: PGear);
  1232 procedure doStepBulletWork(Gear: PGear);
  1233 var
  1233 var
  1234     i, x, y: LongWord;
  1234     i, x, y, iInit: LongWord;
  1235     oX, oY, tX, tY, cX, cY: hwFloat;
  1235     oX, oY, tX, tY, tDx, tDy: hwFloat;
  1236     VGear: PVisualGear;
  1236     VGear: PVisualGear;
  1237 begin
  1237 begin
  1238     AllInactive := false;
  1238     AllInactive := false;
  1239     inc(Gear^.Timer);
  1239     inc(Gear^.Timer);
  1240     i := 80;
  1240     iInit := 80;
       
  1241     i := iInit;
  1241     oX := Gear^.X;
  1242     oX := Gear^.X;
  1242     oY := Gear^.Y;
  1243     oY := Gear^.Y;
  1243     repeat
  1244     repeat
  1244         Gear^.X := Gear^.X + Gear^.dX;
  1245         Gear^.X := Gear^.X + Gear^.dX;
  1245         Gear^.Y := Gear^.Y + Gear^.dY;
  1246         Gear^.Y := Gear^.Y + Gear^.dY;
  1246         tX:= Gear^.X;
  1247         tX:= Gear^.X;
  1247         tY:= Gear^.Y;
  1248         tY:= Gear^.Y;
       
  1249         tDx:= Gear^.dX;
       
  1250         tDy:= Gear^.dY;
  1248         if (Gear^.PortalCounter < 30) and WorldWrap(Gear) then
  1251         if (Gear^.PortalCounter < 30) and WorldWrap(Gear) then
  1249             begin
  1252             begin
  1250             cX:= Gear^.X;
  1253             DrawTunnel(oX, oY, tDx, tDy, iInit + 2 - i, 1);
  1251             cY:= Gear^.Y;
  1254             SpawnBulletTrail(Gear, tX, tY);
  1252             Gear^.X:= tX;
  1255             iInit:= i;
  1253             Gear^.Y:= tY;
  1256             oX:= Gear^.X;
  1254             SpawnBulletTrail(Gear);
  1257             oY:= Gear^.Y;
  1255             Gear^.X:= cX;
       
  1256             Gear^.Y:= cY;
       
  1257             inc(Gear^.PortalCounter);
  1258             inc(Gear^.PortalCounter);
  1258             Gear^.Elasticity:= Gear^.X;
  1259             Gear^.Elasticity:= Gear^.X;
  1259             Gear^.Friction:= Gear^.Y;
  1260             Gear^.Friction:= Gear^.Y;
  1260             SpawnBulletTrail(Gear);
  1261             SpawnBulletTrail(Gear, Gear^.X, Gear^.Y);
  1261             end;
  1262             end;
  1262         x := hwRound(Gear^.X);
  1263         x := hwRound(Gear^.X);
  1263         y := hwRound(Gear^.Y);
  1264         y := hwRound(Gear^.Y);
  1264 
  1265 
  1265         if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] <> 0) then
  1266         if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] <> 0) then
  1288         dec(i)
  1289         dec(i)
  1289     until (i = 0) or (Gear^.Damage > Gear^.Health) or ((Gear^.State and gstDrowning) <> 0);
  1290     until (i = 0) or (Gear^.Damage > Gear^.Health) or ((Gear^.State and gstDrowning) <> 0);
  1290 
  1291 
  1291     if Gear^.Damage > 0 then
  1292     if Gear^.Damage > 0 then
  1292         begin
  1293         begin
  1293         DrawTunnel(oX, oY, Gear^.dX, Gear^.dY, 82 - i, 1);
  1294         DrawTunnel(oX, oY, Gear^.dX, Gear^.dY, iInit + 2 - i, 1);
  1294         dec(Gear^.Health, Gear^.Damage);
  1295         dec(Gear^.Health, Gear^.Damage);
  1295         Gear^.Damage := 0
  1296         Gear^.Damage := 0
  1296         end;
  1297         end;
  1297 
  1298 
  1298     if ((Gear^.State and gstDrowning) <> 0) and (Gear^.Health > 0) then
  1299     if ((Gear^.State and gstDrowning) <> 0) and (Gear^.Health > 0) then
  1329                     begin
  1330                     begin
  1330                     VGear^.Angle := DxDy2Angle(-Gear^.dX, Gear^.dY);
  1331                     VGear^.Angle := DxDy2Angle(-Gear^.dX, Gear^.dY);
  1331                     end;
  1332                     end;
  1332                 end;
  1333                 end;
  1333 
  1334 
  1334             spawnBulletTrail(Gear);
  1335             spawnBulletTrail(Gear, Gear^.X, Gear^.Y);
  1335             Gear^.doStep := @doStepShotIdle
  1336             Gear^.doStep := @doStepShotIdle
  1336             end;
  1337             end;
  1337 end;
  1338 end;
  1338 
  1339 
  1339 procedure doStepDEagleShot(Gear: PGear);
  1340 procedure doStepDEagleShot(Gear: PGear);
  4428             end;
  4429             end;
  4429 
  4430 
  4430         if (iterator^.Kind = gtDEagleShot) or (iterator^.Kind = gtSniperRifleShot) then
  4431         if (iterator^.Kind = gtDEagleShot) or (iterator^.Kind = gtSniperRifleShot) then
  4431             begin
  4432             begin
  4432             // draw bullet trail
  4433             // draw bullet trail
  4433             spawnBulletTrail(iterator);
  4434             spawnBulletTrail(iterator, iterator^.X, iterator^.Y);
  4434             // the bullet can now hurt the hog that fired it
  4435             // the bullet can now hurt the hog that fired it
  4435             iterator^.Data:= nil;
  4436             iterator^.Data:= nil;
  4436             end;
  4437             end;
  4437 
  4438 
  4438         // calc gear offset in portal vector direction
  4439         // calc gear offset in portal vector direction