adding HUD

This commit is contained in:
Alexsandro Percy 2022-05-24 17:09:54 -03:00
parent 75f208ccf3
commit 4bf7529f0e
22 changed files with 305 additions and 31 deletions

View File

@ -2,13 +2,6 @@
steampunk_blimp.vector_up = vector.new(0, 1, 0)
function steampunk_blimp.get_pointer_angle(value, maxvalue)
local angle = value/maxvalue * 180
angle = angle - 90
angle = angle * -1
return angle
end
function steampunk_blimp.check_node_below(obj)
local pos_below = obj:get_pos()
pos_below.y = pos_below.y - 0.1

36
engine_management.lua Normal file
View File

@ -0,0 +1,36 @@
local function boiler_step(self, accel)
end
local function furnace_step(self, accel)
if self._energy > 0 and self._engine_running then
local zero_reference = vector.new()
local acceleration = steampunk_blimp.get_hipotenuse_value(accel, zero_reference)
local consumed_power = acceleration/steampunk_blimp.FUEL_CONSUMPTION
self._energy = self._energy - consumed_power;
end
if self._energy <= 0 then
self._engine_running = false
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
self.object:set_animation_frame_speed(0)
end
end
function steampunk_blimp.engine_step(self, accel)
furnace_step(self, accel)
boiler_step(self, accel)
if self.driver_name then
local player = minetest.get_player_by_name(self.driver_name)
local pressure = steampunk_blimp.get_pointer_angle(self._boiler_pressure, 200 )
local water = steampunk_blimp.get_pointer_angle(self._water_level, steampunk_blimp.MAX_FUEL)
local coal = self._energy
steampunk_blimp.update_hud(player, coal, 180-water, -pressure)
end
end

View File

@ -95,6 +95,8 @@ minetest.register_entity("steampunk_blimp:blimp", {
_baloon_buoyancy = 0,
_show_hud = true,
_energy = 1.0,--0.001,
_water_level = 1.0,
_boiler_pressure = 1.0, --min 155 max 310
_passengers = {}, --passengers list
_passengers_base = {}, --obj id
_passengers_base_pos = steampunk_blimp.copy_vector({}),
@ -107,6 +109,8 @@ minetest.register_entity("steampunk_blimp:blimp", {
return minetest.serialize({
stored_baloon_buoyancy = self._baloon_buoyancy,
stored_energy = self._energy,
stored_water_level = self._water_level,
stored_boiler_pressure = self._boiler_pressure,
stored_owner = self.owner,
stored_shared_owners = self._shared_owners,
stored_hp = self.hp,
@ -132,6 +136,8 @@ minetest.register_entity("steampunk_blimp:blimp", {
self._baloon_buoyancy = data.stored_baloon_buoyancy or 0
self._energy = data.stored_energy or 0
self._water_level = data.stored_water_level or 0
self._boiler_pressure = data.stored_boiler_pressure or 0
self.owner = data.stored_owner or ""
self._shared_owners = data.stored_shared_owners or {}
self.hp = data.stored_hp or 50
@ -299,23 +305,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
newyaw = yaw + self.dtime*(1 - 1 / (math.abs(longit_speed) + 1)) *
self._rudder_angle / 30 * turn_rate * steampunk_blimp.sign(longit_speed)
-- calculate energy consumption --
----------------------------------
if self._energy > 0 and self._engine_running then
local zero_reference = vector.new()
local acceleration = steampunk_blimp.get_hipotenuse_value(accel, zero_reference)
local consumed_power = acceleration/steampunk_blimp.FUEL_CONSUMPTION
--self._energy = self._energy - consumed_power;
local energy_indicator_angle = steampunk_blimp.get_pointer_angle(self._energy, steampunk_blimp.MAX_FUEL)
end
if self._energy <= 0 then
self._engine_running = false
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
self.object:set_animation_frame_speed(0)
end
----------------------------
-- end energy consumption --
steampunk_blimp.engine_step(self, accel)
--roll adjust
---------------------------------

View File

@ -197,6 +197,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
else
ent.driver_name = nil
ent._at_control = false
steampunk_blimp.remove_hud(player)
end
end
if fields.disembark_l then
@ -226,7 +227,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
if fields.anchor then
if fields.anchor == "true" then
local max_speed_anchor = 0.2
local max_speed_anchor = 0.5
if ent._longit_speed then
if ent._longit_speed < max_speed_anchor and
ent._longit_speed > -max_speed_anchor then

View File

@ -1,8 +1,7 @@
--
-- fuel
--
steampunk_blimp.GAUGE_FUEL_POSITION = {x=0,y=-8.45,z=5.31}
steampunk_blimp.MAX_FUEL = minetest.settings:get("steampunk_blimp_max_fuel") or 10
steampunk_blimp.MAX_FUEL = minetest.settings:get("steampunk_blimp_max_fuel") or 99
steampunk_blimp.FUEL_CONSUMPTION = minetest.settings:get("steampunk_blimp_fuel_consumption") or 6000
minetest.register_entity('steampunk_blimp:pointer',{
@ -49,10 +48,10 @@ function steampunk_blimp.load_fuel(self, player)
if fuel then
local stack = ItemStack(item_name .. " 1")
if self.energy < steampunk_blimp.MAX_FUEL then
if self._energy < steampunk_blimp.MAX_FUEL then
inv:remove_item("main", stack)
self.energy = self.energy + fuel.amount
if self.energy > steampunk_blimp.MAX_FUEL then self.energy = steampunk_blimp.MAX_FUEL end
self._energy = self._energy + fuel.amount
if self._energy > steampunk_blimp.MAX_FUEL then self._energy = steampunk_blimp.MAX_FUEL end
--minetest.chat_send_all(self.energy)
if fuel.drop then
@ -62,7 +61,7 @@ function steampunk_blimp.load_fuel(self, player)
end
end
local energy_indicator_angle = steampunk_blimp.get_pointer_angle(self.energy, steampunk_blimp.MAX_FUEL)
--local energy_indicator_angle = steampunk_blimp.get_pointer_angle(self._energy, steampunk_blimp.MAX_FUEL)
end
return true

252
hud.lua Executable file
View File

@ -0,0 +1,252 @@
steampunk_blimp.hud_list = {}
function steampunk_blimp.get_pointer_angle(value, maxvalue)
local angle = value/maxvalue * 180
--angle = angle - 90
--angle = angle * -1
return angle
end
function steampunk_blimp.animate_gauge(player, ids, prefix, x, y, angle)
local angle_in_rad = math.rad(angle + 180)
local dim = 10
local pos_x = math.sin(angle_in_rad) * dim
local pos_y = math.cos(angle_in_rad) * dim
player:hud_change(ids[prefix .. "2"], "offset", {x = pos_x + x, y = pos_y + y})
dim = 20
pos_x = math.sin(angle_in_rad) * dim
pos_y = math.cos(angle_in_rad) * dim
player:hud_change(ids[prefix .. "3"], "offset", {x = pos_x + x, y = pos_y + y})
dim = 30
pos_x = math.sin(angle_in_rad) * dim
pos_y = math.cos(angle_in_rad) * dim
player:hud_change(ids[prefix .. "4"], "offset", {x = pos_x + x, y = pos_y + y})
dim = 40
pos_x = math.sin(angle_in_rad) * dim
pos_y = math.cos(angle_in_rad) * dim
player:hud_change(ids[prefix .. "5"], "offset", {x = pos_x + x, y = pos_y + y})
dim = 50
pos_x = math.sin(angle_in_rad) * dim
pos_y = math.cos(angle_in_rad) * dim
player:hud_change(ids[prefix .. "6"], "offset", {x = pos_x + x, y = pos_y + y})
dim = 60
pos_x = math.sin(angle_in_rad) * dim
pos_y = math.cos(angle_in_rad) * dim
player:hud_change(ids[prefix .. "7"], "offset", {x = pos_x + x, y = pos_y + y})
end
function steampunk_blimp.update_hud(player, coal, water, pressure)
local player_name = player:get_player_name()
local screen_pos_y = -100
local screen_pos_x = 10
local water_gauge_x = screen_pos_x + 374
local water_gauge_y = screen_pos_y
local press_gauge_x = screen_pos_x + 85
local press_gauge_y = water_gauge_y
local coal_1_x = screen_pos_x + 182
local coal_1_y = screen_pos_y
local coal_2_x = coal_1_x + 60
local coal_2_y = screen_pos_y
local ids = steampunk_blimp.hud_list[player_name]
if ids then
local coal_value = coal
if coal_value > 99 then coal_value = 99 end
if coal_value < 0 then coal_value = 0 end
player:hud_change(ids["coal_1"], "text", "steampunk_blimp_"..(math.floor(coal_value/10))..".png")
player:hud_change(ids["coal_2"], "text", "steampunk_blimp_"..(math.floor(coal_value%10))..".png")
steampunk_blimp.animate_gauge(player, ids, "water_pt_", water_gauge_x, water_gauge_y, water)
steampunk_blimp.animate_gauge(player, ids, "press_pt_", press_gauge_x, press_gauge_y, pressure)
else
ids = {}
ids["title"] = player:hud_add({
hud_elem_type = "text",
position = {x = 0, y = 1},
offset = {x = screen_pos_x + 240, y = screen_pos_y - 100},
text = "Blimp engine state",
alignment = 0,
scale = { x = 100, y = 30},
number = 0xFFFFFF,
})
ids["bg"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = screen_pos_x, y = screen_pos_y},
text = "steampunk_blimp_hud_panel.png",
scale = { x = 0.5, y = 0.5},
alignment = { x = 1, y = 0 },
})
ids["coal_1"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = coal_1_x, y = coal_1_y},
text = "steampunk_blimp_0.png",
scale = { x = 0.5, y = 0.5},
alignment = { x = 1, y = 0 },
})
ids["coal_2"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = coal_2_x, y = coal_2_y},
text = "steampunk_blimp_0.png",
scale = { x = 0.5, y = 0.5},
alignment = { x = 1, y = 0 },
})
ids["water_pt_1"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = water_gauge_x, y = water_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["water_pt_2"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = water_gauge_x, y = water_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["water_pt_3"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = water_gauge_x, y = water_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["water_pt_4"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = water_gauge_x, y = water_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["water_pt_5"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = water_gauge_x, y = water_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["water_pt_6"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = water_gauge_x, y = water_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["water_pt_7"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = water_gauge_x, y = water_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["press_pt_1"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = press_gauge_x, y = press_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["press_pt_2"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = press_gauge_x, y = press_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["press_pt_3"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = press_gauge_x, y = press_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["press_pt_4"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = press_gauge_x, y = press_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["press_pt_5"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = press_gauge_x, y = press_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["press_pt_6"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = press_gauge_x, y = press_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
ids["press_pt_7"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = press_gauge_x, y = press_gauge_y},
text = "steampunk_blimp_ind_box.png",
scale = { x = 6, y = 6},
alignment = { x = 1, y = 0 },
})
steampunk_blimp.hud_list[player_name] = ids
end
end
function steampunk_blimp.remove_hud(player)
if player then
local player_name = player:get_player_name()
--minetest.chat_send_all(player_name)
local ids = steampunk_blimp.hud_list[player_name]
if ids then
--player:hud_remove(ids["altitude"])
--player:hud_remove(ids["time"])
player:hud_remove(ids["title"])
player:hud_remove(ids["bg"])
player:hud_remove(ids["coal_1"])
player:hud_remove(ids["coal_2"])
player:hud_remove(ids["water_pt_7"])
player:hud_remove(ids["water_pt_6"])
player:hud_remove(ids["water_pt_5"])
player:hud_remove(ids["water_pt_4"])
player:hud_remove(ids["water_pt_3"])
player:hud_remove(ids["water_pt_2"])
player:hud_remove(ids["water_pt_1"])
player:hud_remove(ids["press_pt_7"])
player:hud_remove(ids["press_pt_6"])
player:hud_remove(ids["press_pt_5"])
player:hud_remove(ids["press_pt_4"])
player:hud_remove(ids["press_pt_3"])
player:hud_remove(ids["press_pt_2"])
player:hud_remove(ids["press_pt_1"])
end
steampunk_blimp.hud_list[player_name] = nil
end
end

View File

@ -74,7 +74,9 @@ steampunk_blimp.colors ={
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "utilities.lua")
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "control.lua")
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "fuel_management.lua")
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "engine_management.lua")
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "custom_physics.lua")
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "hud.lua")
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "forms.lua")

BIN
textures/numeros.xcf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -83,6 +83,7 @@ function steampunk_blimp.dettach_pax(self, player, side)
side = side or "r"
if player then
local name = player:get_player_name() --self._passenger
steampunk_blimp.remove_hud(player)
-- passenger clicked the object => driver gets off the vehicle
for i = 5,1,-1