Skip to content
Snippets Groups Projects
Commit 4dbd0d46 authored by dg's avatar dg
Browse files

color text, ...

git-svn-id: http://svn.net-core.org/repos/t-engine4@10 51575b47-30f0-44d4-a5cc-537603b46e54
parent cd8fc3ef
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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
-- 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 = {}
......
......@@ -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
......@@ -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
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment