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

luaaa

git-svn-id: http://svn.net-core.org/repos/t-engine4@4 51575b47-30f0-44d4-a5cc-537603b46e54
parent 5ce24345
No related branches found
No related tags found
No related merge requests found
......@@ -4,10 +4,20 @@ local Map = require "engine.Map"
module(..., package.seeall, class.inherit(Entity))
function _M:init(t)
t = t or {}
self.name = t.name
Entity.init(self, t)
end
function _M:move(map, x, y)
if self.x and self.y then
map:remove(self.x, self.y, Map.ACTOR)
end
if x < 0 then x = 0 end
if x >= map.w then x = map.w - 1 end
if y < 0 then y = 0 end
if y >= map.h then y = map.h - 1 end
self.x, self.y = x, y
map(x, y, Map.ACTOR, self)
end
......@@ -6,6 +6,7 @@ local next_uid = 1
setmetatable(__uids, {__mode="v"})
function _M:init(t)
print("entity init")
t = t or {}
self.uid = next_uid
__uids[self.uid] = self
......@@ -15,6 +16,7 @@ function _M:init(t)
self.color_g = t.color_g or 0
self.color_b = t.color_b or 0
self.block_sight = t.block_sight
self.block_move = t.block_move
next_uid = next_uid + 1
end
......@@ -26,6 +28,8 @@ function _M:cloned()
next_uid = next_uid + 1
end
function _M:display()
return self.display, self.color_r, self.color_g, self.color_b
function _M:check(prop, ...)
if type(self[prop]) == "function" then return self[prop](...)
else return self[prop]
end
end
......@@ -7,6 +7,8 @@ TERRAIN = 1
OBJECT = 10
ACTOR = 20
displayOrder = { ACTOR, OBJECT, TERRAIN }
function _M:init(w, h)
self.w, self.h = w, h
self.map = {}
......@@ -46,10 +48,10 @@ function _M:display()
player:move(self, player.x+1, player.y)
for i = 0, self.w - 1 do for j = 0, self.h - 1 do
local e = self(i, j, TERRAIN)
local e, si = nil, 1
while not e and si <= #displayOrder do e = self(i, j, displayOrder[si]) si = si + 1 end
local z = i + j * self.w
if e then
-- print("grid", i, j, z, self.seens[z])
if self.seens[z] then
engine.display.char(e.display, i, j, e.color_r, e.color_g, e.color_b)
elseif self.remembers[z] then
......@@ -68,7 +70,7 @@ end
function _M:opaque(x, y)
if x < 0 or x >= self.w or y < 0 or y >= self.h then return false end
local e = self(x, y, TERRAIN)
if e and e.block_sight then return true end
if e and e:check("block_sight") then return true end
end
function _M:apply(x, y)
......
......@@ -3,9 +3,9 @@ module("class", package.seeall)
local base = _G
function make(c)
setmetatable(c, {__index=_M})
c.new = function(...)
local obj = {}
setmetatable(c, {__index=_M})
setmetatable(obj, {__index=c})
if obj.init then obj:init(...) end
return obj
......@@ -15,9 +15,9 @@ end
function inherit(base)
return function(c)
setmetatable(c, {__index=base})
c.new = function(...)
local obj = {}
setmetatable(c, {__index=base})
setmetatable(obj, {__index=c})
if obj.init then obj:init(...) end
return obj
......
local Map = require "engine.Map"
local Entity = require "engine.Entity"
local Actor = require "engine.Actor"
map = Map.new(20, 20)
local floor = Entity.new{display='#', color_r=100, color_g=100, color_b=100}
local e1 = Entity.new{display='#', color_r=255, block_sight=true}
local e2 = Entity.new{display='#', color_g=255, block_sight=true}
local e3 = Entity.new{display='#', color_b=255, block_sight=true}
local e4 = e3:clone{color_r=255}
for i = 0, 19 do for j = 0, 19 do
map(i, j, 1, floor)
end end
map(8, 6, Map.TERRAIN, e4)
map(8, 7, Map.TERRAIN, e2)
map(8, 8, Map.TERRAIN, e3)
map(9, 6, Map.TERRAIN, e1)
map(9, 7, Map.TERRAIN, e2)
map(9, 8, Map.TERRAIN, e3)
map(10, 6, Map.TERRAIN, e1)
map(10, 7, Map.TERRAIN, e2)
map(10, 8, Map.TERRAIN, e3)
player = Actor.new{display='#', color_r=125, color_g=125, color_b=0}
player:move(map, 2, 3)
map:setCurrent()
print("map is ", map)
--dofile("/game/modules/tome/")
local mod_def = loadfile("/tome/init.lua")
if mod_def then
local mod = {}
setfenv(mod_def, mod)
mod_def()
if not mod.name or not mod.short_name or not mod.version or not mod.starter then os.exit() end
require(mod.starter)
else
os.exit()
end
require "engine.class"
require "engine.Actor"
module(..., package.seeall, class.inherit(engine.Actor))
function _M:init(t)
engine.Actor.init(self, t)
end
function _M:move(map, x, y)
engine.Actor.move(self, map, x, y)
end
name = "Tales of Middle Earth"
short_name = "tome"
version = {4,0,0}
starter = "tome.load"
local Map = require "engine.Map"
local Entity = require "engine.Entity"
local Actor = require "tome.class.Actor"
local map = Map.new(20, 20)
local floor = Entity.new{display='#', color_r=100, color_g=100, color_b=100}
local e1 = Entity.new{display='#', color_r=255, block_sight=true}
local e2 = Entity.new{display='#', color_g=255, block_sight=true}
local e3 = Entity.new{display='#', color_b=255, block_sight=true}
local e4 = e3:clone{color_r=255}
for i = 0, 19 do for j = 0, 19 do
map(i, j, 1, floor)
end end
map(8, 6, Map.TERRAIN, e4)
map(8, 7, Map.TERRAIN, e2)
map(8, 8, Map.TERRAIN, e3)
map(9, 6, Map.TERRAIN, e1)
map(9, 7, Map.TERRAIN, e2)
map(9, 8, Map.TERRAIN, e3)
map(10, 6, Map.TERRAIN, e1)
map(10, 7, Map.TERRAIN, e2)
map(10, 8, Map.TERRAIN, e3)
player = Actor.new{name="player!", display='#', color_r=125, color_g=125, color_b=0}
player:move(map, 2, 3)
map:setCurrent()
......@@ -129,6 +129,7 @@ int main (int argc, char *argv[])
{
PHYSFS_init(argv[0]);
PHYSFS_mount("game/", "/", 1);
PHYSFS_mount("game/modules/tome", "/tome", 1);
TTF_Init();
......
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