Change key check lua command names to more consistent ones

This commit is contained in:
Lwmte 2022-08-06 16:59:43 +03:00
parent 57b2e2c013
commit e89ddf4452
5 changed files with 121 additions and 15 deletions

View file

@ -147,11 +147,11 @@
<td class="summary">Play sound effect</td>
</tr>
<tr>
<td class="name" ><a href="#KeyHeld">KeyHeld(action)</a></td>
<td class="name" ><a href="#KeyIsHeld">KeyIsHeld(action)</a></td>
<td class="summary">Check if particular action key is held</td>
</tr>
<tr>
<td class="name" ><a href="#KeyHit">KeyHit(action)</a></td>
<td class="name" ><a href="#KeyIsHit">KeyIsHit(action)</a></td>
<td class="summary">Check if particular action key was hit (once)</td>
</tr>
<tr>
@ -542,8 +542,8 @@ To be used with <a href="../2 classes/Strings.DisplayString.html#DisplayString:G
</dd>
<dt>
<a name = "KeyHeld"></a>
<strong>KeyHeld(action)</strong>
<a name = "KeyIsHeld"></a>
<strong>KeyIsHeld(action)</strong>
</dt>
<dd>
Check if particular action key is held
@ -563,8 +563,8 @@ To be used with <a href="../2 classes/Strings.DisplayString.html#DisplayString:G
</dd>
<dt>
<a name = "KeyHit"></a>
<strong>KeyHit(action)</strong>
<a name = "KeyIsHit"></a>
<strong>KeyIsHit(action)</strong>
</dt>
<dd>
Check if particular action key was hit (once)

View file

@ -1,5 +1,7 @@
-- Place in this LUA script all the levels of your game
-- Title is mandatory and must be the first level
-- Title is mandatory and must be the first level.
-- Shorten some of the internal data types.
local Flow = TEN.Flow
local Level = Flow.Level
@ -12,8 +14,14 @@ local ItemAction = Flow.ItemAction
Flow.SetIntroImagePath("Screens\\Main.png")
Flow.SetTitleScreenImagePath("Screens\\Title.jpg")
-- Flow.SetFarView sets global far view distance in blocks.
-- It will be overwritten by level.farView value, if it is specified.
Flow.SetFarView(20)
--------------------------------------------------
-- Title level
title = Level.new()
@ -25,7 +33,10 @@ title.loadScreenFile = "Screens\\Main.png"
Flow.AddLevel(title)
--------------------------------------------------
-- First test level
test = Level.new()
test.nameKey = "level_test"
@ -33,13 +44,20 @@ test.scriptFile = "Scripts\\TestLevel.lua"
test.ambientTrack = "108"
test.levelFile = "Data\\TestLevel.ten"
test.loadScreenFile = "Screens\\rome.jpg"
-- 0 is no weather, 1 is rain, 2 is snow.
-- Strength varies from 0 to 1 (floating-point value, e.g. 0.5 means half-strength).
test.weather = 0
test.weatherStrength = 1
test.horizon = true
test.farView = 20
test.layer1 = Flow.SkyLayer.new(Color.new(255, 0, 0), 15)
test.fog = Flow.Fog.new(Color.new(0, 0, 0), 12, 20)
-- Presets for inventory item placement.
test.objects = {
InventoryItem.new(
"tut1_ba_cartouche1",

View file

@ -1,5 +1,93 @@
-- Test level script file
local Util = require("Util")
Util.ShortenTENCalls()
LevelFuncs.OnLoad = function() end
LevelFuncs.OnSave = function() end
LevelFuncs.OnControlPhase = function() end
LevelFuncs.OnEnd = function() end
-- An example function which prints a string and leaves it on screen for 1 second.
-- Argument should be typed in TE trigger manager window's argument text field.
LevelFuncs.PrintText = function(Triggerer, Argument)
local TestText = DisplayString(Argument, 100, 100, Color.new(250,250,250))
ShowString(TestText, 1)
end
-- Another example function which emits rotating electric halo around Lara, when
-- action key is pressed.
local currentX = 0.0
local currentY = 0.0
LevelFuncs.OnControlPhase = function()
-- This is a list of all possible keys which can be checked for their pushed/not pushed state.
-- Later we will move them to separate internal file or make them internal TEN constants.
local Keys =
{
Forward = 0,
Back = 1,
Left = 2,
Right = 3,
Crouch = 4,
Sprint = 5,
Walk = 6,
Jump = 7,
Action = 8,
Draw = 9,
Flare = 10,
Look = 11,
Roll = 12,
Inventory = 13,
Pause = 14,
StepLeft = 15,
StepRight = 16
}
-- Your Lara in your level should have Lua name "lara".
local pos = GetMoveableByName("lara"):GetJointPosition(0)
local color = math.random(200, 255)
local vel = Vec3(0, 0, 0)
local rot = math.random(60, 80) * math.random(-1, 1)
local circleLength = 3.14 * 2.0
currentX = currentX + 0.2
currentY = currentY + 0.1
if (currentX > circleLength) then
currentX = currentX - circleLength;
end
if (currentY > circleLength) then
currentY = currentY - circleLength;
end
local partX = math.cos(currentX) * 256
local partZ = math.sin(currentX) * 256
local partY = math.sin(currentY) * 384
pos.x = pos.x + partX
pos.y = pos.y + partY
pos.z = pos.z + partZ
if (KeyIsHit(Keys.Action)) then
Misc.PlaySound(198, pos)
Misc.Vibrate(0.5, 0.1)
end
if (KeyIsHeld(Keys.Action)) then
Misc.PlaySound(197, pos)
Effects.EmitParticle(pos, vel, 5, 1, rot, Color.new(color * 0.5, color * 0.5, color), Color.new(color * 0.2, color * 0.1, color), 2, 16, 64, 32, false, false)
Effects.EmitLight(pos, Color.new(color * 0.5, color * 0.5, color), 7)
end
end

View file

@ -145,8 +145,8 @@ static constexpr char ScriptReserved_SetCineBars[] = "SetCineBars";
static constexpr char ScriptReserved_SetFOV[] = "SetFOV";
static constexpr char ScriptReserved_GetFOV[] = "GetFOV";
static constexpr char ScriptReserved_KeyHeld[] = "KeyHeld";
static constexpr char ScriptReserved_KeyHit[] = "KeyHit";
static constexpr char ScriptReserved_KeyIsHeld[] = "KeyIsHeld";
static constexpr char ScriptReserved_KeyIsHit[] = "KeyIsHit";
static constexpr char ScriptReserved_KeyPush[] = "KeyPush";
static constexpr char ScriptReserved_KeyClear[] = "KeyClear";

View file

@ -125,12 +125,12 @@ namespace Misc
SoundEffect(id, p.has_value() ? &PHD_3DPOS(p.value().x, p.value().y, p.value().z) : nullptr, SoundEnvironment::Always);
}
static bool KeyHeld(int actionIndex)
static bool KeyIsHeld(int actionIndex)
{
return (TrInput & (1 << actionIndex)) != 0;
}
static bool KeyHit(int actionIndex)
static bool KeyIsHit(int actionIndex)
{
return (DbInput & (1 << actionIndex)) != 0;
}
@ -229,14 +229,14 @@ namespace Misc
table_misc.set_function(ScriptReserved_PlaySound, &PlaySoundEffect);
/// Check if particular action key is held
//@function KeyHeld
//@function KeyIsHeld
//@tparam int action mapping index to check
table_misc.set_function(ScriptReserved_KeyHeld, &KeyHeld);
table_misc.set_function(ScriptReserved_KeyIsHeld, &KeyIsHeld);
/// Check if particular action key was hit (once)
//@function KeyHit
//@function KeyIsHit
//@tparam int action mapping index to check
table_misc.set_function(ScriptReserved_KeyHit, &KeyHit);
table_misc.set_function(ScriptReserved_KeyIsHit, &KeyIsHit);
/// Emulate pushing of a certain action key
//@function KeyPush