Posted 24 April 2012 - 03:42 AM
I'm making a game with portals but I can't get the teleportation correct.
When you start, O = portal 1 and 0 = portal 2
The game works fine, its just that you don't teleport to the other portal.
( I know i can compact
portalRedX = 0
portalRedY = 0
but I just didn't want to for this version)
Also "X: " is just for debugging.
Player position on screen: x/2, y-10
Map X:local scroll = 0 (line 1)
Map Y:local jump = 0 (line 2)
First, press O to make a portal, then somewhere else, press 0.
Walk into a portal
When you start, O = portal 1 and 0 = portal 2
The game works fine, its just that you don't teleport to the other portal.
local scroll = 0;
local jump = 0;
local char = ">";
local coins = 0;
local x,y = term.getSize()
local level = 1;
local portalBlue = false
local portalBlueX = 0
local portalBlueY = 0
local portalRed = false
local portalRedX = 0
local portalRedY = 0
function newPortal(type)
if type == 1 then
term.setCursorPos(portalRedX - scroll, portalRedY + jump)
else
term.setCursorPos(portalBlueX - scroll, portalBlueY + jump)
end
if type == 1 and portalRed == true then
if portalRedX - scroll ~= x-1 then
if(portalRedX - scroll == x/2 and portalRedY + jump == y-10)then
if portalBlue == true then scroll = (portalBlueX)end
else
write("O")
end
end
elseif type == 2 and portalBlue == true then
if portalBlueX - scroll ~= x-1 then
if(portalBlueX - scroll == x/2 and portalBlueY + jump == y-10)then
if portalRed == true then scroll = (portalRedX)end
else
write("0")
end
end
end
end
function floor(param1)
for i=1,x-1 do
term.setCursorPos(i, y-9 + jump)
write(param1)
end
end
function newTeleporter(posX, posY, levelid, title)
term.setCursorPos(posX - scroll, posY + jump)
if posX - scroll ~= x-1 then --
if(posX - scroll == x/2 and posY + jump == y-10)then
level = levelid
else
write(title)
end
end
end
function world()
if(level == 1)then
floor("A")
newTeleporter(x/2-3, y-10, 999, "X")
elseif(level == 999)then
floor("O")
end
end
function redraw()
term.clear()
term.setCursorPos(1,1)
write("Coins: " ..coins.. " World: 0-" ..level.. " X: " ..scroll)
newPortal(1)
newPortal(2)
term.setCursorPos(x/2, y-10)
write(char)
world()
end
while true do
redraw()
local event, a, b = os.pullEvent();
if(event == "char" and a == "a")then
scroll = scroll-1
char = "<"
elseif(event == "char" and a == "d")then
scroll = scroll+1
char = ">"
elseif(event == "key" and a == 57)then
jump = 1
for i=1,4 do
sleep(0.1)
jump = i
redraw()
end
for i=1,4 do
sleep(0.1)
jump = jump-i
redraw()
end
jump = 0
elseif(event == "char" and a == "o")then
portalRed = true
if char == ">" then
portalRedX = x/2 + scroll +1
portalRedY = y-10
else
portalRedX = x/2 + scroll -1
portalRedY = y-10
end
elseif(event == "char" and a == "0")then
portalBlue = true
if char == ">" then
portalBlueX = x/2 + scroll +1
portalBlueY = y-10
else
portalBlueX = x/2 + scroll -1
portalBlueY = y-10
end
elseif(event == "char" and a == "r")then
portalBlue = false
portalBlueX = 0
portalBlueY = 0
portalRed = false
portalRedX = 0
portalRedY = 0
end
end
( I know i can compact
portalRedX = 0
portalRedY = 0
but I just didn't want to for this version)
Also "X: " is just for debugging.
Player position on screen: x/2, y-10
Map X:local scroll = 0 (line 1)
Map Y:local jump = 0 (line 2)
First, press O to make a portal, then somewhere else, press 0.
Walk into a portal