Advertisement
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 blockInfo = {
- }
- function isPortalSurface( posX, posY )
- if blockInfo[ posX.. "/" ..posY ] then
- return true
- end
- return false
- end
- function isPortal( posX, posY )
- if portalBlueX == posX and portalBlueY == posY then
- return 0
- elseif portalRedY == posY and portalRedX == posX 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
- 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()
- local event, key, keyX, keyY = os.pullEvent()
- if event == "key" then
- oldCharX = charX
- oldCharY = charY
- if key == keys.left then
- charX = charX -1
- elseif key == keys.right then
- charX = charX +1
- elseif key == keys.up then
- charY = charY -1
- elseif key == keys.down then
- charY = charY +1
- end
- if isPortalSurface( charX, charY ) then
- charX = oldCharX
- charY = oldCharY
- 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 == "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
Advertisement