Page 1 of 1

flung.lua - See enemies tumbling down!

Posted: Mon Jun 03, 2024 2:05 am
by Cloud Devil
A silly library made to make NPCs tumble down when thrown, or launched through a cannon.

Download:
https://drive.google.com/file/d/1LzdV4x ... drive_link

EDIT: Seems that there's a problem in my drive. Anyway, here's the code. Just copy these into a lua file and then name it flung.lua
Spoiler: show
--A silly library if you want to see npcs tumbling down
--Rotation code based from Saturnyoshi & Emral's Grrrol

local flung = {}
local npcDrawn = nil

local npcManager = require("npcManager")
local npcutils = require("npcs/npcutils")

function flung.onInitAPI()
registerEvent(flung, "onDraw")
registerEvent(flung, "onTick")
end

function drawNPCFrame(id, frame, x, y, angle, direction)
local settings = npcManager.getNpcSettings(id)
local priority = -45

local myWidth = settings.gfxwidth
local myHeight = settings.gfxheight

if settings.gfxwidth == 0 then
myWidth = settings.width
end
if settings.gfxwidth == 0 then
myHeight = settings.height
end

if settings.foreground then
priority = -15
end

local img = Graphics.sprites.npc[id].img
imgHeight = img.height
imgWidth = img.width

local npcDrawn = Sprite.box({
texture = img,
width = myWidth,
height = myHeight,
x = x + settings.gfxoffsetx + (myWidth * 0.5),
y = y + settings.gfxoffsety + (myHeight * 0.5),
rotation = angle,
pivot = Sprite.align.CENTER,
frames = imgHeight / myHeight,
frame = frame,
})

npcDrawn.x = x + settings.gfxoffsetx + (myWidth * 0.5)
npcDrawn.y = y + settings.gfxoffsety + (myHeight * 0.5)

if direction > 0 then
npcDrawn.scale = vector.v2(-1, 1)
end

npcDrawn:draw({
align = Sprite.align.CENTER,
frame = frame,
sceneCoords = true,
priority = priority,
})
end

function flung.onDraw()
for _,fallingNPC in ipairs(NPC.get()) do
if fallingNPC.isProjectile then
local config = npcManager.getNpcSettings(fallingNPC.id)
local data = fallingNPC.data
local tid = fallingNPC.id

local tdir = fallingNPC.data._basegame.angle or 0

if tdir == nil then return end

local myWidth = config.gfxwidth
local myHeight = config.gfxheight

if config.gfxwidth == 0 then
myWidth = config.width
end
if config.gfxwidth == 0 then
myHeight = config.height
end

local drawX = fallingNPC.x + 0.5 * fallingNPC.width - 0.5 * myWidth
local drawY = fallingNPC.y + fallingNPC.height - myHeight

npcutils.hideNPC(fallingNPC)

drawNPCFrame(tid, fallingNPC.frame, drawX, drawY, tdir, fallingNPC.direction)
end
end
end

function flung.onTick()
for _,fallingNPC in ipairs(NPC.get()) do
if fallingNPC.isProjectile then
local data = fallingNPC.data._basegame
-- Rotation
local fallMagnitude = fallingNPC.speedX
if fallingNPC.speedX == 0 then
fallMagnitude = fallingNPC.direction
end
if fallingNPC:mem(0x12A, FIELD_WORD) > 0 and not fallingNPC.isHidden and fallingNPC:mem(0x124,FIELD_WORD) ~= 0 and fallingNPC:mem(0x12C,FIELD_WORD) == 0 then
if data.angle == nil then
data.angle = 0
data.timer = 0
else
data.angle = data.angle + (fallMagnitude / (0.5 * fallingNPC.height)) * 0.5 * 180 / math.pi
if fallingNPC:mem(0x12C, FIELD_WORD) > 0 then
data.angle = data.angle + 15
end
end
if fallingNPC:mem(0x12C, FIELD_WORD) ~= 0 then return end
data.timer = data.timer + fallingNPC.direction * fallingNPC.speedX
end
end
end
end

return flung

Re: flung.lua - See enemies tumbling down!

Posted: Mon Jun 03, 2024 1:03 pm
by mariobrigade2018
Gif pls.

Re: flung.lua - See enemies tumbling down!

Posted: Tue Jun 04, 2024 10:03 pm
by MarioChallengerX2
Hey. Why does the download link say it's in violation of Google's ToS?

Re: flung.lua - See enemies tumbling down!

Posted: Tue Jun 04, 2024 10:10 pm
by mariobrigade2018
MarioChallengerX2 wrote:
Tue Jun 04, 2024 10:03 pm
Hey. Why does the download link say it's in violation of Google's ToS?
WHAT?

Added in 10 hours 47 minutes 5 seconds:
Cloud Devil wrote:
Mon Jun 03, 2024 2:05 am
Ping
Still need GIF pls.

Re: flung.lua - See enemies tumbling down!

Posted: Tue Jun 11, 2024 4:08 pm
by Spudly
How do you exclude npcs from the rotating, and how do you also make rotating effects?

Re: flung.lua - See enemies tumbling down!

Posted: Tue Jun 11, 2024 8:42 pm
by mariobrigade2018
Spudly wrote:
Tue Jun 11, 2024 4:08 pm
How do you exclude npcs from the rotating, and how do you also make rotating effects?
You could add a table that excludes certain npc and then add another check that searches for the NPCs in the table and send them out of the library.
Cloud Devil wrote: Ping
GIF pls.

Re: flung.lua - See enemies tumbling down!

Posted: Wed Jun 12, 2024 11:31 pm
by Spudly
mariobrigade2018 wrote:
Tue Jun 11, 2024 8:42 pm
Spudly wrote:
Tue Jun 11, 2024 4:08 pm
How do you exclude npcs from the rotating, and how do you also make rotating effects?
You could add a table that excludes certain npc and then add another check that searches for the NPCs in the table and send them out of the library.
Cloud Devil wrote: Ping
GIF pls.
That solves the blacklist issue, but what about the effects?