~jordanreger/cc

70925adabf97ecfd96e1141590684a3891adf002 — Jordan Reger 3 months ago 4a4bb85
feat: added "ring" page
1 files changed, 53 insertions(+), 16 deletions(-)

M xOS/.x
M xOS/.x => xOS/.x +53 -16
@@ 3,6 3,8 @@ local background_color = colors.lightGray

local window = window.create(term.current(), 1, 1, width, height)

local page = "home"

function setup()
    window.setBackgroundColor(background_color)
    if (background_color ~= colors.black and background_color ~= colors.gray) then


@@ 14,27 16,62 @@ function setup()
end

function render()
    window.setCursorPos(width / 2, height / 2)
    window.write("xx")
    window.setCursorPos(width / 2, height / 2 + 1)
    window.write("xx")
    if page == "home" then
        render_home()
    end

    if page == "ring" then
        ring()
        page = "home"
    end
end

function render_home()
    window.clear()

    window.setCursorPos(width / 2 - 1, height / 2)
    window.write("Ring")
    window.setCursorPos(width / 2 - 3, height / 2 + 1)
    window.write("Shutdown")
end

function ring()
    rednet.open("back")

    local receiver_id = 17

    rednet.send(receiver_id, "gps")
    local r_id, r_pos = rednet.receive()

    local r_x, r_y, r_z = r_pos[1], r_pos[2], r_pos[3]
    local receiver = vector.new(r_x, r_y, r_z)

    local x, y, z = gps.locate()
    local client = vector.new(x, y, z)

    function update_pos()
        x, y, z = gps.locate()
        client = vector.new(x, y, z)
    end

    while true do
        local displacement = receiver - client
        if ((displacement.x > 0) and (displacement.x < 2)) and ((displacement.y < 2) and (displacement.y > 0)) and ((displacement.z > -1) and (displacement.z < 1)) then
            rednet.send(receiver_id, "open")
        end
        
        if((displacement.x < 0) and (displacement.x > -2)) and ((displacement.y < 2) and (displacement.y > 0)) and ((displacement.z > -1) and (displacement.z < 1)) then
            rednet.send(receiver_id, "open")
        end
        update_pos()
    end
end

function on_click()
    local e, id, x, y = os.pullEvent("mouse_click")
    if e then
        if x == width / 2 and y == height / 2 then
            window.setCursorPos(1, 1)
            window.write("top left")
        elseif x == width / 2 + 1 and y == height / 2 then
            window.setCursorPos(1, 1)
            window.write("top right")
        elseif x == width / 2 and y == height / 2 + 1 then
            window.setCursorPos(1, 1)
            window.write("bottom left")
        elseif x == width / 2 + 1 and y == height / 2 + 1 then
            window.setCursorPos(1, 1)
            window.write("bottom right")
        if (x >= width / 2 - 1 and x <= width / 2 + 2 and y == height / 2) then
            page = "ring"
        else
            return
        end