mirror of
https://codeberg.org/SumianVoice/sum_airship.git
synced 2025-03-15 04:11:23 +00:00
add gitignore, code quality and add fuel system, add sounds for fuelled flight
This commit is contained in:
parent
487bddfa10
commit
aa68f4af63
8 changed files with 187 additions and 21 deletions
45
.gitignore
vendored
Normal file
45
.gitignore
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
*.blend1
|
||||
|
||||
# ---> Lua
|
||||
# Compiled Lua sources
|
||||
luac.out
|
||||
|
||||
# luarocks build files
|
||||
*.src.rock
|
||||
*.zip
|
||||
*.tar.gz
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.os
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
*.def
|
||||
*.exp
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
|
|
@ -1,2 +1,4 @@
|
|||
# sum_airship
|
||||
mod for mcl
|
||||
|
||||
[ContentDB](https://content.minetest.net/packages/Sumianvoice/sum_airship/)
|
161
init.lua
161
init.lua
|
@ -2,6 +2,8 @@ local S = minetest.get_translator(minetest.get_current_modname())
|
|||
|
||||
-- globalscope var for the whole mod
|
||||
sum_airship = {
|
||||
speed_mult = 4,
|
||||
fuel_time = 10, -- per second
|
||||
i = {},
|
||||
}
|
||||
|
||||
|
@ -10,7 +12,6 @@ local boat_y_offset = 0.35
|
|||
local boat_y_offset_ground = boat_y_offset + 0.6
|
||||
local boat_side_offset = 1.001
|
||||
local boat_max_hp = 4
|
||||
local speed_mult = 4
|
||||
|
||||
|
||||
-- make sure silly people don't try to run it without the needed dependencies.
|
||||
|
@ -144,6 +145,8 @@ local boat = {
|
|||
textures = {"sum_airship_texture_oak_boat.png"},
|
||||
animations = {
|
||||
idle = {x= 10, y= 90},
|
||||
fly = {x= 91, y= 170},
|
||||
boost = {x= 91, y= 170},
|
||||
},
|
||||
visual_size = boat_visual_size,
|
||||
hp_max = boat_max_hp,
|
||||
|
@ -158,17 +161,107 @@ local boat = {
|
|||
_animation = 0, -- 0: not animated; 1: paddling forwards; -1: paddling forwards
|
||||
_regen_timer = 0,
|
||||
_damage_anim = 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 boat.update_sound(self, dtime)
|
||||
local fuel = self._fuel
|
||||
if not fuel or not type(fuel) == "number" then return false end
|
||||
if fuel > 2 then
|
||||
if self._sounds.engine.time_elapsed > 2.1
|
||||
and self._sounds.engine.handle
|
||||
and self._sounds.engine.playing then
|
||||
minetest.sound_stop(self._sounds.engine.handle)
|
||||
self._sounds.engine.playing = false
|
||||
self._sounds.engine.time_elapsed = 0
|
||||
end
|
||||
if not self._sounds.engine.playing then
|
||||
self._sounds.engine.playing = true
|
||||
self._sounds.engine.time_elapsed = 0
|
||||
self._sounds.engine.handle = minetest.sound_play("sum_airship_lip_trill", {
|
||||
gain = 1,
|
||||
object = self.object,
|
||||
max_hear_distance = 10,
|
||||
loop = false,
|
||||
})
|
||||
if self._sounds.engine_stop.playing then
|
||||
minetest.sound_stop(self._sounds.engine_stop.handle)
|
||||
self._sounds.engine_stop.playing = false
|
||||
self._sounds.engine_stop.time_elapsed = 0
|
||||
end
|
||||
end
|
||||
elseif self._sounds.engine.playing then
|
||||
minetest.sound_stop(self._sounds.engine.handle)
|
||||
self._sounds.engine.playing = false
|
||||
if not self._sounds.engine_stop.playing then
|
||||
self._sounds.engine_stop.playing = true
|
||||
self._sounds.engine_stop.time_elapsed = 0
|
||||
self._sounds.engine_stop.handle = minetest.sound_play("sum_airship_lip_trill_end", {
|
||||
gain = 0.8,
|
||||
object = self.object,
|
||||
max_hear_distance = 10,
|
||||
loop = false,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- function boat.update_sound(self, forward, dtime)
|
||||
-- if math.abs(forward) > 0 then
|
||||
-- if not self._sounds.engine.playing then
|
||||
-- self._sounds.engine.playing = true
|
||||
-- self._sounds.engine.handle = minetest.sound_play("sum_airship_lip_trill", {
|
||||
-- gain = 0.3,
|
||||
-- object = self.object,
|
||||
-- max_hear_distance = 10,
|
||||
-- loop = true,
|
||||
-- })
|
||||
-- end
|
||||
-- elseif forward == 0 and self._sounds.engine.playing then
|
||||
-- minetest.sound_stop(self._sounds.engine.handle)
|
||||
-- self._sounds.engine.playing = false
|
||||
-- end
|
||||
-- end
|
||||
|
||||
minetest.register_on_respawnplayer(detach_object)
|
||||
|
||||
function boat.on_rightclick(self, clicker)
|
||||
if self._passenger or not clicker or clicker:get_attach() then
|
||||
return
|
||||
local item = clicker:get_wielded_item()
|
||||
local item_name = item:get_name()
|
||||
if clicker and item_name == "mcl_core:coal_lump" or item_name == "mcl_core:charcoal_lump" then
|
||||
self._fuel = self._fuel + sum_airship.fuel_time
|
||||
elseif self._passenger or not clicker or clicker:get_attach() then
|
||||
else
|
||||
attach_object(self, clicker)
|
||||
end
|
||||
attach_object(self, clicker)
|
||||
end
|
||||
|
||||
boat.chimney_dist = -1.0
|
||||
boat.chimney_yaw = 0.13
|
||||
boat.chimney_height = 0.9
|
||||
function boat.get_chimney_pos(self)
|
||||
local p = self.object:get_pos()
|
||||
local yaw = self.object:get_yaw()
|
||||
local ret = {
|
||||
x = p.x + (boat.chimney_dist * math.sin(-yaw + boat.chimney_yaw)),
|
||||
y = p.y + boat.chimney_height,
|
||||
z = p.z + (boat.chimney_dist * math.cos(-yaw + boat.chimney_yaw))}
|
||||
return ret
|
||||
end
|
||||
|
||||
function boat.on_activate(self, staticdata, dtime_s)
|
||||
self.object:set_armor_groups({fleshy = 100})
|
||||
|
@ -178,6 +271,7 @@ function boat.on_activate(self, staticdata, dtime_s)
|
|||
self._v = data.v
|
||||
self._last_v = self._v
|
||||
self._itemstring = data.itemstring
|
||||
self._fuel = data.fuel
|
||||
|
||||
while #data.textures < 5 do
|
||||
table.insert(data.textures, data.textures[1])
|
||||
|
@ -191,6 +285,7 @@ function boat.get_staticdata(self)
|
|||
return minetest.serialize({
|
||||
v = self._v,
|
||||
itemstring = self._itemstring,
|
||||
fuel = self._fuel,
|
||||
textures = self.object:get_properties().textures
|
||||
})
|
||||
end
|
||||
|
@ -223,7 +318,16 @@ function boat.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d
|
|||
end
|
||||
end
|
||||
|
||||
function boat.sound_countdown(self, dtime)
|
||||
for _, sound in pairs(self._sounds) do
|
||||
if sound.playing then
|
||||
sound.time_elapsed = sound.time_elapsed + dtime
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function boat.on_step(self, dtime, moveresult)
|
||||
boat.sound_countdown(self, dtime)
|
||||
if minetest.get_modpath("mcl_burning") then
|
||||
mcl_burning.tick(self.object, dtime, self) end
|
||||
|
||||
|
@ -279,11 +383,13 @@ function boat.on_step(self, dtime, moveresult)
|
|||
end
|
||||
end
|
||||
|
||||
local has_controls = false
|
||||
if self._driver then
|
||||
if had_passenger and not self._passenger then
|
||||
set_attach(self)
|
||||
end
|
||||
local ctrl = self._driver:get_player_control()
|
||||
if ctrl then has_controls = true end
|
||||
if ctrl and ctrl.sneak then
|
||||
detach_object(self._driver, true)
|
||||
self._driver = nil
|
||||
|
@ -338,10 +444,15 @@ function boat.on_step(self, dtime, moveresult)
|
|||
self.object:set_rotation(vector.new(anim, yaw, anim))
|
||||
|
||||
local vel = vector.new(0, 0, 0)
|
||||
if self._driver and not in_water then
|
||||
if not in_water then
|
||||
local speed = sum_airship.speed_mult
|
||||
if self._fuel > 0 then
|
||||
self._fuel = self._fuel - dtime
|
||||
speed = speed * 3
|
||||
end
|
||||
dir = vector.multiply(yaw_dir, forward)
|
||||
dir.y = climb
|
||||
vel = vector.multiply(dir, speed_mult)
|
||||
vel = vector.multiply(dir, speed)
|
||||
elseif in_water then
|
||||
vel = {x=0, y=5, z=0}
|
||||
else
|
||||
|
@ -373,23 +484,31 @@ function boat.on_step(self, dtime, moveresult)
|
|||
|
||||
self.object:set_acceleration(vel)
|
||||
|
||||
-- I hate trig
|
||||
local chimney_dist = -1.0
|
||||
local chimney_pos = {
|
||||
x=p.x + (chimney_dist * math.sin(-yaw+0.13)),
|
||||
y=p.y+0.9,
|
||||
z=p.z + (chimney_dist * math.cos(-yaw+0.13))}
|
||||
local chimney_pos = boat.get_chimney_pos(self)
|
||||
if true or has_controls then -- only do it if you got the input
|
||||
boat.update_sound(self, dtime)
|
||||
end
|
||||
|
||||
local spread = 0.06
|
||||
minetest.add_particle({
|
||||
pos = vector.offset(chimney_pos, math.random(-1, 1)*spread, 0, math.random(-1, 1)*spread),
|
||||
velocity = vector.add(wind_vel, {x=0, y=math.random(0.2*100,0.7*100)/100, z=0}),
|
||||
expirationtime = math.random(0.5, 2),
|
||||
size = math.random(0.1, 4),
|
||||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = "sum_airship_smoke.png",
|
||||
})
|
||||
if self._fuel > 0 or math.random(0,100) > 80 then
|
||||
minetest.add_particle({
|
||||
pos = vector.offset(chimney_pos, math.random(-1, 1)*spread, 0, math.random(-1, 1)*spread),
|
||||
velocity = vector.add(wind_vel, {x=0, y=math.random(0.2*100,0.7*100)/100, z=0}),
|
||||
expirationtime = math.random(0.5, 2),
|
||||
size = math.random(0.1, 4),
|
||||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = "sum_airship_smoke.png",
|
||||
})
|
||||
end
|
||||
-- animations
|
||||
if self._fuel > 0 then
|
||||
self.object:set_animation(self.animations.boost, 25)
|
||||
elseif self._driver then
|
||||
self.object:set_animation(self.animations.fly, 25)
|
||||
else
|
||||
self.object:set_animation(self.animations.idle, 25)
|
||||
end
|
||||
end
|
||||
|
||||
-- Register one entity for all boat types
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
sounds/sum_airship_lip_trill.ogg
Normal file
BIN
sounds/sum_airship_lip_trill.ogg
Normal file
Binary file not shown.
BIN
sounds/sum_airship_lip_trill_end.ogg
Normal file
BIN
sounds/sum_airship_lip_trill_end.ogg
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue