Adding multiplayer help.

Alright so I’m using code that @dave1707 had created for multiplayer and trying to integrate it with my fixed FPS game, however I’m stuck and don’t know why I can’t get it to work
Here’s my project and Dave’s code

--all code by JakAttak
--# Main
function setup()
    local connectionMade = function()
        output.clear()
        parameter.clear()
        print("Connected!")
 
        gameSetup()
    end
 
    multihandler = Multiplayer(receiveData, connectionMade)
 
    parameter.action("Host Game", function()
        multihandler:hostGame()
    end)
 
    parameter.action("Find Game", function()
        multihandler:findGame()
    end)
 
    parameter.action("Join Game", function()
        if other_ip then
            multihandler:joinGame(other_ip, other_port)
        else
            parameter.text("other_ip", "")
            parameter.text("other_port", "")
 
            print("Fill in the host's ip and port, then click join game again")
        end
    end)
end
 
function gameSetup()
    canvas = image(WIDTH, HEIGHT)
    parameter.color("pen_col", color(0, 255, 0))
    parameter.integer("pen_size", 2, 100, 10)
    parameter.action("clear", function()
        clear()
        multihandler:sendData("clear")
    end)
    pen_touch = nil
    last_point = vec2(0, 0)
end
 
function clear()
    canvas = image(WIDTH, HEIGHT)
end
 
function receiveData(d)
    if d == "clear" then
        clear()
    else
        local tb = loadstring("return " .. d)()
        drawPoint(tb.point, tb.last_point, tb.drawing_line, tb.pen_size, tb.pen_col)
    end
end
 
function drawPoint(point, lastPoint, drawingLine, penSize, penCol)
    pushStyle()
    setContext(canvas)    -- Start drawing to screen image
 
    fill(penCol) stroke(penCol)    -- Set draw color to color var
 
    strokeWidth(penSize)
    if drawingLine then
        line(point.x, point.y, lastPoint.x, lastPoint.y)    -- draw a line between the two points
    else
        ellipse(point.x, point.y, penSize)    -- Place a dot there
    end
 
    setContext()
    popStyle()
end
 
function draw()
    background(255, 255, 255, 255)
 
    multihandler:update()
 
    if multihandler.connected then
        sprite(canvas, WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)    -- Draw the image onto the screen
    else
        fill(0)
        text("Waiting for connection...", WIDTH / 2, HEIGHT / 2)
    end
end
 
function vec2ToStr(vec)
    return "vec2" .. tostring(vec)
end
 
function colToStr(col)
    return "color(" .. col.r .. ", " ..  col.g .. ", " .. col.b.. ", " .. col.a .. ")"
end
 
function touched(t)
    if multihandler.connected then
        local p, lp, d, ps, pc = vec2(t.x, t.y), last_point, drawing_line, pen_size, pen_col
        if t.state == BEGAN then
            pen_touch = t.id
        end
        if t.id == pen_touch then
            drawPoint(vec2(t.x, t.y), last_point, drawing_line, pen_size, pen_col)
            drawing_line = true
            last_point = vec2(t.x, t.y)
        end
        if t.state == ENDED then
            drawing_line = false
            pen_touch = nil
        end
 
        multihandler:sendData("{ point = " .. vec2ToStr(p) .. ", last_point = " .. vec2ToStr(lp) .. ", drawing_line = " .. tostring(d) .. ", pen_size = " .. ps .. ", pen_col = " .. colToStr(pc) .. " }")
    end
end
 
--multiplayer library follows
--# Multiplayer
 
local socket = require("socket")
 
Multiplayer = class()
 
function Multiplayer:init(dcb, ccb)
    self.my_ip, self.my_port = self:getLocalIP(), 5400
    self.peer_ip, self.peer_port = nil, self.my_port
 
    self.client = socket.udp()
    self.client:settimeout(0)
 
    self.connected = false
    self.is_host = false
    self.searching = false
 
    self.dataCallback = dcb or function() end
    self.connectedCallback = ccb or function() end
end
 
-- Returns this iPad's local ip
function Multiplayer:getLocalIP()
    local randomIP = "192.167.188.122"
    local randomPort = "3102" 
    local randomSocket = socket.udp() 
    randomSocket:setpeername(randomIP,randomPort) 
 
    local localIP, somePort = randomSocket:getsockname()
 
    randomSocket:close()
    randomSocket = nil
 
    return localIP
end
 
-- Set the connected status and call the connection callback if needed
function Multiplayer:setConnectedVal(bool)
    self.connected = bool
 
    if self.connected then
        self.connectedCallback()
    end
end
 
function Multiplayer:setHostVal(bool)
    self.is_host = bool
end
 
-- Prepare to be the host
function Multiplayer:hostGame()
    print("Connect to " .. self.my_ip .. ":" .. self.my_port)
 
    self.client:setsockname(self.my_ip, self.my_port)
 
    self:setConnectedVal(false)
    self.is_host = true
    self.searching = false

    -----
end
 
-- Find a host
function Multiplayer:findGame()
    print("Searching for games...")
 
    self.searching = true
 
    local ip_start, ip_end = self.my_ip:match("(%d+.%d+.%d+.)(%d+)")
    for i = 1, 255 do
        if i ~= tonumber(ip_end) then
            tween.delay(0.01 * i, function()
                self.client:setsockname(ip_start .. i, self.my_port)
                self.client:sendto("connection_confirmation", ip_start .. i, self.my_port)
            end)
        end
    end
end
 
-- Prepare to join a host
function Multiplayer:joinGame(ip, port)
    self.peer_ip, self.peer_port = ip, port
 
    self.client:setsockname(ip, port)
 
    self.is_host = false
    self.searching = false
 
    self:sendData("connection_confirmation")
end
 
-- Send data to the other client
function Multiplayer:sendData(msg_to_send)
    if self.peer_ip then
        self.client:sendto(msg_to_send, self.peer_ip, self.peer_port)
    end
end
 
-- Check for data received from the other client
function Multiplayer:checkForReceivedData()
    local data, msg_or_ip, port_or_nil = self.client:receivefrom()
    if data then
            -- Store the ip of this new client so you can send data back
            self.peer_ip, self.peer_port = msg_or_ip, port_or_nil
 
            if not self.connected and data == "connection_confirmation" then
                self:sendData("connection_confirmation")
                self:setConnectedVal(true)
            end
 
            -- Call callback with received data
            if data ~= "connection_confirmation" then
                self.dataCallback(data)
            end
    end
end
 
function Multiplayer:update()
    self:checkForReceivedData()
end

@chrislightsaber When you post code, put 3 ~~~ on a line before and after the code. I added them to your code above so it shows correctly. You say you can’t get it to work, but you’re not saying what you’re doing and what’s not happening. As for your zipped up code, I can’t help you with it because I don’t mess with zip files.

Oh so essentially I replaced the original setup with some of the code from multiplayer and placed the origional setup under start game after the game is hosted. Ok, try and upload the main files a different way so you don’t have to mess with the zip @dave1707

Alright I’m about to make a lot of code posts, here’s all the codes (each class is a different post) also enable craft and voxel player for it to work

function cam() 
    intzoom = 0.2*((intzoom*4 + zoom))
    fov = (95-(intzoom*55))
    angle = angleoffset+ anglebase
    topangle = topanglebase+topangleoffset
       camspot = vec3(camerax,cameray,cameraz)
      topanglebase = math.min(90,math.max(-90,topanglebase))
    topangle = math.min(89.9,math.max(-89.9,topangle))
    fps =  math.ceil(1/DeltaTime)

 --   rotate(yaw)
    pushMatrix()
    perspective(fov, WIDTH/HEIGHT)
    local camdown = vec2(distance/(fov/44),0):rotate(math.rad(topangle))
    
local camplane = vec2(camdown.x,0):rotate(math.rad(angle))

    camera(camplane.x+camspot.x,camdown.y+camspot.y,camplane.y+camspot.z, camspot.x,camspot.y,camspot.z, 0,4,0)
    

    
    end
 
    
    function generatevisibility()   
        local dim = leveldim
        
        for i = -dim,dim do
            end
            end
    
function drawground(tex)
    
    local dat = vec2(camerax,cameraz)/(2048)
    local flank = vec2(math.ceil(dat.x),math.ceil(dat.y))
    
    for i = flank.x-5,6+flank.x do
        for j = flank.y-5,6+flank.y do
            if dat:dist(vec2(i,j)) < 2 then
                drawplane(tex,i*2048,31.9,j*2048,32,32,32,0,90,90)
            end
        end
    end
end
function definefacerot()
    white = setflat(color(255, 255, 255, 255))
   red = setflat(color(255, 0, 0, 255))
blue = setflat(color(0, 0, 255, 255))
green = setflat(color(0, 255, 0, 255))
black =setflat(color(3, 3, 3, 255))
dark =setflat(color(33, 34, 35, 255))
-- = setflat(color(233, 218, 61, 255))

local face = {

{90,1,0,0}, -- north     3
 {180,1,0,0}, --back   2
 {0}, --front        1

{270,0,1,0}, -- west     6
{90,0,1,0}, -- east      5
{270,1,0,0}, -- south    4

nil
}


cubefacerot= face
end

function setflat(culurr)
    
local cull = image(1,1)

cull:set(1,1,culurr)

return cull
end

function drawcube(xx,yy,zz,tex,size,shading,rra,rrb,rrc)
    if shading == nil then shading = 0 end
    pushMatrix()
    translate(xx,yy,zz)
    if rra == nil then else rotate(rra) end
     if rrb == nil then else rotate(rrb,1,0,0) end
     if rrc == nil then else rotate(rrc,0,0,1) end
    scale(size/64,size/64,size/64)
    pushMatrix()
    for i = 1,6 do
        pushMatrix()
rotate(unpack(cubefacerot[i]))
if shading > 0 then
        tint(255-(i)*shading) 
    end
        translate(0,0,-32)
        sprite(tex,0,0,64)
        popMatrix()
--rect(i*111,0,99,99)
 end
noTint()
popMatrix()

popMatrix()
end
    
—Entity
function shoot(div)
    if div == nil then div = 9 end
            if muzzle == 1 then
            drawmodel("bullet",33,-8,0,math.random(-0,100)/5,nil,math.random(-0,100)/5,5) 
        --drawmodel("bullet",33,-8,0,math.random(-shotrange,shotrange)/div,nil,math.random(-shotrange,shotrange)/div,5)
    end
    --craft.model("Primitives:Sphere")
    
    end
function flash()
muzzle = 1
    end
  function muzzledraw(other)
        if muzzle == 1
            
                then
        pushMatrix()

       

noStroke()
fill(255, 255, 255, 255)
if other == nil then other = 0 end

rotate(90,0,1,0)
translate(0,-8,33)

rotate(math.random(-44,45))
rect(0,0,1,math.random(17,19))
rect(0,0,math.random(17,19),1)

rect(0,0,6,6)

popMatrix() end
end  
    function hand(xx,yy,zz)
        modelcube(xx/10,yy/10,zz/10,skin,4,5,3.5)
    end
function drawmodel(index,xx,yy,zz,rra,rrb,rrc,size)
pushMatrix()
if size == nil then size = 1 end
translate(xx,yy,zz)
    if rra == nil then else rotate(rra,0,1,0) end
     if rrb == nil then else rotate(rrb,1,0,0) end
     if rrc == nil then else rotate(rrc,0,0,1) end
    scale (size,size,size)
    
    if index == "ramp" then
        
        rotate(45,1,0,0)
        modelcube(0,0,0,cork,55,4,89,19)
        end
        
        
        if index == "bullet" then
pushMatrix()
sprite(white,500,0,1000,1)
rotate(90,1,0,0)
sprite(white,500,0,1000,1)
popMatrix()
end
    
    if index == "cube" then
        rotate(170,1,0,0)
        
        modelcube(0,0,0,55,500,20000,0)
        sprite("Documents:Stone Brick",500,0,100000,1000)
        end
    
    if index == "cube2" then
        rotate(2000,35,30,25)
        modelcube(0,0,0,gunbarrel, 0,1000,1000,0)
        end
    
if index == "rifle" then
    translate(intzoom-recoil,-intzoom*1.5,(1-intzoom)*7.5)
    
    shoot()
    rotate(recoil*3,0,0,1)

--hand(50,-155,-7)
--hand(-122,-145,7)

modelcube(-3,-10,0,dark,20,5,4,12) 
modelcube(-20,-12,0,gunbarrel,13,8,3,12) 
modelcube(-1,-8,0,gunbarrel, 4,2,2,12) 
        --modelcube(-1,-8,0,gunbarrel, 4,2,2,12)
modelcube(15,-8,0,gunbarrel,34,3,3,12)  
modelcube(31,-6,0,gunbarrel,1,1,1,12) 
modelcube(5,-17,0,dark,3,9,2)
end

if index == "minigun" then

    translate(intzoom-recoil*2,-intzoom*1.5,(1-intzoom)*7.5)
            hand(77,-131,-17)
hand(-65,-145,7)
    muzzledraw()
    
    local spotty = vec2(2,2):rotate(ElapsedTime*9)
    for i = 1,5 do
        modelcube(15,spotty.x-10,spotty.y,minigunbarrel,25,2,2,22)
        spotty = spotty:rotate(math.rad(72))
        end
          modelcube(-1,-10,0,gunbarrel,7,7,7,12) 
        modelcube(1,-7,0,gunbarrel,5,3,5,12) 
    end

if index == "shotgun" then

    translate(intzoom-recoil,-intzoom*1.5,(1-intzoom)*7.5)
    for i = 0,math.random(3,5) do
    shoot(3)
    end
    rotate(recoil*4,0,0,1)
        hand(66-limit((recoil-4)*44,0,47),-111,-11)
hand(-122,-122,7)
       modelcube(-2,-10,0,dark,26,3,3,12) 
       modelcube(-21,-12,0,gunbody,12,7,4,12) 
    modelcube(-2,-9,0,gunbody,11,3,5,12) 
modelcube(9,-8,-1.2,gunbarrel,25,2,2,12) 
   modelcube(9,-8,1.2,gunbarrel,25,2,2,12) 

end
    
    
popMatrix()
end
    
function definemodels()
   local img = image(8, 8)
img:set(2,4,255,255,0,255)
img:set(2,5,255,255,0,255)
img:set(3,3,255,255,0,255)
img:set(3,4,255,255,154,255)
img:set(3,5,255,255,154,255)
img:set(3,6,255,255,0,255)
img:set(4,2,255,255,0,255)
img:set(4,3,255,255,154,255)
img:set(4,4,255,255,255,255)
img:set(4,5,255,255,255,255)
img:set(4,6,255,255,154,255)
img:set(4,7,255,255,0,255)
img:set(5,2,255,255,0,255)
img:set(5,3,255,255,154,255)
img:set(5,4,255,255,255,255)
img:set(5,5,255,255,255,255)
img:set(5,6,255,255,154,255)
img:set(5,7,255,255,0,255)
img:set(6,3,255,255,0,255)
img:set(6,4,255,255,154,255)
img:set(6,5,255,255,154,255)
img:set(6,6,255,255,0,255)
img:set(7,4,255,255,0,255)
img:set(7,5,255,255,0,255)
muzzleflash = img

    grass = image(12,12)
    dirt = image(12,12)
    gunbody = image(12,12)
    gunhandle = image(12,12)
    gunbarrel = image(12,12)
    minigunbarrel = image(12,12)
    skin = image(12,12)
    cork = image(12,12)
    test = image(1,12)
    --display.newImage( "image.png" )
for i = 1,12 do
    for j = 1,12 do
grass:set(i,j,(colornoise(77,16)), colornoise(167,24), colornoise(70,49), 255)
dirt:set(i,j,(colornoise(77,16)), colornoise(167,24), colornoise(70,49), 255) 
--dirt:set(i,j,(colornoise(106,16)), colornoise(88,13), colornoise(59), 255)
gunbody:set(i,j,colornoise(150), colornoise(119), colornoise(79), 255)
gunhandle:set(i,j,colornoise(122), colornoise(100), colornoise(66), 255)
gunbarrel:set(i,j,colornoise(152,2),colornoise(152,2),colornoise(150,2),255)
minigunbarrel:set(i,j,colornoise(199,6),colornoise(199,5),colornoise(199,4),255)
cork:set(i,j,colornoise(209,6),colornoise(199,5),colornoise(23,4),255)
skin:set(i,j,colornoise(190,6),colornoise(160,5),colornoise(120,4),255)
        test:set(i,j,5,100,5,255)


end
end
grasshires = image(128,128)
for i = 1,128 do
    for j = 1,128 do
grasshires:set(i,j,(colornoise(66,9)), colornoise(160,15), colornoise(51,20), 255)
end
end
end

function colornoise(dull,derr)
    if derr == nil then derr = 11 end
    return dull +math.random(-derr,derr) end
    
    function drawplane(tex,xx,yy,zz,sx,sy,sz,rra,rrb,rrc)
        pushMatrix()
            translate(xx,yy,zz)
                if rra == nil then else rotate(rra,0,1,0) end
     if rrb == nil then else rotate(rrb,1,0,0) end
     if rrc == nil then else rotate(rrc,0,0,1) end
    scale(sx,sy,sz)
        sprite(tex,0,0,64)
        popMatrix()
    end
    
function modelcube(xx,yy,zz,tex,sx,sy,sz,shading)
    if shading == nil then shading = 0 end
    pushMatrix()
    translate(xx,yy,zz)
    scale(sx/64,sy/64,sz/64)
    pushMatrix()
    for i = 1,6 do
        pushMatrix()
rotate(unpack(cubefacerot[i]))
if shading > 0 then
        tint(255-(i)*shading) end
        translate(0,0,-32)
        sprite(tex,0,0,64)
        popMatrix()
rect(i*111,0,99,99)
 end
noTint()
popMatrix()
popMatrix()
end
FPS = class()

function FPS:init()
    --juice.text.init(self, "FPS", 0,0)
    self.pos = vec2(0,0)
    
    self.fps = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
    self.idx = 0
end

function FPS:average()
    local v = 0
    for i = 1,#self.fps do
        v = v + self.fps[i]
    end
    v = (v/(#self.fps))
    
    self.string = string.format("FPS: %.1f",1/v)
end

function FPS:update(dt)
    self.fps[self.idx + 1] = dt
    
    self.idx = (self.idx + 1)%(#self.fps)
    
    self:average()
end

function FPS:draw()
    pushStyle()
    fontSize(22)
    fill(255)
    text( self.string, self.pos.x, self.pos.y )
    popStyle()
end

--[[
each level is based on 2d arrays of data. the first value is an elevation map. this tells the renderer how high, in 64 pixel units, something is.
after that is texture data- the top texture, and the side texture.

these are stored as a basic table and vec2 data. x is side texture and y is top texture.

after that are objects, such as ramps. these have a rotation value of 0,1,2 or 3. they are placed on top of the pile at thier lowest. since it is not assumed that every space has an object, they are placed in an array and given coordinates in vec3 format, where 1 is a 64 pixel length.

each object follows this format
object[1] = the type of object
object[2] = unique id
object[3] = the position, in vec3
object[4] = the angle as rotated from above
object[5] = whatever. used for coded objects, the renderer ignores it
--]]


    
function texturepallette(value)
    local pal = {}
    
    if value == 1 then
        pal = {"dirt","grass"}
    end
    return pal
    
end

function genlevel(dim)
    local space = {}
    for i = 1,dim do
        space[i] = {}
        for j = 1,dim do
            space[i][j] = 0
            end
        end
        return space
    end


function gentex(dim)
    local space = {}
    for i = 1,dim do
        space[i] = {}
        for j = 1,dim do
            space[i][j] = vec2(1,1)
            end
        end
        return space
    end

function setuplevel(select)

if select == "playground" then
    
    leveldim = 40-- ()must be a multiple of two
    
    texpal = texturepallette(1) -- which set of textures to reference
    
    texpal[0] = grasshires -- which texture is the ground texture
    
level = genlevel(leveldim) -- generates the levelspace. number input 
            --is the dimensions of the X and Z sides.
            
    texes = gentex(leveldim)-- same as above for texture data.
 --[
    level = {
        {2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  5,  5,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  2, 3,  4,  5,  5,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  5,  5,  1,  1,  1,  1,  1,  1, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  2, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  2, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  4,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  2,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  3,  1,  1,  4,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  4,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 1,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  15,  1,  1,  1,  1,  1, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 2,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 8,  8,  8,  8,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 3,  2,  1,  8,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 4,  2,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 5,  6,  7,  8,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},
        {1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8, 8,  8,  8,  8,  1,  1,  1,  1,  1,  1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  8},}
    
  --]
            
end


calcslices() 
end   
function shoot(div)
    if div == nil then div = 9 end
            if muzzle == 1 then
            drawmodel("bullet",33,-8,0,math.random(-0,100)/5,nil,math.random(-0,100)/5,5) 
        --drawmodel("bullet",33,-8,0,math.random(-shotrange,shotrange)/div,nil,math.random(-shotrange,shotrange)/div,5)
    end
    --craft.model("Primitives:Sphere")
    
    end
function flash()
muzzle = 1
    end
  function muzzledraw(other)
        if muzzle == 1
            
                then
        pushMatrix()

       

noStroke()
fill(255, 255, 255, 255)
if other == nil then other = 0 end

rotate(90,0,1,0)
translate(0,-8,33)

rotate(math.random(-44,45))
rect(0,0,1,math.random(17,19))
rect(0,0,math.random(17,19),1)

rect(0,0,6,6)

popMatrix() end
end  
    function hand(xx,yy,zz)
        modelcube(xx/10,yy/10,zz/10,skin,4,5,3.5)
    end
function drawmodel(index,xx,yy,zz,rra,rrb,rrc,size)
pushMatrix()
if size == nil then size = 1 end
translate(xx,yy,zz)
    if rra == nil then else rotate(rra,0,1,0) end
     if rrb == nil then else rotate(rrb,1,0,0) end
     if rrc == nil then else rotate(rrc,0,0,1) end
    scale (size,size,size)
    
    if index == "ramp" then
        
        rotate(45,1,0,0)
        modelcube(0,0,0,cork,55,4,89,19)
        end
        
        
        if index == "bullet" then
pushMatrix()
sprite(white,500,0,1000,1)
rotate(90,1,0,0)
sprite(white,500,0,1000,1)
popMatrix()
end
    
    if index == "cube" then
        rotate(170,1,0,0)
        
        --modelcube(0,0,0,55,500,20000,0)
        sprite("Surfaces:Desert Cliff Color",5000,0,100000,100000)
        end
    
    if index == "cube2" then
        rotate(2000,35,30,25)
        modelcube(0,0,0,gunbarrel, 0,1000,1000,0)
        end
    
if index == "rifle" then
    translate(intzoom-recoil,-intzoom*1.5,(1-intzoom)*7.5)
    
    shoot()
    rotate(recoil*3,0,0,1)

--hand(50,-155,-7)
--hand(-122,-145,7)

modelcube(-3,-10,0,test,20,5,4,12) 
modelcube(-20,-12,0,gunbarrel,13,8,3,12) 
modelcube(-1,-8,0,gunbarrel, 4,2,2,12) 
        --modelcube(-1,-8,0,gunbarrel, 4,2,2,12)
modelcube(15,-8,0,gunbarrel,34,3,3,12)  
modelcube(31,-6,0,gunbarrel,1,1,1,12) 
modelcube(5,-17,0,gunhandle,3,9,2)
end

if index == "minigun" then

    translate(intzoom-recoil*2,-intzoom*1.5,(1-intzoom)*7.5)
            hand(77,-131,-17)
hand(-65,-145,7)
    muzzledraw()
    
    local spotty = vec2(2,2):rotate(ElapsedTime*9)
    for i = 1,5 do
        modelcube(15,spotty.x-10,spotty.y,minigunbarrel,25,2,2,22)
        spotty = spotty:rotate(math.rad(72))
        end
          modelcube(-1,-10,0,gunbarrel,7,7,7,12) 
        modelcube(1,-7,0,gunbarrel,5,3,5,12) 
    end

if index == "shotgun" then

    translate(intzoom-recoil,-intzoom*1.5,(1-intzoom)*7.5)
    for i = 0,math.random(3,5) do
    shoot(3)
    end
    rotate(recoil*4,0,0,1)
        hand(66-limit((recoil-4)*44,0,47),-111,-11)
hand(-122,-122,7)
       modelcube(-2,-10,0,dark,26,3,3,12) 
       modelcube(-21,-12,0,gunbody,12,7,4,12) 
    modelcube(-2,-9,0,gunbody,11,3,5,12) 
modelcube(9,-8,-1.2,gunbarrel,25,2,2,12) 
   modelcube(9,-8,1.2,gunbarrel,25,2,2,12) 

end
    
    
popMatrix()
end
    
function definemodels()
   local img = image(8, 8)
img:set(2,4,255,255,0,255)
img:set(2,5,255,255,0,255)
img:set(3,3,255,255,0,255)
img:set(3,4,255,255,154,255)
img:set(3,5,255,255,154,255)
img:set(3,6,255,255,0,255)
img:set(4,2,255,255,0,255)
img:set(4,3,255,255,154,255)
img:set(4,4,255,255,255,255)
img:set(4,5,255,255,255,255)
img:set(4,6,255,255,154,255)
img:set(4,7,255,255,0,255)
img:set(5,2,255,255,0,255)
img:set(5,3,255,255,154,255)
img:set(5,4,255,255,255,255)
img:set(5,5,255,255,255,255)
img:set(5,6,255,255,154,255)
img:set(5,7,255,255,0,255)
img:set(6,3,255,255,0,255)
img:set(6,4,255,255,154,255)
img:set(6,5,255,255,154,255)
img:set(6,6,255,255,0,255)
img:set(7,4,255,255,0,255)
img:set(7,5,255,255,0,255)
muzzleflash = img

    grass = image(12,12)
    dirt = image(12,12)
    gunbody = image(12,12)
    gunhandle = image(12,12)
    gunbarrel = image(12,12)
    minigunbarrel = image(12,12)
    skin = image(12,12)
    cork = image(12,12)
    test = image(12,12)
    --test = sprite("Surfaces:Desert Cliff Color",5000,0,100000,100000)
    --display.newImage( "image.png" )
for i = 1,12 do
    for j = 1,12 do
grass:set(i,j,(colornoise(77,16)), colornoise(167,24), colornoise(70,49), 255)
dirt:set(i,j,(colornoise(77,16)), colornoise(167,24), colornoise(70,49), 255) 
--dirt:set(i,j,(colornoise(106,16)), colornoise(88,13), colornoise(59), 255)
gunbody:set(i,j,colornoise(150), colornoise(119), colornoise(79), 255)
gunhandle:set(i,j,colornoise(122), colornoise(100), colornoise(66), 255)
gunbarrel:set(i,j,colornoise(152,2),colornoise(152,2),colornoise(150,2),255)
minigunbarrel:set(i,j,colornoise(199,6),colornoise(199,5),colornoise(199,4),255)
cork:set(i,j,colornoise(209,6),colornoise(199,5),colornoise(23,4),255)
skin:set(i,j,colornoise(190,6),colornoise(160,5),colornoise(120,4),255)
        test:set(i,j,0,100,5,255)


end
end
grasshires = image(128,128)
for i = 1,128 do
    for j = 1,128 do
grasshires:set(i,j,(colornoise(66,9)), colornoise(160,15), colornoise(51,20), 255)
end
end
end

function colornoise(dull,derr)
    if derr == nil then derr = 11 end
    return dull +math.random(-derr,derr) end
    
    function drawplane(tex,xx,yy,zz,sx,sy,sz,rra,rrb,rrc)
        pushMatrix()
            translate(xx,yy,zz)
                if rra == nil then else rotate(rra,0,1,0) end
     if rrb == nil then else rotate(rrb,1,0,0) end
     if rrc == nil then else rotate(rrc,0,0,1) end
    scale(sx,sy,sz)
        sprite(tex,0,0,64)
        popMatrix()
    end
    
function modelcube(xx,yy,zz,tex,sx,sy,sz,shading)
    if shading == nil then shading = 0 end
    pushMatrix()
    translate(xx,yy,zz)
    scale(sx/64,sy/64,sz/64)
    pushMatrix()
    for i = 1,6 do
        pushMatrix()
rotate(unpack(cubefacerot[i]))
if shading > 0 then
        tint(255-(i)*shading) end
        --tint(255, 255, 255, 255)
        translate(0,0,-32)
        --sprite("Surfaces:Desert Cliff Color",0,0,65)
        sprite(tex,0,0,64)
        popMatrix()
--rect(i*111,0,99,99)
 end
noTint()
popMatrix()
popMatrix()
end
    

backingMode(STANDARD)
    supportedOrientations(LANDSCAPE_ANY)    
displayMode(FULLSCREEN)
 function setup()

 
   fps = FPS()
    parameter.boolean("Batch", false, function(v)
        print("Batching = "..tostring(v))
        spriteBatching(v)
    end)
    
    parameter.boolean("UseMesh", false)
    
    parameter.boolean("UseString", true)
    
    img = readImage("Planet Cute:Character Horn Girl")
    str = "Planet Cute:Character Horn Girl"
    
    amt = 40
    
    sw,sh = spriteSize("Planet Cute:Character Horn Girl") 
    
    
    
    
 scene = craft.scene()
    -- Setup camera and lighting
    scene.sun.rotation = quat.eulerAngles(25, 125, 0)

    -- Set the scenes ambient lightingds
    scene.ambientColor = color(127, 127, 127, 255)   
    
    allBlocks = blocks()    
    
    -- Setup voxel terrain
    scene.voxels:resize(vec3(5,1,5))      
    scene.voxels.coordinates = vec3(0,0,0)
    
    -- Create ground put of grass
    scene.voxels:fill("Redstone Ore")
    scene.voxels:box(0,10,0,16*5,10,16*5)
    scene.voxels:fill("Dirt")
    scene.voxels:box(0,0,0,16*5,9,16*5)
   
    
    
    
    
    
    
    
    
    
    
    camspot = vec3(0,0,0)
distance = 1
fov = 99
touchmap = {}


definefacerot()
definemodels()

noSmooth()



rectMode(CENTER)

setuplevel("playground")
touchsetup()
end

function touched(touch)
    if touch.state == ENDED then
        touchrelease(touch)
        touchmap[touch.id] = nil
            
    else
        local derpy = 0
        if touchmap[touch.id] == nil then inittouch(touch) end
        touchmap[touch.id] = touch
    end

end




function draw()
    

    
   -- FPS.pos = vec2(WIDTH - 60, 20)
  --  FPS:update(DeltaTime)
  --  FPS:draw2()



    background(134, 166, 179, 255)
    
    
    cam()
    
    playercalc()
    noStroke()
fill(59, 68, 47, 255)

--drawground(grass)



hudgun()

       drawmodel("ramp",64,64,0,270,0)
    drawmodel("ramp",0,0,0,270,0)
    drawmodel("cube",64,64,64,270,100)
   -- drawmodel("cube2",64,-64,64,270,100)
 drawmodel(weaponindex,128,128,0,270,0,0)
--entities()
drawslices()
   -- scenen()
--scene:draw()
    drawcube(0,0,0,1,90,1,nil,nil,nil)

    

    

-- Classic 3d wireframe cube demo in LUA
-- based on version for PSP by Nils - ventoline.com
-- modified for Codea - Tom Bortels November 2011

--scene:draw()
    
  

ortho()
 viewMatrix(matrix())
zLevel(1)
control()
zLevel(0)
end


function playersetup()
    player["yspeed"] = 0
    weaponlist = {"rifle","shotgun","minigun","nothing"}
    weaponindex = "rifle"
    weapon = 1
    gunrate = 33
    canjump = 1
    gunacc = 3
    gunaccbuff = 3
    cameray = 33
    cameraybuff=cameray
    end
    
function jump()
    if canjump == 1 then
        canjump = 0
   player["yspeed"] = 7.2 end
end

function playercalc()
    
    muzzle = 0
    
    if guntimer > 0 then guntimer = guntimer - 1 else 
        if shoottouch == nil then else
    guntimer = gunrate
    gunaccbuff = gunaccbuff*3
    flash() end
    end
    recoil = (recoil*2 + math.max(guntimer-gunrate/5,0)^0.7)/5
    local elev = 0
    elev = math.max(level[round(camerax/64)][round(cameraz/64)]*64)


    playergrid = vec2( round(camerax/64),round(cameraz/64))
    
    if cameray < 66+elev and player["yspeed"] <= 0 then cameray = 66+elev
    canjump = 1
    player["yspeed"] = player["yspeed"] /2 -1
     else
    player["yspeed"] = player["yspeed"] -0.3 end
    cameray = cameray + player["yspeed"]
    
    
  
    
    end
    
    
function hudgun()
    if weapon > #weaponlist then weapon = 1 end
    weaponindex = weaponlist[weapon]
drawmodel(weaponindex,camspot.x,camspot.y+1/19,camspot.z,180-angle,0,-(topangle),1/22)


if weaponindex == "rifle" then gunrate = 33 
gunacc = 10 
end
if weaponindex == "shotgun" then gunrate = 78 
gunacc = 35
end
if weaponindex == "minigun" then gunrate = math.random(4,6) 
gunacc = 27
end
gunaccbuff = gunaccbuff*0.8+ gunacc/5

cameraz = limit(cameraz,64,(64*leveldim))
camerax = limit(camerax,64,(64*leveldim))

speed = 14.4+intzoom*3
if axis.x > 0 then
    local elevne = level[math.ceil(camerax/64-1/5)][round(cameraz/64)]
if elevne < round(cameray/64)  then
camerax = camerax + axis.x/speed
    end
end

if axis.y > 0 then
    local elevne = level[round(camerax/64)][math.floor(cameraz/64+1/5)]
    if elevne < round(cameray/64)  then
cameraz = cameraz - axis.y/speed
    end
end

if axis.y < 0 then
    local elevne = level[round(camerax/64)][math.ceil(cameraz/64-1/5)]
    if elevne < round(cameray/64)  then
cameraz = cameraz - axis.y/speed
    end
end

if axis.x < 0 then
    local elevne = level[math.floor(camerax/64+1/5)][round(cameraz/64)]
    if elevne < round(cameray/64)  then
camerax = camerax + axis.x/speed
    end
end

    

end
function defineslice()
    local dim = math.ceil(leveldim/2)
    local sliced = {}
      for m = -dim,dim do
        sliced[m] = {}
        for i = -dim,dim do
            sliced[m][i] = {}
            for j = 1,levelcap do
            sliced[m][i][j] = 0
    end
    end
    end
    return sliced
    end
    
function calcslices()
    levelcap = 0
    local dim = leveldim
    for i = 1, dim do
        for j = 1,dim do
            level[i][j] = level[i][j] --+ math.random(0,1) this makes it random
            levelcap = math.max(level[i][j],levelcap )
        end
    end -- the maximum vertical value has been set
      
    nplanes = defineslice()
    eplanes = defineslice()
    splanes = defineslice()
    wplanes = defineslice()
  
for i = 1,dim do
    for j = 1,dim do
        for k = 1,levelcap do
            local mine = level[i][j]
            if mine >= k then
                
                    
                        
                        if i < leveldim and level[i+1][j] < mine and k > level[i+1][j] then
                              eplanes[-i+dim/2][-j+dim/2][k] = dirt 
               
                end
                              if i > 1 and level[i-1][j] < mine and k > level[i-1][j] then
                    wplanes[i-dim/2][j-dim/2][k] = dirt 
                
                end
                
                   
                        if j < leveldim and level[i][j+1] < mine and k > level[i][j+1] then
                            splanes[-j+dim/2][i-dim/2][k] = dirt
                
                end
                
                   if j > 1 and level[i][j-1] < mine and k > level[i][j-1] then
                    
                nplanes[j-dim/2][-i+dim/2][k] = dirt
                end
                

               
            
            end
        end
    end
end
    
     
        
        

end
    

function wraplimit(val,range)
    while val < 0 do
        val = val + range end
        
            while val >= range do
        val = val - range end
        
        return val   
end
    
function visiangle(dimmy,q)
   local derp = 2
if q == 4 then
if dimmy < playergrid.x then derp = 0 else derp = 1 end end

if q == 2 then
if leveldim-dimmy > playergrid.x then derp = 0 else derp = 1 end end
if q == 1 then
if dimmy < playergrid.y then derp = 0 else derp = 1 end end

if q == 3 then
if leveldim-dimmy > playergrid.y then derp = 0 else derp = 1 end end


    return derp
end
    
function drawslices()
    local ango = wraplimit(-angle,360)
    local dim = leveldim

    pushMatrix()
    rotate(90,1,0,0)

            for k = 1,math.ceil(cameray/64+0.1) do
                                pushMatrix()
                translate(0,0,-k*64-32)
                for i = 1, dim do
        for j = 1,dim do
            local mine = level[i][j]

            if mine == k then
                

            sprite(dirt,i*64,j*64,64) 
           end
            end
        end
        popMatrix()
    end
    popMatrix()
pushMatrix()
    translate(dim*32,0,dim*32)--places the slices in the game area
    

    local sides = {nplanes,eplanes,splanes,wplanes}
    local shadesies = {37,88,111,77}
    
    for q = 1,4 do
        
        
        local planar = sides[q]
    tint(255-shadesies[q])
        pushMatrix()
        
      rotate((q-1)*270,0,1,0)
            for i = -dim/2,dim/2 do
                if visiangle(i+dim/2,q) == 1 then
        
                pushMatrix()
                translate(0,0,(i-0.5)*64)
                for j =  -dim/2,dim/2 do
                    for k = 1,levelcap  do
                        if planar[i][j][k] == 0 then else
                            sprite(planar[i][j][k],-j*64,k*64,64)
                        end
                    end
                end
                popMatrix()
                end
            end
        popMatrix()
    end 
    popMatrix()
    noTint()
end
function touchsetup()
    camerax = leveldim*32
    cameray = 0
    cameraz = leveldim*32
    movetouch = nil
    shotrange = 10
    aimtouch = nil
    looktouch = nil
    shoottouch = nil
    zoomtouch = nil
    player = {}
    recoil = 0
    guntimer = 0
                        playersetup()
    jumptouch = nil
    swaptouch = nil
    jumptouch = nil
    axis = vec2(0,0)
    health = 100
    zoom = 0
    intzoom = 0
    anglebase = 0
    topanglebase = 0
    angleoffset = 0
    topangleoffset = 0
end
function control()
    pushMatrix()
strokeWidth(1)
    stroke(255, 255, 255, 255)
    noFill()
    if weaponindex == "nothing" then else
        shotrange = ((limit(gunaccbuff+axis:len()/5,1,50*(gunacc/10))+ shotrange)/2)/(1+intzoom/2)
  pushMatrix()
  translate(WIDTH/2,HEIGHT/2)
line(0,shotrange,0,shotrange-12)
line(shotrange,0,shotrange-12,0)
line(0,-shotrange,0,-shotrange+12)
line(-shotrange,0,-shotrange+12,0)
popMatrix() end
ellipse(WIDTH-100,100,120)
ellipse(WIDTH-100+angleoffset,100-topangleoffset,11)
ellipse(100,100,120)
    pushMatrix()
    pushStyle()
    translate(WIDTH-100,HEIGHT-100)
    ellipse(0,0,120)
    stroke(255,255-intzoom*255,255-intzoom*255,255)
    ellipse(0,0,40)
    line(0,8,0,33)
    line(0,-8,0,-33)
    line(8,0,33,0)
    line(-8,0,-33,0)
    popStyle()
    popMatrix()

ellipse(100,HEIGHT-100,120)

    
    fill(255, 255, 255, 255)
    fontSize(16)
    font("Courier-Oblique")
  text(weaponindex,100,HEIGHT-100)
 text("health",100,115)
    text("%"..health,95,85)
    
    popMatrix()

if zoom == 0 and looktouch == nil and aimtouch == nil then topanglebase = topanglebase*0.999 end
if looktouch == nil then topangleoffset = round(topangleoffset/2)
angleoffset = round(angleoffset/2) end
if movetouch == nil then axis = axis/1.3 end

   for k,touch in pairs(touchmap) do
    ellipse(touch.x,touch.y,4)
    
        if looktouch == nil then else
     if touch.id == looktouch.id then 
local look = vec2( lookaxisx -touch.x,-lookaxisy+touch.y)*-2
if look:len() > 90 then look = look:normalize() *90 end
  angleoffset = (look.x+angleoffset*2)/(5+intzoom*7)
topangleoffset = (look.y+topangleoffset*2)/(5+intzoom*7)
-- cameraz = cameraz - axis.y/20
     end 
    end

        if movetouch == nil then else
     if touch.id == movetouch.id then 
 axis = (-vec2(     moveaxisx -touch.x,moveaxisy-touch.y)):rotate(math.rad(90-angle))
if axis:len() > 60 then axis = axis:normalize() *60 end

     end 
        end
         if aimtouch == nil then else
     if touch.id == aimtouch.id and touch.state == MOVING then 
        
        anglebase = anglebase + ((round(touch.x)-round(aimaxisx)))/(1.2+(intzoom*3))
        topanglebase = topanglebase - (round(touch.y)-round(aimaxisy))/(1.2+intzoom*3)
       aimaxisx = touch.x
       aimaxisy = touch.y
     end 
        end        
        
  end
    
    end
    
    
    
function touchrelease(touch)
    if aimtouch == nil then else
    if aimtouch.id  == touch.id then aimtouch  = nil end end
    if movetouch == nil then else
    if movetouch.id == touch.id then movetouch = nil end end
    if looktouch == nil then else
    if looktouch.id == touch.id then looktouch = nil end end
    if weapontouch == nil then else
    if weapontouch.id == touch.id then weapontouch = nil end end
    if shoottouch == nil then else
    if shoottouch.id == touch.id then shoottouch = nil end end
    if zoomtouch == nil then else
    if zoomtouch.id == touch.id then zoomtouch = nil end end
        if jumptouch == nil then else
    if jumptouch.id == touch.id then jumptouch = nil end end
end
    
function inittouch(touch)
    local durp = 0 
   

    
           if hitradius(100,100,touch.x,touch.y,60)==1 then
        
        jumptouch = touch
        jump() end 
    
       if hitradius(100,HEIGHT-100,touch.x,touch.y,60)==1 then
        durp = 1
        weapontouch = touch
        weapon = weapon + 1 end 
    
    if hitradius(WIDTH-100,HEIGHT-100,touch.x,touch.y,60)==1 then
        durp = 1
        zoomtouch = touch
        zoom = invert(zoom) end
    
     if hitradius(WIDTH-100,100,touch.x,touch.y,60) == 1 then
        
    if shoottouch == nil then
        shoottouch = touch

        end end
            
            
            if durp == 0 then
    if touch.x > WIDTH*0.6 then
    if aimtouch  == nil then aimtouch = touch 
   aimaxisx = touch.x
        aimaxisy = touch.y 
    end
            end
            if touch.x < WIDTH*0.4 then
    if movetouch == nil then movetouch = touch 
    moveaxisx = touch.x
    moveaxisy = touch.y
    end
        end
    end
end
function coin(weigh)
    if weigh==nil then
        weigh = 50
        end
  local thing = 0  
    if math.random(0,100) > weigh then
    thing = 1
    end
        return thing
 end

    function limit(actualvalue,lowlimit,highlimit)
    return math.min(highlimit,math.max(actualvalue,lowlimit))
end

function round(input)
    return math.floor(input+0.5)
end

function hitbox(x1,y1,x2,y2,w,h)
    
    if h == nil then
        h = w
        end
    rval = 0
    if x1-w/2 < x2 and x1 + w/2 > x2 and y1-h/2 < y2 and y1 + h/2 > y2 then
        rval = 1
        end
    return rval
    end
    
function hitradius (x1,y1,x2,y2,r)
    tytyty = vec2(x1-x2,y1-y2)
    if tytyty:len() < r then
    return 1
    else
        return 0
        end
        end
        
    











function bitmake(numberin, digitsin)
    --this function returns a table of bits from a number. 
    --if called with one argument it assumes yhere are 8 bits, that the number is in the range
    --of 0-255.
    returner = {}
    if digitsin == nil then
        digitabub = 7
        else
    digitabub = math.floor(digitsin)
    end
    bitbuffer = math.floor(numberin)
    for i = 0, digitabub do
        returner[i]  = 0
        end  
    for i = 0, digitabub do    
        if bitbuffer >= 2^(digitabub-i) then
          returner[digitabub-i]  = 1
        bitbuffer = bitbuffer - 2^(digitabub-i)
        end
      return returner    
    end
end


function sign(signinputlol)
    if signinputlol == 0 then
        return 0
    else
        if signinputlol > 1 then
            return 1
        else
            return -1
            end
        end
end

function min(blub)
return math.min(blub)
end
    
function max(blub)
return math.max(blub)
end

function point_distance(x1,y1,x2,y2)
    return (((x1-x2)^2)+((y1-y2)^2)^0.5)
    end

function invert(input)
    return math.abs(input-1)
end

function fix(n)
    return ( n * camzoom)
    end

function rand(blub,bllub2,blub3)
    return math.random(blub,bllub2,blub3)
end

That’s a lot of code to copy and paste in so sorry for the hassle if you try I couldn’t find an easier way it won’t let me upload the file direct

@chrislightsaber Yes, that is a lot of code. I loaded just the code from your first post, the code by JakAttak, and it ran with no problems. Just in case you’re unclear, you need 2 iPads running on the same router. Here’s what you need to do. Load that code on both iPads and run both. Press Host Game on both iPads and then on one of the iPads press Find Game. The 2 iPads should now be connected and anything you draw on one of them will also show on the other.

@chrislightsaber Just because you can connect 2 iPads together, doesn’t mean you can run a game together on both of them. A lot of coding needs to be done for the 2 programs to communicate with each other. An even if you get them to communicate, the connection might not be fast enough for what you’re doing and you’ll lose a lot of data transmitted between them.

@dave1707 I have to setup stuff in the code to ransfer player position and stuff I’m guessing? I figured that was the issue

@chrislightsaber I haven’t tried to run the other code you posted yet, so I’m not sure how involved it is. Just saying you need to transfer the player positions might be just the start of a lot of code changes/additions.