diff --git a/game/engine/LogDisplay.lua b/game/engine/LogDisplay.lua index 48b98889fb8f5d60708fabf8fe00f6ae4fdbb6e4..18c9679b130e0b751031f66e1991f2d3f59bc323 100644 --- a/game/engine/LogDisplay.lua +++ b/game/engine/LogDisplay.lua @@ -16,7 +16,10 @@ function _M:init(w, h, max, fontname, fontsize, color, bgcolor) end function _M:call(str, ...) - table.insert(self.log, 1, str:format(...)) + local lines = str:format(...):splitLines(self.w - 4, self.font) + for i = #lines, 1, -1 do + table.insert(self.log, 1, lines[i]) + end while #self.log > self.max do table.remove(self.log) end @@ -38,7 +41,7 @@ function _M:display() local i = 1 while i < self.h do if not self.log[i] then break end - self.surface:drawString(self.font, self.log[i], 0, (i-1) * self.font_h, self.color[1], self.color[2], self.color[3]) + self.surface:drawColorString(self.font, self.log[i], 0, (i-1) * self.font_h, self.color[1], self.color[2], self.color[3]) i = i + 1 end return self.surface diff --git a/game/engine/Tiles.lua b/game/engine/Tiles.lua index 7905386844760301d50fcf121e66d1feb2200d88..e07178065386fd7b38a0bd46f3cacabf83028b66 100644 --- a/game/engine/Tiles.lua +++ b/game/engine/Tiles.lua @@ -9,10 +9,10 @@ function _M:init(w, h, fontname, fontsize) end function _M:get(char, fr, fg, fb, br, bg, bb) - local fgidx = 65536 * fr + 256 + fg + fb + local fgidx = 65536 * fr + 256 * fg + fb local bgidx if br >= 0 and bg >= 0 and bb >= 0 then - bgidx = 65536 * br + 256 + bg + bb + bgidx = 65536 * br + 256 * bg + bb else bgidx = "none" end diff --git a/game/engine/Tooltip.lua b/game/engine/Tooltip.lua index 0071832df439e3e328b52f8a5c721e7c8c655d9a..6ebfe02ae7e91fda41261d27f9dd82a840972319 100644 --- a/game/engine/Tooltip.lua +++ b/game/engine/Tooltip.lua @@ -5,7 +5,6 @@ module(..., package.seeall, class.make) function _M:init(fontname, fontsize, color, bgcolor) self.color = color or {255,255,255} self.bgcolor = bgcolor or {0,0,0} - self.w, self.h = w, h self.font = core.display.newFont(fontname or "/data/font/Vera.ttf", fontsize or 10) self.font_h = self.font:lineSkip() self.max = max or 400 @@ -13,7 +12,7 @@ function _M:init(fontname, fontsize, color, bgcolor) end function _M:set(str, ...) - self.text = str:format(...) + self.text = str:format(...):splitLines(300, self.font) self.changed = true end @@ -22,11 +21,12 @@ function _M:display() if not self.changed then return self.surface end self.changed = false - local w, h = self.font:size(self.text) - self.surface = core.display.newSurface(w + 4, h + 4) + self.surface = core.display.newSurface(300, self.font_h * #self.text) -- Erase and the display the map self.surface:erase(self.bgcolor[1], self.bgcolor[2], self.bgcolor[3]) - self.surface:drawString(self.font, self.text, 0, 0, self.color[1], self.color[2], self.color[3]) + for i, l in ipairs(self.text) do + self.surface:drawColorString(self.font, self.text[i], 0, (i-1) * self.font_h, self.color[1], self.color[2], self.color[3]) + end return self.surface end diff --git a/game/engine/init.lua b/game/engine/init.lua index 0e6327e7ba19ddd270367ffb11969fc475618c6e..afa638303451d443a3acd2f2df1a5fa80405dcc0 100644 --- a/game/engine/init.lua +++ b/game/engine/init.lua @@ -1,3 +1,6 @@ +-- load some utility functions +dofile("/engine/utils.lua") + require "engine.KeyCommand" -- Setup a default key handler @@ -6,7 +9,10 @@ key:setCurrent() -- Exit the game, this is brutal for now key:addCommand(key._x, {"ctrl"}, function() os.exit() end) +-- Fullscreen toggle +key:addCommand(key._RETURN, {"alt"}, function() core.display.fullscreen() end) +-- Load the game module local mod_def = loadfile("/tome/init.lua") if mod_def then local mod = {} diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index 6cdeaa5f354ad3f32160a8c82bcec06e921ff4a6..451584890343b3681069766a90d8103b260c4906 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -4,9 +4,13 @@ require "engine.Actor" module(..., package.seeall, class.inherit(engine.Actor)) function _M:init(game, t) - self.game = game t.block_move = _M.bumped engine.Actor.init(self, t) + + self.game = game + self.life = 100 + + self.tooltip = _M.tooltip end function _M:move(x, y, force) @@ -25,3 +29,7 @@ function _M:bumped(x, y, e) end return true end + +function _M:tooltip() + return self.name.."\n#ff0000#HP: "..self.life +end diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua index 4b70980dedcabc9267a85454d686b241e2bea447..362d69109545024d0ee7a70b88791a0d5ebe89d6 100644 --- a/game/modules/tome/class/Game.lua +++ b/game/modules/tome/class/Game.lua @@ -12,20 +12,20 @@ local NPC = require "tome.class.NPC" module(..., package.seeall, class.inherit(engine.GameTurnBased)) function _M:init() - engine.GameTurnBased.init(self, engine.KeyCommand.new(), 1000, 100) + engine.GameTurnBased.init(self, engine.Key.current, 1000, 100) self:setupCommands() self.tooltip = engine.Tooltip.new(nil, nil, {255,255,255}, {30,30,30}) self.log = engine.LogDisplay.new(400, 150, nil, nil, nil, {255,255,255}, {30,30,30}) - self.log("Welcome to Tales of Middle Earth!") + self.log("Welcome to #00FF00#Tales of Middle Earth!") local map = Map.new(40, 20) -- map:liteAll(0, 0, map.w, map.h) - local floor = Entity.new{display='.', color_r=100, color_g=100, color_b=100, color_br=0, color_bg=50, color_bb=0} - local e1 = Entity.new{display='#', color_r=255, block_sight=true} - local e2 = Entity.new{display='#', color_g=255, block_sight=true} + local floor = Entity.new{display='.', color_r=100, color_g=200, color_b=100, color_br=0, color_bg=50, color_bb=0} + local e1 = Entity.new{display='#', color_r=255, block_sight=true, block_move=true} + local e2 = Entity.new{display='#', color_g=255, block_sight=true, block_move=true} local e3 = Entity.new{display='#', color_b=255, block_sight=true, block_move=true} local e4 = e3:clone{color_r=255} @@ -148,12 +148,6 @@ function _M:setupCommands() self.paused = false end end, - [{"_x","ctrl"}] = function() - os.exit() - end, - [{"_RETURN","alt"}] = function() - core.display.fullscreen() - end, } self.key:setCurrent() end diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua index ed64537cb2d591a9cac2a68c18a6ed6974621be1..dee6a5b60f2cf4dacf32a84cda2d02182d1cfed1 100644 --- a/game/modules/tome/class/Player.lua +++ b/game/modules/tome/class/Player.lua @@ -5,7 +5,6 @@ module(..., package.seeall, class.inherit(tome.class.Actor)) function _M:init(game, t) tome.class.Actor.init(self, game, t) - self.tooltip = "This is you!" end function _M:move(x, y, force)