Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ThreeD")
- objects = {
- {oType = "frame", x = 4, y = 0, z = 0, width = 1, height = 1, length = 1, color = colors.blue},
- {oType = "flip", x = 4, y = 0, z = 4, width = 1, height = 1, color = colors.blue},
- }
- playerX = -10
- playerY = 0
- playerZ = 0
- playerSpeed = 0.5
- playerDirectionHor = 0
- playerDirectionVer = 0
- screenWidth = term.getSize()
- screenHeight = 19
- groundColor = colors.lime
- FoV = 140
- ThreeDFrame = ThreeD.newFrame(1, 1, screenWidth, screenHeight, FoV, playerX, playerY, playerZ, playerDirectionVer, playerDirectionHor, colors.lime)
- function degreeToRadian(degree)
- return degree * math.pi / 180
- end
- function drawObjects()
- local objectsToSort = textutils.unserialize(textutils.serialize(objects))
- local sortedObjects = {}
- while (table.getn(objectsToSort) > 0) do
- local biggestDistance = 0
- local biggestDistanceNr = 0
- for objNr, object in pairs(objectsToSort) do
- local distance = ((math.abs(playerX - object.x)) ^ 2 + (math.abs(playerZ - object.z)) ^ 2) ^ 0.5
- if (distance > biggestDistance) then
- biggestDistance = distance
- biggestDistanceNr = objNr
- end
- end
- table.insert(sortedObjects, objectsToSort[biggestDistanceNr])
- table.remove(objectsToSort, biggestDistanceNr)
- end
- term.setBackgroundColor(colors.white)
- term.clear()
- ThreeDFrame:drawGround()
- for objNr, object in pairs(sortedObjects) do
- ThreeDFrame:drawObject(object)
- end
- end
- function drawScreen()
- drawObjects()
- end
- function inputPlayer()
- local sEvent, key = os.pullEventRaw()
- if (sEvent == "key") then
- local dX = 0
- local dY = 0
- local dZ = 0
- if (key == keys.left) then
- playerDirectionHor = (playerDirectionHor - 10)
- if (playerDirectionHor <= -180) then
- playerDirectionHor = playerDirectionHor + 360
- end
- elseif (key == keys.right) then
- playerDirectionHor = (playerDirectionHor + 10)
- if (playerDirectionHor >= 180) then
- playerDirectionHor = playerDirectionHor - 360
- end
- elseif (key == keys.down) then
- playerDirectionVer = (playerDirectionVer - 10)
- if (playerDirectionVer <= -180) then
- playerDirectionVer = playerDirectionVer + 360
- end
- elseif (key == keys.up) then
- playerDirectionVer = (playerDirectionVer + 10)
- if (playerDirectionVer >= 180) then
- playerDirectionVer = playerDirectionVer - 360
- end
- elseif (key == keys.space) then
- dY = playerSpeed
- elseif (key == keys.leftShift) then
- dY = -playerSpeed
- elseif (key == keys.w) then
- dX = playerSpeed * math.cos(degreeToRadian(playerDirectionHor))
- dZ = playerSpeed * math.sin(degreeToRadian(playerDirectionHor))
- elseif (key == keys.s) then
- dX = -playerSpeed * math.cos(degreeToRadian(playerDirectionHor))
- dZ = -playerSpeed * math.sin(degreeToRadian(playerDirectionHor))
- elseif (key == keys.a) then
- dX = playerSpeed * math.cos(degreeToRadian(playerDirectionHor - 90))
- dZ = playerSpeed * math.sin(degreeToRadian(playerDirectionHor - 90))
- elseif (key == keys.d) then
- dX = playerSpeed * math.cos(degreeToRadian(playerDirectionHor + 90))
- dZ = playerSpeed * math.sin(degreeToRadian(playerDirectionHor + 90))
- end
- if (dX ~= nil) then
- playerX = playerX + dX
- end
- if (dY ~= nil) then
- playerY = playerY + dY
- end
- if (dZ ~= nil) then
- playerZ = playerZ + dZ
- end
- ThreeDFrame.playerX = playerX
- ThreeDFrame.playerY = playerY
- ThreeDFrame.playerZ = playerZ
- ThreeDFrame.playerDirectionHor = playerDirectionHor
- ThreeDFrame.playerDirectionVer = playerDirectionVer
- end
- end
- while true do
- inputPlayer()
- drawScreen()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement