Animate library: Add new parameter maxMoveTime to AnimMove
authorWuzzy <Wuzzy2@mail.ru>
Thu, 26 Oct 2017 22:40:17 +0200
changeset 12783 cb29ec085767
parent 12782 255c2978b366
child 12784 1f8a62d1609d
Animate library: Add new parameter maxMoveTime to AnimMove
ChangeLog.txt
share/hedgewars/Data/Scripts/Animate.lua
--- a/ChangeLog.txt	Thu Oct 26 21:14:55 2017 +0200
+++ b/ChangeLog.txt	Thu Oct 26 22:40:17 2017 +0200
@@ -380,6 +380,7 @@
  + Locale library: loc_noop -- Mark string for translation but don't translate it
  + Animate library: AnimInit([startAnimating]) -- New parameter startAnimating: if true, will start game in cinematic mode with most controls disabled. Must play an animation after that
  + Animate library: AnimSetInputMask(extraInputMask) -- Set input mask in a manner comptible with the Animate library
+ + Animate library: AnimMove(gear, dir, posx, posy, [maxMoveTime]) -- new optional parameter maxMoveTime. If hog did not reach its destination within maxMoveTime milliseconds, animation stops and hog is just teleported there
  + Gear values: “Boom” -- used to modify explosion size and/or damage for most gears
  + 8 overridable custom sprites/sounds: sprCustom1-sprCustom8, sndCustom1-sndCustom8
  * Fixed call: HideHog(gear) -- Fix crash when gear is invalid. Returns true on success or false otherwise
--- a/share/hedgewars/Data/Scripts/Animate.lua	Thu Oct 26 21:14:55 2017 +0200
+++ b/share/hedgewars/Data/Scripts/Animate.lua	Thu Oct 26 22:40:17 2017 +0200
@@ -1,4 +1,5 @@
 local animPos, lastx, lasty, jumpTypes, jumpTimes, moveDirs, jumpStarted
+local moveTime = 0
 local backJumped, jTimer, awTime, globalWait, stageEvents, seNum, curEvent
 local needtoDecrease
 local AnimList, AnimListNum
@@ -166,13 +167,22 @@
   return true
 end
 
-function AnimMove(gear, dir, posx, posy)
+function AnimMove(gear, dir, posx, posy, maxMoveTime)
   dirr = moveDirs[dir]
   SetGearMessage(gear, dirr)
-  if GetX(gear) == posx or GetY(gear) == posy then
+  moveTime = moveTime + 1
+  if (maxMoveTime and moveTime > maxMoveTime) then
+    SetGearMessage(gear, 0)
+    SetGearPosition(gear, posx, posy)
+    lastx = GetX(gear)
+    lasty = GetY(gear)
+    moveTime = 0
+    return true
+  elseif GetX(gear) == posx or GetY(gear) == posy then
     SetGearMessage(gear, 0)
     lastx = GetX(gear)
     lasty = GetY(gear)
+    moveTime = 0
     return true
   end
   return false