improved power control

master
Alexsandro Percy 2022-05-26 11:19:58 -03:00
parent a66373bfe8
commit f419633d44
6 changed files with 25 additions and 17 deletions

View File

@ -52,15 +52,19 @@ function steampunk_blimp.control(self, dtime, hull_direction, longit_speed, acce
if self.anchored == false then
local factor = 1
if ctrl.up then
steampunk_blimp.powerAdjust(self, dtime, factor, 1)
--self.object:set_animation_frame_speed(40)
local can_acc = true
if self._power_lever >= 82 then can_acc = false end
if ctrl.aux1 then can_acc = true end
if can_acc then
steampunk_blimp.powerAdjust(self, dtime, factor, 1)
end
elseif ctrl.down then
steampunk_blimp.powerAdjust(self, dtime, factor, -1)
--self.object:set_animation_frame_speed(-40)
else
--self.object:set_animation_frame_speed(steampunk_blimp.iddle_rotation)
end
end
if not ctrl.aux1 and self._power_lever < 0 then self._power_lever = 0 end
self._is_going_up = false
if ctrl.jump then
@ -91,18 +95,6 @@ function steampunk_blimp.control(self, dtime, hull_direction, longit_speed, acce
if longit_speed > max_speed then
engineacc = engineacc - (longit_speed-max_speed)
end
if engineacc < 0 then
local is_reversed = false
if ctrl then
if ctrl.aux1 then
is_reversed = true
end
end
if is_reversed == false then
engineacc = 0
self._power_lever = 0
end
end
if engineacc ~= nil then
retval_accel=vector.add(accel,vector.multiply(hull_direction,engineacc))

View File

@ -85,7 +85,8 @@ function steampunk_blimp.engine_step(self, accel)
local pressure = steampunk_blimp.get_pointer_angle(self._boiler_pressure, 200 )
local water = steampunk_blimp.get_pointer_angle(self._water_level, steampunk_blimp.MAX_WATER)
local coal = self._energy
steampunk_blimp.update_hud(player, coal, 180-water, -pressure)
--minetest.chat_send_all(self._power_lever)
steampunk_blimp.update_hud(player, coal, 180-water, -pressure, self._power_lever)
end
end

17
hud.lua
View File

@ -35,7 +35,7 @@ function steampunk_blimp.animate_gauge(player, ids, prefix, x, y, angle)
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)
function steampunk_blimp.update_hud(player, coal, water, pressure, power_lever)
local player_name = player:get_player_name()
local screen_pos_y = -100
@ -49,6 +49,8 @@ function steampunk_blimp.update_hud(player, coal, water, pressure)
local coal_1_y = screen_pos_y
local coal_2_x = coal_1_x + 60
local coal_2_y = screen_pos_y
local throttle_x = screen_pos_x + 395
local throttle_y = screen_pos_y + 45
local ids = steampunk_blimp.hud_list[player_name]
if ids then
@ -57,6 +59,9 @@ function steampunk_blimp.update_hud(player, coal, water, pressure)
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")
player:hud_change(ids["throttle"], "offset", {x = throttle_x, y = throttle_y - power_lever})
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
@ -99,6 +104,15 @@ function steampunk_blimp.update_hud(player, coal, water, pressure)
alignment = { x = 1, y = 0 },
})
ids["throttle"] = player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
offset = {x = throttle_x, y = throttle_y},
text = "steampunk_blimp_throttle.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},
@ -231,6 +245,7 @@ function steampunk_blimp.remove_hud(player)
player:hud_remove(ids["bg"])
player:hud_remove(ids["coal_1"])
player:hud_remove(ids["coal_2"])
player:hud_remove(ids["throttle"])
player:hud_remove(ids["water_pt_7"])
player:hud_remove(ids["water_pt_6"])
player:hud_remove(ids["water_pt_5"])

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB