diff --git a/init.lua b/init.lua index 696b443..98df888 100644 --- a/init.lua +++ b/init.lua @@ -68,6 +68,7 @@ airutils.get_wind = dofile(minetest.get_modpath("airutils") .. DIR_DELIM ..'/win dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "uuid_manager.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "common_entities.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_wind.lua") +dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "water_splash.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "inventory_management.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "light.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "physics_lib.lua") diff --git a/water_splash.lua b/water_splash.lua new file mode 100644 index 0000000..5b2574a --- /dev/null +++ b/water_splash.lua @@ -0,0 +1,52 @@ +local function calculateVelocity(magnitude, angle) + -- Calcula os componentes do vetor usando ângulo polar + -- Supondo que o ângulo é dado no plano XY, com z = 0 + local velocity = { + x = magnitude * math.cos(angle), + y = 0, -- Se a velocidade não tem componente z + z = magnitude * math.sin(angle), + } + + return velocity +end + +local function water_particle(pos, vel) + if airutils.splash_texture == nil then return end + if airutils.splash_texture == "" then return end + + minetest.add_particle({ + pos = pos, + velocity = vel, --{x = 0, y = 0, z = 0}, + acceleration = {x = 0, y = 0, z = 0}, + expirationtime = 2.0, + size = 4.8, + collisiondetection = false, + collision_removal = false, + vertical = false, + texture = airutils.splash_texture, + }) +end + +function airutils.add_splash(pos, yaw, x_pos) + local direction = yaw + + local spl_pos = vector.new(pos) + water_particle(spl_pos, {x=0,y=0,z=0}) + + --right + local move = x_pos/10 + spl_pos.x = spl_pos.x + move * math.cos(direction) + spl_pos.z = spl_pos.z + move * math.sin(direction) + + local velocity = calculateVelocity(1.0, yaw) + water_particle(spl_pos, velocity) + + --left + direction = direction - math.rad(180) + spl_pos = vector.new(pos) + spl_pos.x = spl_pos.x + move * math.cos(direction) + spl_pos.z = spl_pos.z + move * math.sin(direction) + + velocity = calculateVelocity(1.0, yaw - math.rad(180)) + water_particle(spl_pos, velocity) +end