Posted 02 February 2013 - 01:52 PM
Hi all! I am trying to create a Mario game in CC, and need help with the redraw function, because all it does is print an "@" at Mario's head. The getMario is just for debugging.
Code:
Thanks in advance for your help! ;)/>
Code:
Spoiler
local args = {...}
local number = 1
local X,Y = 1,1
local mario = {x=9, y=7}
local function getMario()
return mario.x, mario.y
end
local function drawMario()
local y,x = term.getCursorPos()
write("X")
term.setCursorPos(y-1, x)
write("@")
term.setCursorPos(y,x)
end
local function resetColors()
term.setTextColor(1)
term.setBackgroundColor(colors.black)
end
local function load(file)
local filedata = {}
if fs.exists(file) then
local r = fs.open(file, "r")
repeat
local ok = r.readLine()
if ok then
table.insert(filedata, ok)
else
local error = true
end
until error
return filedata
else
return nil
end
end
local function redraw()
term.clear()
term.setCursorPos(1,1)
local x,y = getMario()
local dim,s = term.getSize()
local xL, xL2 = math.ceil(x - dim), math.floor(x + dim)
for k,v in ipairs(load(args[1])) do
for i=xL, xL2 do
if string.sub(v, i, i) == "C" or string.sub(v,i,i) == "?" then
term.setCursorPos(Y,X)
term.setTextColor(colors.white)
term.setBackgroundColor(colors.yellow)
write("?")
elseif string.sub(v,i,i) == "#" or string.sub(v,i,i) == "H" then
term.setCursorPos(Y,X)
term.setTextColor(colors.black)
term.setBackgroundColor(colors.brown)
write("#")
elseif string.sub(v,i,i) == "=" then
term.setCursorPos(Y,X)
term.setBackgroundColor(colors.brown)
write(" ")
elseif string.sub(v,i,i) == "O" then
term.setCursorPos(Y,X)
term.setTextColor(colors.yellow)
write("O")
end
resetColors()
X = X+1
end
X = 1
Y = Y+1
end
term.setCursorPos(x,y)
drawMario()
end
redraw()
Thanks in advance for your help! ;)/>