Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

The life view is now a menu attached to the game.

It means that its callbacks on_draw, on_key_pressed, on_update, etc. are
now called automatically.
Other HUD elements will do the same.
  • Loading branch information...
commit 3871085b9a7871e847e9d5073f1f2f19ec61f7f0 1 parent d3c7447
Christopho authored
18 quests/zsdx/data/hud/hearts.lua
View
@@ -18,6 +18,8 @@ function hearts:initialize(game)
self.game = game
self.surface = sol.surface.create(90, 18)
self.surface:set_transparency_color{0, 0, 0}
+ self.dst_x = 0
+ self.dst_y = 0
self.empty_heart_sprite = sol.sprite.create("hud/empty_heart")
self.nb_max_hearts_displayed = game:get_max_life() / 4
self.nb_current_hearts_displayed = game:get_life()
@@ -132,7 +134,21 @@ function hearts:rebuild_surface()
end
end
-function hearts:draw(dst_surface, x, y)
+function hearts:set_dst_position(x, y)
+ self.dst_x = x
+ self.dst_y = y
+end
+
+function hearts: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
-- Everything was already drawn on self.surface.
self.surface:draw(dst_surface, x, y)
20 quests/zsdx/data/play_game.lua
View
@@ -7,17 +7,10 @@ function game:on_started()
-- Set up the HUD.
self.hud = {}
self.hud.hearts = hearts_class:new(self)
+ self.hud.hearts:set_dst_position(-104, 6)
self:set_hud_enabled(true)
end
-function game:on_post_draw(surface)
- -- Draw the hud after the game is drawn.
- if game:is_hud_enabled() then
- local width, height = surface:get_size()
- self.hud.hearts:draw(surface, width - 104, 6)
- end
-end
-
-- Useful functions for this quest.
function game:is_hud_enabled()
@@ -25,7 +18,16 @@ function game:is_hud_enabled()
end
function game:set_hud_enabled(hud_enabled)
- game.hud_enabled = hud_enabled
+
+ if hud_enabled ~= game.hud_enabled then
+ game.hud_enabled = hud_enabled
+
+ if hud_enabled then
+ sol.menu.start(self, self.hud.hearts)
+ else
+ sol.menu.stop(self.hud.hearts)
+ end
+ end
end
-- Returns the item name of a bottle with the specified content, or nil.
3  quests/zsdx/data/screens/savegames.lua
View
@@ -161,7 +161,8 @@ function savegame_menu:draw_savegame(slot_index)
slot.player_name_text:draw(self.surface, 87, 61 + slot_index * 27)
if slot.hearts_view ~= nil then
- slot.hearts_view:draw(self.surface, 168, 51 + slot_index * 27)
+ slot.hearts_view:set_dst_position(168, 51 + slot_index * 27)
+ slot.hearts_view:on_draw(self.surface)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.