Posted 07 November 2013 - 04:09 PM
Title: how to print text based on tables?
im making a pacman game for computercraft, i made these tables:
im making a pacman game for computercraft, i made these tables:
foods = {"o", "0","."}
foodscore = {5, 10, 1}
foodXpos = {5, 15, 25}
foodYpos = {5, 15, 25}
what i want to do is to draw those contents in their respective positions, using print(""), and then make something like collision check, if pacman x and y is equal to any of these x and y positions of these tables, delete their respective variables, this is the code:
x = 10
food = "o"
foodX = 5
foodY = 5
foodE = true
foodcolor = colors.red
y = 10
pac = "<"
hnum = 1
function Update()
term.clear()
term.setCursorPos(x, y)
term.setTextColor(colors.yellow)
print(pac)
term.setCursorPos(foodX, foodY)
term.setTextColor(foodcolor)
print(food)
if x == foodX and y == foodY and foodE == true then
food = ""
term.setCursorPos(x, y)
term.setTextColor(colors.yellow)
print(pac)
foodX = 0
foodY = 0
foodE = false
end
end
while true do
local sEvent, param = os.pullEvent("key")
if sEvent == "key" then
if param == 205 then
x = x + 1
pac = "<"
end
if param == 203 then
x = x - 1
pac = ">"
end
if param == 200 then
y = y - 1
pac = "V"
end
if param == 208 then
y = y + 1
pac = "A"
end
Update()
end
end
Edited on 07 November 2013 - 03:12 PM