Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local charX = 0
- local charY = 0
- local currentMap = ""; -- DO NOT CHANGE
- local maps = {
- ["map_0"] = {
- " XXX",
- " XBX",
- "XXXXXXXBX",
- "XZBBBBBBX",
- "XXXXXXXBX",
- " XBX",
- " XXX",
- }
- }
- local colorSet = {
- ["X"] = colors.lightGray,
- ["B"] = colors.black,
- ["Z"] = colors.cyan,
- }
- local spawnX = 0
- local spawnY = 0
- local justTeleported = false
- local blockInfo = {
- }
- function isPortalSurface( posX, posY )
- if isPortal( posX, posY ) == 1 or isPortal == 2 then
- return false
- elseif blockInfo[ posX.. "/" ..posY ] then
- return true
- end
- return false
- end
- function isPortal( posX, posY )
- if portalBlueX == posX and portalBlueY == posY then
- return 0
- elseif portalRedX == posX and portalRedY == posY then
- return 1
- end
- return false
- end
- function loadmap( map )
- term.setBackgroundColour( colors.gray )
- term.clear()
- local theMap = maps[map]
- for i=1,#theMap do
- for iv=1,#(theMap[i]) do
- local pixel = string.sub( theMap[i], iv, iv )
- if colorSet[pixel] then
- paintutils.drawPixel( 3+iv, 3+i, colorSet[pixel] )
- if map ~= currentMap then --If first time loading then...
- if pixel == "Z" then
- charX = 3+iv
- charY = 3+i
- elseif pixel == "X" then
- blockInfo[3+iv.. "/" ..3+i] = true
- end
- end
- end
- end
- end
- if map ~= currentMap then
- currentMap = map
- end
- end
- local portalBlueX = 0
- local portalBlueY = 0
- local portalRedX = 0
- local portalRedY = 0
- local portalTeleport = nil
- local gravity = nil
- function redraw()
- loadmap( "map_0" )
- paintutils.drawPixel( portalBlueX, portalBlueY, colors.blue )
- paintutils.drawPixel( portalRedX, portalRedY, colors.red )
- term.setBackgroundColour( colors.black )
- term.setTextColour( colors.lime )
- term.setCursorPos( charX, charY )
- write("A")
- end
- while true do
- redraw()
- if isPortal( charX, charY ) then
- if portalTeleport == nil then
- portalTeleport = os.startTimer( 0.5 )
- end
- elseif not isPortalSurface( charX, charY-1 ) then
- if portalTeleport == nil and gravity == nil then
- gravity = os.startTimer( 0.5 )
- justTeleported = false
- end
- end
- local event, key, keyX, keyY = os.pullEvent()
- if event == "key" then
- oldCharX = charX
- oldCharY = charY
- if key == keys.left then
- charX = charX -1
- justTeleported = false
- elseif key == keys.right then
- charX = charX +1
- justTeleported = false
- end
- if isPortalSurface( charX, charY ) then
- charX = oldCharX
- charY = oldCharY
- justTeleported = false
- end
- elseif event == "mouse_click" then
- if isPortalSurface( keyX, keyY ) then
- if key == 1 then
- portalBlueX = keyX
- portalBlueY = keyY
- elseif key == 2 then
- portalRedX = keyX
- portalRedY = keyY
- end
- end
- elseif event == "timer" and key == gravity then
- gravity = nil
- if isPortal( charX, charY ) ~= true then
- charY = charY +1
- end
- elseif event == "timer" and key == portalTeleport then
- if not justTeleported then
- local portalType = isPortal( charX, charY )
- portalTeleport = nil
- if portalType == 0 then
- charX = portalRedX
- charY = portalRedY
- elseif portalType == 1 then
- charX = portalBlueX
- charY = portalBlueY
- end
- justTeleported = true
- end
- portalTeleport = nil
- elseif event == "char" then
- if key == "r" or key == "R" then
- portalBlueX = 0
- portalBlueY = 0
- portalRedX = 0
- portalRedY = 0
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment