Helpful/Cool LunaLua Codes Thread
Posted: Mon Mar 14, 2016 8:15 pm
At the suggestion of Quill...
Have any basic/cool LunaLua code you want to share? Post it here! Let everyone know that you made something cool with Lua and stuff. Feel free to give small advice to other posters in this thread if their code is inefficent, or they could make their code more easily configurable, etc., as well.
To kick this thread off, here's some simple, configurable, commented code for a multi jump:
There's even a sound effect and a fancy little boost effect and everything. You can change numberOfJumps to however many jumps you want your player to have, and you can change jump height to whatever you want.
Have any basic/cool LunaLua code you want to share? Post it here! Let everyone know that you made something cool with Lua and stuff. Feel free to give small advice to other posters in this thread if their code is inefficent, or they could make their code more easily configurable, etc., as well.
To kick this thread off, here's some simple, configurable, commented code for a multi jump:
Code: Select all
-- Configuration
local numberOfJumps = 2;
local jumpHeight = -11;
-- Setup
local jumpCounter = numberOfJumps;
-- Reset jump counter upon touching the floor
function onTick()
if player:mem(0x146,FIELD_WORD) == 2 then
jumpCounter = numberOfJumps;
end
end
-- Actual double jump
function onKeyDown(keycode)
if keycode == KEY_JUMP and jumpCounter > 0 then
-- Subtract jump counter
jumpCounter = jumpCounter - 1;
-- Launch player
player.speedY = jumpHeight;
-- Play sound effect and do dust effect
if player:mem(0x146,FIELD_WORD) == 0 then
playSFX(1)
for i=-3,3,6 do
local smoke = Animation.spawn(74,player.x+(player.width/2),player.y+player.height)
smoke.speedX = i;
smoke.speedY = 4;
end
end
end
end