Hi all,
i want an item counter to be displayed in the hud. But i dont get it to work what am I doing wrong??
Item:
ore.lua:
ore_counter.lua:
hud:
ore.lua:
thanks in advance
i want an item counter to be displayed in the hud. But i dont get it to work what am I doing wrong??
Item:
ore.lua:
Code Select
local item = ...
function item:on_obtaining(variant, savegame_variable)
self:get_game():get_item("ore_counter"):add_amount(1)
end
ore_counter.lua:
Code Select
local item = ...
function item:on_created()
self:set_savegame_variable("ore")
self:set_amount_savegame_variable("ore_amount")
self:set_max_amount(99)
end
hud:
ore.lua:
Code Select
local ore = {}
function ore:new(game)
local object = {}
setmetatable(object, self)
self.__index = self
object:initialize(game)
return object
end
function ore:initialize(game)
self.game = game
self.surface = sol.surface.create(48, 12)
self.digits_text = sol.text_surface.create{
font = "white_digits",
horizontal_alignment = "left",
}
local item = self.game:get_item("ore_counter")
self.digits_text:set_text(item:get_amount())
self.rupee_icons_img = sol.surface.create("hud/rupee_icon.png")
self.money_displayed = item:get_amount()
self:rebuild_surface()
end
function ore:rebuild_surface()
local item = self.game:get_item("ore_counter")
self.surface:clear()
self.money_displayed = item:get_amount()
self.digits_text:set_text(self.money_displayed)
self.digits_text:draw(self.surface, 16, 5)
end
function ore:set_dst_position(x, y)
self.dst_x = x
self.dst_y = y
end
function ore:on_draw(dst_surface)
local x, y = self.dst_x, self.dst_y
local width, height = dst_surface:get_size()
if x < 0 then
x = width + x
end
if y < 0 then
y = height + y
end
self.surface:draw(dst_surface, x, y)
end
return ore
thanks in advance