Files
pke/data/scripts/game_hud.lua
2026-03-07 07:48:16 +03:00

70 lines
1.9 KiB
Lua

local RED_COLOR = { 1.0, 0.0, 0.0, 1.0 }
local GREEN_COLOR = { 0.0, 1.0, 0.0, 1.0 }
local BLUE_COLOR = { 0.0, 0.0, 1.0, 1.0 }
local BLACK_COLOR = { 0.0, 0.0, 0.0, 1.0 }
local WHITE_COLOR = { 1.0, 1.0, 1.0, 1.0 }
local draw_test_hud = false
local draw_debug_string = false
local debug_string_text = ""
local debug_string_time = 0.0
local debug_string_max_time = 0.0
function game_hud_draw( )
if not draw_test_hud then
return
end
-- example of color
local color = { 0.5, 0.5, 0.1, 1.0 }
-- example of drawing
ui.draw_rect(150.0, 150.0, 350.0, 350.0, BLUE_COLOR)
ui.draw_image("data/textures/koshka1.jpg", 160.0, 160.0, 340.0, 340.0, WHITE_COLOR)
ui.draw_text("Hello, world!", 200.0, 200.0, GREEN_COLOR)
if g_player then
game_player_hud_draw()
end
-- debug
if draw_debug_string then
game_debug_string_draw()
end
end
function game_player_hud_draw()
local display_x, display_y = ui.get_display_size()
local color = { 0.0, 0.0, 0.0, 0.3 }
local text_color = { 0.0, 0.0, 0.0, 0.6 }
local hud_rect_size_x = 200
local hud_rect_size_y = 100
local offset_text = ui.calc_text_width("Health") + 5
ui.draw_rect(0.0, display_y, hud_rect_size_x, display_y - hud_rect_size_y, color)
ui.draw_text("Health", 10.0, display_y - hud_rect_size_y + 20, WHITE_COLOR)
ui.draw_text(string.format("%.0f", g_player:get_health()), 10.0 + offset_text, display_y - hud_rect_size_y + 20, WHITE_COLOR)
end
function put_debug_string_to_screen(text, text_time)
debug_string_max_time = text_time
debug_string_text = text
debug_string_time = 0.0
draw_debug_string = true
end
function game_debug_string_draw()
debug_string_time = debug_string_time + engine.get_delta()
if debug_string_time >= debug_string_max_time then
debug_string_max_time = 0.0
debug_string_time = 0.0
draw_debug_string = false
end
local offset = ui.calc_text_width(debug_string_text)
ui.draw_rect(490, 500, 490 + offset + 20, 550, BLACK_COLOR)
ui.draw_text(debug_string_text, 500, 500, RED_COLOR)
end