Update balloon.lua, sum_airship_texture.png, and sum_airship_texture_oak_boat.png

This commit is contained in:
Sumyjkl 2023-01-11 13:56:21 +11:00
parent d5737a31da
commit b8310e0887
2 changed files with 115 additions and 12 deletions

View file

@ -19,18 +19,115 @@ local ship = {
backface_culling = false,
mesh = "sum_airship.b3d",
textures = {"sum_airship_texture.png"},
on_rightclick = me.on_rightclick,
on_activate = me.on_activate,
get_staticdata = me.get_staticdata,
on_death = me.on_death,
on_step = me.on_step,
_animations = {
idle = {x= 10, y= 90},
fly = {x= 91, y= 170},
boost = {x= 91, y= 170},
},
_driver = nil,
_removed = false,
_flags = {},
_itemstring = "sum_airship:boat",
_passenger = nil,
_vel = 0,
_regen_timer = 0,
_fuel = 0,
_sounds = {
engine = {
handle = nil,
gain = 0.1,
playing = false,
time_elapsed = 0,
},
engine_stop = {
handle = nil,
gain = 0.1,
playing = false,
time_elapsed = 0,
},
}
}
function me.on_activate(self, staticdata, dtime_s)
local sounds = {
engine_idle = {
sound_name = "sum_airship_lip_trill",
gain = 1.4,
max_hear_distance = 10,
loop = false,
pitch = 0.75,
},
engine_stop = {
sound_name = "sum_airship_lip_trill_end",
gain = 2.2,
max_hear_distance = 10,
loop = false,
pitch = 1,
},
engine_boost = {
sound_name = "sum_airship_lip_trill",
gain = 40,
max_hear_distance = 10,
loop = false,
pitch = 1,
},
}
function me.sound_play(self, sound_obj, sound_instance)
sound_instance.handle = minetest.sound_play(sound_obj.sound_name, {
gain = sound_obj.gain,
max_hear_distance = sound_obj.max_hear_distance,
loop = sound_obj.loop,
pitch = sound_obj.pitch or 1,
object = self.object,
})
sound_instance.playing = true
sound_instance.time_elapsed = 0
end
function me.sound_stop(sound_instance)
if sound_instance.handle then
minetest.sound_stop(sound_instance.handle)
end
sound_instance.playing = false
sound_instance.time_elapsed = 0
sound_instance.handle = nil
end
function me.update_sound(self, dtime, forward)
local fuel = self._fuel
local is_thrust = forward ~= 0 and self._driver
if not fuel or not type(fuel) == "number" then self._fuel = 0 end
if self._sounds.engine.time_elapsed > 2.1
and self._sounds.engine.handle
and self._sounds.engine.playing then
me.sound_stop(self._sounds.engine)
end
if not self._sounds.engine.playing then
if self._fuel > 1 then
me.sound_play(self, sounds.engine_boost, self._sounds.engine)
elseif is_thrust then
me.sound_play(self, sounds.engine_idle, self._sounds.engine)
end
if self._fuel > 1 and self._sounds.engine_stop.playing then
me.sound_stop(self._sounds.engine_stop)
end
end
if self._fuel <= 1 and self._sounds.engine.playing then
if self._fuel > 0 and not self._sounds.engine_stop.playing
and self._sounds.engine_stop.time_elapsed == 0 then
me.sound_play(self, sounds.engine_stop, self._sounds.engine_stop)
end
if not is_thrust
or (self._sounds.engine_stop.time_elapsed == 0
and self._sounds.engine_stop.playing) then
me.sound_stop(self._sounds.engine)
end
end
end
function ship.on_activate(self, staticdata, dtime_s)
local data = minetest.deserialize(staticdata)
if type(data) == "table" then
self._itemstring = data.itemstring
@ -42,10 +139,10 @@ function me.on_activate(self, staticdata, dtime_s)
self._flags = data._flags
if self._driver then me.detach(self) end
end
self.object:set_animation({x=0, y=149}, 24)
self.object:set_animation(ship._animations.idle, 24)
end
function me.get_staticdata(self)
function ship.get_staticdata(self)
return minetest.serialize({
itemstring = self._itemstring,
_driver = ((self._driver and self._driver:is_player())
@ -72,7 +169,7 @@ function me.detach(self)
end
function me.on_death(self, killer)
function ship.on_death(self, killer)
if killer and killer:is_player()
and not minetest.is_creative_enabled(killer:get_player_name()) then
local inv = killer:get_inventory()
@ -84,16 +181,22 @@ function me.on_death(self, killer)
self._driver = nil
end
function me.on_rightclick(self, clicker)
function ship.on_rightclick(self, clicker)
local item = clicker:get_wielded_item()
local item_name = item:get_name()
if clicker and item and item_name
if clicker and (item and item_name)
and (string.find(item_name, ":coal")
or string.find(item_name, ":charcoal")) then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end
self._fuel = self._fuel + sum_airship.fuel_time
me.sound_stop(self._sounds.engine)
minetest.sound_play("sum_airship_fire", {
gain = 1,
object = self.object,
})
else
me.attach(self, clicker)
end
@ -151,7 +254,7 @@ function me.get_balloon_collide(self)
return force
end
function me.on_step(self, dtime, moveresult)
function ship.on_step(self, dtime, moveresult)
local exit = false
local pi = nil
-- allow to exit

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB