LuaLibraries.wiki
changeset 246 7b1a6c46c3b5
parent 103 023ff3c709ac
child 500 dc66ea78b36d
--- a/LuaLibraries.wiki	Wed Aug 22 17:14:45 2012 +0000
+++ b/LuaLibraries.wiki	Wed Aug 22 20:08:59 2012 +0000
@@ -110,4 +110,201 @@
 
 == Variable functions ==
 
-to be continued...
\ No newline at end of file
+to be continued...
+
+
+= Animate =
+
+This library provides functions that aid cinematic/cut-scene creation and functions for handling events. 
+
+In order to use it's full potential, the following lines need to be at the beginning of onGameTick.
+
+<code lang="lua">function onGameTick()
+    !AnimUnWait()
+    if !ShowAnimation() == false then
+        return
+    end
+    !ExecuteAfterAnimations()
+    !CheckEvents()
+end</code>
+
+Also, !AnimInit() needs to be called in !onGameInit().
+Each of these functions will be explained below.
+
+== Cinematic Handling ==
+
+=== !ShowAnimation() ===
+<blockquote>Performs the current action in the cinematic and returns true if finished, otherwise false. It needs to be used in onGameTick. Cut-scenes need to be added with !AddAnim(steps).</blockquote>
+
+=== !AddAnim(steps) ===
+<blockquote>Adds steps to the array of animations, where steps is a table with numbers as keys and elements of the following form. Each step is a table having the following keys: func, args, swh.
+
+  * _func_ is the function to be executed. It can be any function that returns false when it needs to be called again in following game ticks (e.g. !AnimMove). It can be one of the cinematic functions. 
+
+  * _args_ is a table containing the arguments that need to be passed to the function given
+
+  * _swh_ is an optional boolean value that defaults to true and denotes whether the current hedgehog should be switched to the hog given as argument.</blockquote>
+Example:
+<code lang="lua">cinem = {
+    {func = AnimSay, args = {myHog, "Snails! SNAILS!", SAY_SAY, 3000}},
+    {func = AnimMove, args = {myhog, "Left", 2000, 0}},
+    {func = AddCaption, swh = false, args = {"But he found no more snails..."}}
+    }
+AddAnim(cinem)</code>
+
+=== !RemoveAnim(steps) ===
+<blockquote>Removes steps from the animations array.</blockquote>
+
+=== !AddSkipFunction(anim, func, args) ===
+<blockquote>Adds _func_ to the array of functions used to skip animations, associating it with _anim_. When the animation is skipped (see below), the function is called with _args_ as arguments.</blockquote>
+Example:
+<code lang="lua">AddSkipFunc(cinem, SkipCinem, {})</code>
+
+=== !RemoveSkipFunction(anim) ===
+<blockquote> Removes the skip function associated with _anim_.</blockquote>
+
+=== !SetAnimSkip(bool) ===
+<blockquote> Sets the state of animation skipping to _bool_. It is useful in case the player is allowed to skip the animation.</blockquote>
+Example:
+<code lang="lua">function onPrecise()
+    if !AnimInProgress() then
+        SetAnimSkip(true)
+    end
+end</code>
+
+=== !AnimInProgress() ===
+<blockquote> Returns true if a cinematic is currently taking place, false otherwise.</blockquote>
+
+=== !ExecuteAfterAnimations() ===
+<blockquote> Calls the functions (added with !AddFunction) that need to be executed after the cinematic. The best location for this function call is in onGameTick.</blockquote>
+
+=== !AddFunction(element) ===
+<blockquote> Adds _element_ to the functions array that are to be called after the cinematic. _element_ is a table with the keys: func, args.</blockquote>
+Example:
+<code lang="lua">AddFunction({func = AfterCinem, args = {2}})</code>
+
+=== !RemoveFunction() ===
+<blockquote> Removes the first function from the aforementioned list.</blockquote>
+
+=== !AnimInit() ===
+<blockquote> Initializes variables used by the other functions. Needs to be called in onGameInit.</blockquote>
+
+=== !AnimUnWait() ===
+<blockquote> Decreases the wait time used by cinematics. It is best called in onGameTick</blockquote>
+
+== Cinematic Functions ==
+
+=== !AnimSwitchHog(gear) ===
+<blockquote> Switches to _gear_ and follows it. </blockquote>
+
+=== !AnimWait(gear, time) ===
+<blockquote> Increases the wait time by _time_. _gear_ is just for compatibility with !ShowAnimation.</blockquote>
+
+=== !AnimSay(gear, text, manner, time) ===
+<blockquote> Calls HogSay with the first three arguments and increses the wait time by _time_.</blockquote>
+Example:
+<code lang="lua">cinem = {
+    {func = AnimSay, args = {gear1, "You're so defensive!", SAY_SAY, 2500}},
+    {func = AnimSay, args = {gear2, "No, I'm not!", SAY_SAY, 2000}}
+   }</code>
+
+=== !AnimSound(gear, sound, time) ===
+<blockquote> Plays the sound _sound_ and increases the wait time by _time_.</blockquote>
+
+=== !AnimTurn(hog, dir) ===
+<blockquote> Makes _hog_ face in direction _dir_, where _dir_ is either "Right" or "Left".</blockquote>
+
+=== !AnimMove(hog, dir, x, y) ===
+<blockquote> Makes _hog_ move in direction _dir_ until either his horizontal coordinate is _x_ or his vertical coordinate is _y_.</blockquote>
+
+=== !AnimJump(hog, jumpType) ===
+<blockquote> Makes _hog_ perform a jump of type _jumpType_, where _jumpType_ is either "long", "high" or "back".</blockquote>
+
+=== !AnimSetGearPosition(gear, x, y, fall) ===
+<blockquote> Sets the position of _gear_ to (x, y). If the optional argument _fall_ is not false then the gear is given a small falling velocity in order to get around exact positioning.</blockquote>
+
+=== !AnimDisappear(gear, x, y) ===
+<blockquote> Teleports the gear to (x, y), adding some effects at the previous position and sounds. Doesn't follow the gear.</blockquote>
+
+=== !AnimOutOfNowhere(gear, x, y) ===
+<blockquote> Teleports the gear to (x, y), adding effects and sounds at the final position. Follows gear.</blockquote>
+
+=== !AnimTeleportGear(gear, x, y) ===
+<blockquote> Teleports the gear to (x, y), adding effects and sounds both at the starting position and the final position. Follows gear.</blockquote>
+
+=== !AnimVisualGear(gear, x, y, vgType, state, critical, follow) ===
+<blockquote> Calls AddVisualGear with arguments second to sixth. If the optional argument _follow_ is true then the gear is followed. _gear_ is for compatibility only.</blockquote>
+
+=== !AnimCaption(gear, text, time) ===
+<blockquote> Adds _text_ as caption and increases wait time by _time_.</blockquote>
+
+=== !AnimCustomFunction(gear, func, args) ===
+<blockquote> Calls the function _func_ with _args_ as arguments. This function is useful, for instance, when the cinematic uses the position of a gear at the moment of execution. If _func_ needs to be called in following game ticks then it should return false.</blockquote>
+Example:
+<code lang="lua">function NeedToTurn(hog1, hog2)
+   if GetX(hog1) < GetX(hog2) then
+      HogTurnLeft(hog1, false)
+      HogTurnLeft(hog2, true)
+   else
+      HogTurnLeft(hog2, false)
+      HogTurnLeft(hog1, true)
+   end
+end
+
+cinem = {{func = AnimCustomFunction, args = {hog1, NeedToTurn, {hog1, hg2}}}}</code>
+
+=== !AnimInsertStepNext(step) ===
+<blockquote> Inserts _step_ after the current step (read: action) in the cinematic array. Useful when an action depends on variables (e.g. positoins). It can be used mostly with !AnimCustomFunction. Note: In case of multiple consecutive calls, steps need to be added in reverse order.</blockquote>
+Example:
+<code lang="lua">function BlowHog(deadHog)
+  AnimInsertStepNext({func = DeleteGear, args = {deadHog}, swh = false}) 
+  AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog), GetY(deadHog), vgtBigExplosion, 0, true}, swh = false})
+  AnimInsertStepNext({func = AnimWait, args = {deadHog, 1200}})
+  AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) + 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
+  AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}})
+  AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) + 10, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
+  AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}})
+  AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 10, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
+  AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}})
+  AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
+end
+cinem = {{func = AnimCustomFunction, args = {liveHog, BlowHog, {deadHog}}}}</code>
+
+== Event Handling ==
+
+Events are pairs of functions that are used to check for various conditions. One of them is for verification and, if it returns true, the second function is called.
+
+=== !AddEvent(condFunc, condArgs, doFunc, doArgs, evType) ===
+<blockquote> Adds the functions _condFunc_ and _doFunc_ to the events list. They get called with the respective args (_condArgs_ and _doArgs_). _condFunc_ will get called in every game tick until it returns true or is removed. Once it returns true, doFunc is called and they are or are not removed from the list, depending on _evType_ (0 for removal, 1 for keeping). An _evType_ of 1 is useful for repeating actions (e.g. every time a hog gets damaged, do something).</blockquote>
+Example:
+<code lang="lua">function CheckPos()
+   return GetX(myHog) > 1500
+end
+function CheckAmmo()
+   return GetAmmoCount(myHog, amGrenade) == 0
+end
+function DoPos()
+   ShowMission("Scooter", "Mover", "Nice Work", 0, 0)
+end
+function DoAmmo()
+   AddAmmo(myHog, amGrenade, 5)
+end
+AddEvent(CheckPos, {}, DoPos, {}, 0) -- Add event that gets removed on completion
+AddEvent(CheckAmmo, {}, DoAmmo, {}, 1) -- Add repeating event</code>
+
+=== !AddNewEvent(condFunc, condArgs, doFunc, doArgs, evType) ===
+<blockquote> Does the same as !AddEvent, but first checks if the event is already in the list so that it isn't added twice.</blockquote>
+
+=== !RemoveEventFunc(cFunc, cArgs) ===
+<blockquote> Removes the event(s) that have _cFunc_ as the condition checking function. If _cArgs_ is not nil then only those events get removed that have _cArgs_ as arguments for _cFunc_, too.</blockquote>
+Example:
+<code lang="lua">AddEvent(condFunc1, condArgs1, doFunc, doArgs)
+AddEvent(condFunc1, condArgs2, doFunc, doArgs)
+AddEvent(condFunc1, condArgs2, doFunc, doArgs)
+AddEvent(condFunc2, condArgs1, doFunc, doArgs)
+AddEvent(condFunc2, condArgs2, doFunc, doArgs)
+RemoveEventFunc(condFunc1) --Removes all three events that have condFunc1
+RemoveEventFunc(condFunc2, condArgs1) --Removes a single event</code>
+
+=== !CheckEvents ===
+<blockquote> Verifies all the condition functions in the events list and calls the respective 'action' functions if the conditions are met. If the evType of a completed event is 0 then it is removed from the list. This function is best placed in onGameTick.</blockquote>
\ No newline at end of file