☘| Platformer Creator

Instructions:  - I reshared this to make some MAJOR changes...\n   1. Create new orange enemies that throw bombs;\n   2. Modify the thumbnail;\n   3. Add the fact that I will make a part 6\n=====Info=====\nThe Red Ninja: https://scratch.mit.edu/projects/401255085/\nThe Red Ninja 2: https://scratch.mit.edu/projects/402521703/\nThe Red Ninja 3: https://scratch.mit.edu/projects/402980379/\nThe Red Ninja 4: https://scratch.mit.edu/projects/404940060/\n=====Disclaimer=====\nIt might lag occasionally on slow devices because of too many clones, but still, enjoy! This is also mobile friendly.\nFor less lag go to Forkphorus.github.io/#406739724\n=====Controls=====\nMove and Swim || Arrow keys or mobile tap\nShoot || Space or “Use weapon” button\nSwitch Weapon || Z or “Switch weapon” button\nSkip level || S\nAll levels are possible on both mobile and computer!

@Stage\n\ndefine create block (x) (y) (z) (type)\nadd (x) to [block - x v]\nadd (y) to [block - y v]\nadd (z) to [block - z v]\nadd (type) to [block - type v]\nadd (join (x) (join (join [:] (y)) (join [:] (z)))) to [block - search v]\n\ndefine Fill (x1) (y1) (z1) (x2) (y2) (z2) (type)\nset [stage: loop1iterator v] to (x1)\nrepeat (((x2) - (x1)) + (1))\n    set [stage: loop2iterator v] to (y1)\n    repeat (((y2) - (y1)) + (1))\n        set [stage: loop3iterator v] to (z1)\n        repeat (((z2) - (z1)) + (1))\n            create block (Stage: loop1Iterator) (Stage: loop2Iterator) (Stage: loop3Iterator) (type)\n            change [stage: loop3iterator v] by (1)\n        end\n        change [stage: loop2iterator v] by (1)\n    end\n    change [stage: loop1iterator v] by (1)\nend\n\ndefine generate map\ndelete all of [block - x v]\ndelete all of [block - y v]\ndelete all of [block - z v]\ndelete all of [block - type v]\ndelete all of [block - search v]\nif <(level) = [1]> then\n    setSpawn [0.5] [0.5] [0] [0] [0]\n    3x3 platform [0] [0] [-1]\n    Fill [0] [2] [-1] [0] [8] [-1] [platform]\n    Next Level Platform [0] [10] [-1]\n    set [difficulty v] to [EASY]\nend\nif <(level) = [2]> then\n    3x3 platform [0] [0] [-1]\n    Fill [0] [2] [-1] [0] [8] [-1] [platform]\n    Next Level Platform [0] [10] [-1]\n    create block [0] [3] [0] [death]\n    create block [0] [7] [0] [death]\nend\nif <(level) = [3]> then\n    3x3 platform [0] [0] [-1]\n    Fill [0] [2] [-1] [0] [3] [-1] [platform]\n    Fill [1] [3] [-1] [3] [3] [-1] [platform]\n    Fill [3] [4] [-1] [3] [5] [-1] [platform]\n    Fill [-3] [6] [-1] [3] [6] [-1] [platform]\n    Fill [-3] [7] [-1] [-3] [9] [-1] [platform]\n    Fill [-3] [10] [-1] [-1] [10] [-1] [platform]\n    Fill [0] [10] [-1] [0] [11] [-1] [platform]\n    Next Level Platform [0] [13] [-1]\nend\nif <(level) = [4]> then\n    3x3 platform [0] [0] [-1]\n    Fill [-1] [3] [-1] [1] [3] [-1] [platform]\n    Fill [-1] [5] [0] [1] [5] [0] [platform]\n    Fill [-1] [7] [1] [1] [7] [1] [platform]\n    Fill [-1] [9] [2] [1] [9] [2] [platform]\n    Fill [-1] [11] [1] [1] [11] [1] [platform]\n    Fill [-1] [13] [0] [1] [13] [0] [platform]\n    Fill [-1] [15] [-1] [1] [15] [-1] [platform]\n    Next Level Platform [0] [18] [-1]\nend\nif <(level) = [5]> then\n    setSpawn [1] [1] [0] [0] [0]\n    4x4 platform [0.5] [0.5] [-1]\n    Fill [-1] [3] [-1] [0] [4] [-1] [platform]\n    Fill [1] [3] [-1] [2] [4] [-1] [death]\n    Fill [-1] [5] [-1] [0] [6] [-1] [death]\n    Fill [1] [5] [-1] [2] [6] [-1] [platform]\n    Fill [-1] [7] [-1] [0] [8] [-1] [platform]\n    Fill [1] [7] [-1] [2] [8] [-1] [death]\n    Fill [-1] [9] [-1] [0] [10] [-1] [death]\n    Fill [1] [9] [-1] [2] [10] [-1] [platform]\n    Fill [-1] [11] [-1] [0] [12] [-1] [platform]\n    Fill [1] [11] [-1] [2] [12] [-1] [death]\n    Fill [-1] [13] [-1] [0] [14] [-1] [death]\n    Fill [1] [13] [-1] [2] [14] [-1] [platform]\n    4x4 Next Level Platform [0.5] [16.5] [-1]\nend\nif <(level) = [6]> then\n    setSpawn [0.5] [0.5] [0] [0] [0]\n    3x3 platform [0] [0] [-1]\n    Fill [-1] [5] [0] [1] [7] [0] [platform]\n    Fill [-1] [12] [0] [1] [14] [0] [platform]\n    Fill [-5] [12] [0] [-5] [14] [0] [platform]\n    Fill [-9] [12] [0] [-9] [14] [0] [platform]\n    Next Level Platform [-14] [13] [0]\n    set [difficulty v] to [MEDIUM]\nend\nif <(level) = [7]> then\n    3x3 platform [0] [0] [-1]\n    Fill [-1] [5] [0] [1] [7] [0] [platform]\n    Fill [-1] [12] [0] [1] [14] [0] [platform]\n    Fill [5] [12] [0] [5] [14] [0] [platform]\n    Fill [9] [12] [0] [9] [14] [0] [platform]\n    Fill [13] [12] [0] [15] [14] [0] [platform]\n    Fill [17] [12] [1] [17] [14] [3] [death]\n    Fill [19] [11] [0] [21] [15] [0] [platform]\n    Fill [25] [12] [0] [25] [14] [0] [platform]\n    Fill [28] [12] [0] [28] [14] [0] [platform]\n    Next Level Platform [32] [13] [0]\n    set [difficulty v] to [HARD]\nend\nif <(level) > [7]> then\n    Fill [-5] [-3] [-1] [5] [7] [-1] [barrier]\n    Fill [-5] [-4] [0] [5] [-4] [10] [barrier]\n    Fill [-5] [8] [0] [5] [8] [10] [barrier]\n    Fill [-6] [-3] [0] [-6] [7] [10] [barrier]\n    Fill [6] [-3] [0] [6] [7] [10] [barrier]\n    create block [0] [2] [0] [platform]\n    create block [1] [4] [1] [platform]\n    create block [-1] [5] [2] [platform]\nend\nset [player - z v] to [-15]\n\nwhen flag clicked\nerase all\nhide variable [level v]\nhide variable [fps v]\nhide variable [start v]\nhide variable [difficulty v]\nset [start v] to [-1]\nset [level v] to [1]\ngenerate map\nwait until <(start) = [1]>\nbroadcast (FinishedLoading v)\nwait until <(level) > [7]>\nhide variable [level v]\nhide variable [difficulty v]\n\nwhen I receive [finishedloading v]\nshow variable [fps v]\nshow variable [level v]\nshow variable [difficulty v]\nforever\n    if <<(Player - Z) < [-10]> or <<[touching v] contains [death]?> or <<(Player - Feet Z-) = [death]> or <<(Player - Head Z+) = [death]> or <<(Player - Feet X-) = [death]> or <<(Player - Feet X+) = [death]> or <<(Player - Feet Y-) = [death]> or <<(Player - Feet Y+) = [death]> or <<(Player - Head X-) = [death]> or <<(Player - Head X+) = [death]> or <<(Player - Head Y-) = [death]> or <(Player - Head Y+) = [death]>>>>>>>>>>>> then\n        set [player - x v] to (Spawn - X)\n        set [player - y v] to (Spawn - Y)\n        set [player - z v] to (Spawn - Z)\n        set [player - xv v] to [0]\n        set [player - yv v] to [0]\n        set [player - zv v] to [0]\n        set [player - pitch v] to (Spawn - Pitch)\n        set [player - yaw v] to (Spawn - Yaw)\n    end\n    if <<(Player - Feet Z-) = [goal]> or <<(Player - Head Z+) = [goal]> or <<(Player - Feet X-) = [goal]> or <<(Player - Feet X+) = [goal]> or <<(Player - Feet Y-) = [goal]> or <<(Player - Feet Y+) = [goal]> or <<(Player - Head X-) = [goal]> or <<(Player - Head X+) = [goal]> or <<(Player - Head Y-) = [goal]> or <(Player - Head Y+) = [goal]>>>>>>>>>> then\n        change [level v] by (1)\n        generate map\n    end\nend\n\nwhen [m v] key pressed\nset [muted v] to (() - (muted))\n\nwhen flag clicked\nhide variable [muted v]\nset [muted v] to [-1]\nforever\n    if <(muted) = [-1]> then\n        set volume to (50) %\n    else\n        set volume to (0) %\n    end\nend\n\ndefine Next Level Platform (x) (y) (z)\ncreate block (x) (y) (z) [goal]\nFill ((x) - (1)) ((y) - (1)) (z) ((x) + (1)) ((y) - (1)) (z) [platform]\nFill ((x) - (1)) ((y) + (1)) (z) ((x) + (1)) ((y) + (1)) (z) [platform]\ncreate block ((x) + (1)) (y) (z) [platform]\ncreate block ((x) - (1)) (y) (z) [platform]\n\ndefine 3x3 platform (x) (y) (z)\nFill ((x) - (1)) ((y) - (1)) (z) ((x) + (1)) ((y) + (1)) (z) [platform]\n\ndefine setSpawn (x) (y) (z) (pitch) (yaw)\nset [spawn - x v] to (x)\nset [spawn - y v] to (y)\nset [spawn - z v] to (z)\nset [spawn - pitch v] to (pitch)\nset [spawn - yaw v] to (yaw)\n\ndefine 4x4 platform (x) (y) (z)\nFill ((x) - (1.5)) ((y) - (1.5)) (z) ((x) + (1.5)) ((y) + (1.5)) (z) [platform]\n\ndefine 4x4 Next Level Platform (x) (y) (z)\nFill ((x) - (0.5)) ((y) - (0.5)) (z) ((x) + (0.5)) ((y) + (0.5)) (z) [goal]\nFill ((x) - (1.5)) ((y) - (1.5)) (z) ((x) + (1.5)) ((y) - (1.5)) (z) [platform]\nFill ((x) - (1.5)) ((y) + (1.5)) (z) ((x) + (1.5)) ((y) + (1.5)) (z) [platform]\nFill ((x) - (1.5)) ((y) - (0.5)) (z) ((x) - (1.5)) ((y) + (0.5)) (z) [platform]\nFill ((x) + (1.5)) ((y) - (0.5)) (z) ((x) + (1.5)) ((y) + (0.5)) (z) [platform]\n\nwhen flag clicked\nwait (0.75) seconds\nforever\n    play sound [Tomás Novoa - Géminis \(2021\) v] until done\nend\n\n@Lag Reducer?\n\n@Engine\n\ndefine generateBlockDistances\nset [renderorder - iterator v] to [1]\ndelete all of [block - distance v]\ndelete all of [block - render order calc v]\nrepeat (length of [block - x v])\n    set [gbd - x△ v] to ((item (RenderOrder - Iterator) of [block - x v]) - (Player - X))\n    set [gbd - y△ v] to ((item (RenderOrder - Iterator) of [block - y v]) - (Player - Y))\n    set [gbd - z△ v] to ((item (RenderOrder - Iterator) of [block - z v]) - (Player - Z))\n    add (((GBD - X△) * (GBD - X△)) + (((GBD - Y△) * (GBD - Y△)) + ((GBD - Z△) * (GBD - Z△)))) to [block - distance v]\n    add (RenderOrder - Iterator) to [block - render order calc v]\n    change [renderorder - iterator v] by (1)\nend\n\ndefine fill (ax) (ay) (bx) (by) (cx) (cy) resolution: (res)\nset [lena v] to ([sqrt v] of ((((bx) - (cx)) * ((bx) - (cx))) + (((by) - (cy)) * ((by) - (cy)))) )\nset [lenb v] to ([sqrt v] of ((((ax) - (cx)) * ((ax) - (cx))) + (((ay) - (cy)) * ((ay) - (cy)))) )\nset [lenc v] to ([sqrt v] of ((((ax) - (bx)) * ((ax) - (bx))) + (((ay) - (by)) * ((ay) - (by)))) )\nset [peri v] to ((1) / (((lena) + (lenb)) + (lenc)))\nset [incx v] to (((((lena) * (ax)) + ((lenb) * (bx))) + ((lenc) * (cx))) * (peri))\nset [incy v] to (((((lena) * (ay)) + ((lenb) * (by))) + ((lenc) * (cy))) * (peri))\nset [ind v] to ([sqrt v] of ((((((lenb) + (lenc)) - (lena)) * (((lenc) + (lena)) - (lenb))) * (((lena) + (lenb)) - (lenc))) * (peri)) )\nset [aox v] to ((incx) - (ax))\nset [aoy v] to ((incy) - (ay))\nset [box v] to ((incx) - (bx))\nset [boy v] to ((incy) - (by))\nset [cox v] to ((incx) - (cx))\nset [coy v] to ((incy) - (cy))\nif <<(lena) < (lenb)> and <(lena) < (lenc)>> then\n    set [td v] to ([sqrt v] of (((Aox) * (Aox)) + ((Aoy) * (Aoy))) )\nelse\n    if <<(lenb) > (lena)> or <(lenb) > (lenc)>> then\n        set [td v] to ([sqrt v] of (((Cox) * (Cox)) + ((Coy) * (Coy))) )\n    else\n        set [td v] to ([sqrt v] of (((Box) * (Box)) + ((Boy) * (Boy))) )\n    end\nend\nset [rate v] to ((((td) * (2)) - (ind)) / ((td) * (4)))\nset [td v] to ((1) + (0))\ngo to x: (round (incx)) y: (round (incy))\nset pen size to (ind)\npen down\nrepeat ([ceiling v] of (([log v] of ((res) / (ind)) ) / ([log v] of (rate) )) )\n    set [td v] to ((td) * (rate))\n    set pen size to ((ind) * (td))\n    go to x: (((Aox) * (td)) + (ax)) y: (((Aoy) * (td)) + (ay))\n    go to x: (((Box) * (td)) + (bx)) y: (((Boy) * (td)) + (by))\n    go to x: (((Cox) * (td)) + (cx)) y: (((Coy) * (td)) + (cy))\n    go to x: (((Aox) * (td)) + (ax)) y: (((Aoy) * (td)) + (ay))\nend\npen up\n\ndefine quicksort (lowerbound) (upperbound)\nset [lower v] to (lowerbound)\nset [upper v] to (upperbound)\nset [pivot v] to (item ([floor v] of (((lowerbound) + (upperbound)) / (2)) ) of [block - distance v])\nrepeat until <(lower) > (upper)>\n    repeat until <not <(item (lower) of [block - distance v]) < (pivot)>>\n        change [lower v] by (1)\n    end\n    repeat until <not <(item (upper) of [block - distance v]) > (pivot)>>\n        change [upper v] by (-1)\n    end\n    if <not <(lower) > (upper)>> then\n        set [tempswap v] to (item (lower) of [block - distance v])\n        replace item (lower) of [block - distance v] with (item (upper) of [block - distance v])\n        replace item (upper) of [block - distance v] with (tempSwap)\n        set [tempswap v] to (item (lower) of [block - render order calc v])\n        replace item (lower) of [block - render order calc v] with (item (upper) of [block - render order calc v])\n        replace item (upper) of [block - render order calc v] with (tempSwap)\n        change [lower v] by (1)\n        change [upper v] by (-1)\n    end\nend\nif <(lowerbound) < (upper)> then\n    quicksort (lowerbound) (upper)\nend\nif <(lower) < (upperbound)> then\n    quicksort (lower) (upperbound)\nend\nset [renderorder - iterator v] to [1]\nif <(length of [block - render order calc v]) = (length of [block - render order v])> then\n    repeat (length of [block - render order calc v])\n        replace item (RenderOrder - Iterator) of [block - render order v] with (item (RenderOrder - Iterator) of [block - render order calc v])\n        change [renderorder - iterator v] by (1)\n    end\nelse\n    delete all of [block - render order v]\n    repeat (length of [block - render order calc v])\n        add (item (RenderOrder - Iterator) of [block - render order calc v]) to [block - render order v]\n        change [renderorder - iterator v] by (1)\n    end\nend\n\ndefine drawSpinningCrystal (x) (y) (z) (objectsize) (speed) (pensize)\npoint in direction ((timer) * (speed))\nrepeat (4)\n    3D point -> 2D point (x) (y) ((z) - (objectsize))\n    if <(2D - Visible?) = [false]> then\n        stop [this script v]\n    end\n    set [x1 v] to (2D - X)\n    set [y1 v] to (2D - Y)\n    3D point -> 2D point ((x) + (([cos v] of (direction) ) * (objectsize))) ((y) + (([sin v] of (direction) ) * (objectsize))) (z)\n    if <(2D - Visible?) = [false]> then\n        stop [this script v]\n    end\n    set [x2 v] to (2D - X)\n    set [y2 v] to (2D - Y)\n    3D point -> 2D point (x) (y) ((z) + (objectsize))\n    if <(2D - Visible?) = [false]> then\n        stop [this script v]\n    end\n    set [x3 v] to (2D - X)\n    set [y3 v] to (2D - Y)\n    3D point -> 2D point ((x) + (([cos v] of ((direction) + (90)) ) * (objectsize))) ((y) + (([sin v] of ((direction) + (90)) ) * (objectsize))) (z)\n    if <(2D - Visible?) = [false]> then\n        stop [this script v]\n    end\n    set [x4 v] to (2D - X)\n    set [y4 v] to (2D - Y)\n    set [pensize v] to ([ceiling v] of ((3) / ([sqrt v] of (((((x) - (Rendered Player - X)) * ((x) - (Rendered Player - X))) + (((y) - (Rendered Player - Y)) * ((y) - (Rendered Player - Y)))) + (((z) - (Rendered Player - Z)) * ((z) - (Rendered Player - Z)))) )) )\n    if <(Render - Filler?) = [1]> then\n        set pen color to (#5bf530)\n        fill (X1) (Y1) (X2) (Y2) (X4) (Y4) resolution: (penSize)\n        fill (X3) (Y3) (X2) (Y2) (X4) (Y4) resolution: (penSize)\n        set pen color to (#1c4e0f)\n    end\n    drawLine - 2D (X1) (Y1) (X2) (Y2) (penSize)\n    drawLine - 2D (X2) (Y2) (X3) (Y3) (penSize)\n    drawLine - 2D (X2) (Y2) (X4) (Y4) (penSize)\n    turn right (90) degrees\nend\nset pen color to (#5bf530)\n\ndefine drawCube (x) (y) (z) (type)\nif <not <<(type) = [barrier]> or <(type) = [0]>>> then\n    if <(type) = [goal]> then\n        set pen color to (#5bf530)\n        drawSpinningCrystal ((x) + (0.5)) ((y) + (0.5)) ((z) + (2.5)) [0.5] [200] [3]\n    else\n        if <(type) = [death]> then\n            set pen color to (#ff4c4c)\n        else\n            if <(type) = [platform]> then\n                set pen color to (#989898)\n            else\n                set pen color to (#ff9ac0)\n            end\n        end\n    end\n    getBlock ((x) + (1)) (y) ((z) + (Setting - Camera Z Offset))\n    set [block - x+ v] to (BlockTypeReturn)\n    getBlock ((x) - (1)) (y) ((z) + (Setting - Camera Z Offset))\n    set [block - x- v] to (BlockTypeReturn)\n    getBlock (x) ((y) + (1)) ((z) + (Setting - Camera Z Offset))\n    set [block - y+ v] to (BlockTypeReturn)\n    getBlock (x) ((y) - (1)) ((z) + (Setting - Camera Z Offset))\n    set [block - y- v] to (BlockTypeReturn)\n    getBlock (x) (y) (((z) + (1)) + (Setting - Camera Z Offset))\n    set [block - z+ v] to (BlockTypeReturn)\n    getBlock (x) (y) (((z) - (1)) + (Setting - Camera Z Offset))\n    set [block - z- v] to (BlockTypeReturn)\n    if <<(Rendered Player - X) > ((x) + (1))> and <<(Block - X+) = [air]> or <(Block - X+) = [barrier]>>> then\n        set [blockface x+ render? v] to [1]\n        drawFace ((x) + (1)) (y) (z) ((x) + (1)) ((y) + (1)) (z) ((x) + (1)) ((y) + (1)) ((z) + (1)) ((x) + (1)) (y) ((z) + (1))\n    else\n        set [blockface x+ render? v] to [0]\n    end\n    if <<(Rendered Player - X) < (x)> and <<(Block - X-) = [air]> or <(Block - X-) = [barrier]>>> then\n        set [blockface x- render? v] to [1]\n        drawFace (x) (y) (z) (x) ((y) + (1)) (z) (x) ((y) + (1)) ((z) + (1)) (x) (y) ((z) + (1))\n    else\n        set [blockface x- render? v] to [0]\n    end\n    if <<(Rendered Player - Y) < (y)> and <<(Block - Y-) = [air]> or <(Block - Y-) = [barrier]>>> then\n        set [blockface y- render? v] to [1]\n        drawFace ((x) + (1)) (y) (z) ((x) + (1)) (y) ((z) + (1)) (x) (y) ((z) + (1)) (x) (y) (z)\n    else\n        set [blockface y- render? v] to [0]\n    end\n    if <<(Rendered Player - Y) > ((y) + (1))> and <<(Block - Y+) = [air]> or <(Block - Y+) = [barrier]>>> then\n        set [blockface y+ render? v] to [1]\n        drawFace ((x) + (1)) ((y) + (1)) (z) ((x) + (1)) ((y) + (1)) ((z) + (1)) (x) ((y) + (1)) ((z) + (1)) (x) ((y) + (1)) (z)\n    else\n        set [blockface y+ render? v] to [0]\n    end\n    if <<(Rendered Player - Z) > ((z) + (0.5))> and <<(Block - Z+) = [air]> or <(Block - Z+) = [barrier]>>> then\n        set [blockface z+ render? v] to [1]\n        drawFace ((x) + (1)) ((y) + (1)) ((z) + (1)) (x) ((y) + (1)) ((z) + (1)) (x) (y) ((z) + (1)) ((x) + (1)) (y) ((z) + (1))\n    else\n        set [blockface z+ render? v] to [0]\n    end\n    if <<(Rendered Player - Z) < ((z) + (0.5))> and <<(Block - Z-) = [air]> or <(Block - Z-) = [barrier]>>> then\n        set [blockface z- render? v] to [1]\n        drawFace ((x) + (1)) ((y) + (1)) (z) (x) ((y) + (1)) (z) (x) (y) (z) ((x) + (1)) (y) (z)\n    else\n        set [blockface z- render? v] to [0]\n    end\n    set pen color to (#3e3e3e)\n    if <<(Blockface X+ Render?) = [1]> or <(Blockface Y- Render?) = [1]>> then\n        drawLine - 3D ((x) + (1)) (y) (z) ((x) + (1)) (y) ((z) + (1)) [-1]\n    end\n    if <<(Blockface X+ Render?) = [1]> or <(Blockface Y+ Render?) = [1]>> then\n        drawLine - 3D ((x) + (1)) ((y) + (1)) (z) ((x) + (1)) ((y) + (1)) ((z) + (1)) [-1]\n    end\n    if <<(Blockface X+ Render?) = [1]> or <(Blockface Z+ Render?) = [1]>> then\n        drawLine - 3D ((x) + (1)) (y) ((z) + (1)) ((x) + (1)) ((y) + (1)) ((z) + (1)) [-1]\n    end\n    if <<(Blockface X+ Render?) = [1]> or <(Blockface Z- Render?) = [1]>> then\n        drawLine - 3D ((x) + (1)) (y) (z) ((x) + (1)) ((y) + (1)) (z) [-1]\n    end\n    if <<(Blockface X- Render?) = [1]> or <(Blockface Y+ Render?) = [1]>> then\n        drawLine - 3D (x) ((y) + (1)) (z) (x) ((y) + (1)) ((z) + (1)) [-1]\n    end\n    if <<(Blockface X- Render?) = [1]> or <(Blockface Y- Render?) = [1]>> then\n        drawLine - 3D (x) (y) (z) (x) (y) ((z) + (1)) [-1]\n    end\n    if <<(Blockface X- Render?) = [1]> or <(Blockface Z+ Render?) = [1]>> then\n        drawLine - 3D (x) (y) ((z) + (1)) (x) ((y) + (1)) ((z) + (1)) [-1]\n    end\n    if <<(Blockface X- Render?) = [1]> or <(Blockface Z- Render?) = [1]>> then\n        drawLine - 3D (x) (y) (z) (x) ((y) + (1)) (z) [-1]\n    end\n    if <<(Blockface Y- Render?) = [1]> or <(Blockface Z- Render?) = [1]>> then\n        drawLine - 3D (x) (y) (z) ((x) + (1)) (y) (z) [-1]\n    end\n    if <<(Blockface Y- Render?) = [1]> or <(Blockface Z+ Render?) = [1]>> then\n        drawLine - 3D (x) (y) ((z) + (1)) ((x) + (1)) (y) ((z) + (1)) [-1]\n    end\n    if <<(Blockface Z+ Render?) = [1]> or <(Blockface Y+ Render?) = [1]>> then\n        drawLine - 3D (x) ((y) + (1)) ((z) + (1)) ((x) + (1)) ((y) + (1)) ((z) + (1)) [-1]\n    end\n    if <<(Blockface Z- Render?) = [1]> or <(Blockface Y+ Render?) = [1]>> then\n        drawLine - 3D (x) ((y) + (1)) (z) ((x) + (1)) ((y) + (1)) (z) [-1]\n    end\nend\n\ndefine renderFrame\nerase all\ngenerateBlockDistances\nquicksort (1) (length of [block - x v])\nset [rendered player - pitch v] to (Player - Pitch)\nset [rendered player - yaw v] to (Player - Yaw)\nset [rendered player - x v] to (Player - X)\nset [rendered player - y v] to (Player - Y)\nset [rendered player - z v] to (Player - Z)\nset [sin x v] to ([sin v] of (Rendered Player - Pitch) )\nset [cos x v] to ([cos v] of (Rendered Player - Pitch) )\nset [sin y v] to ([sin v] of (() - (Rendered Player - Yaw)) )\nset [cos y v] to ([cos v] of (() - (Rendered Player - Yaw)) )\nset [drawer - blockselector v] to (length of [block - x v])\nrepeat (length of [block - x v])\n    set [drawer - renderorderblock v] to (item (Drawer - BlockSelector) of [block - render order v])\n    drawCube ((item (Drawer - RenderOrderBlock) of [block - x v]) - (Setting - Camera X Offset)) ((item (Drawer - RenderOrderBlock) of [block - y v]) - (Setting - Camera Y Offset)) ((item (Drawer - RenderOrderBlock) of [block - z v]) - (Setting - Camera Z Offset)) (item (Drawer - RenderOrderBlock) of [block - type v])\n    change [drawer - blockselector v] by (-1)\nend\n\ndefine getBlock (x) (y) (z)\nset [type v] to (join ([floor v] of (x) ) (join (join [:] ([floor v] of (y) )) (join [:] ([floor v] of (z) ))))\nset [blocknumber v] to (item # of (join ([floor v] of (x) ) (join (join [:] ([floor v] of (y) )) (join [:] ([floor v] of (z) )))) in [block - search v])\nif <(BlockNumber) = [0]> then\n    set [blocktypereturn v] to [air]\nelse\n    set [blocktypereturn v] to (item (BlockNumber) of [block - type v])\nend\n\nwhen I receive [finishedloading v]\nshow variable [timer v]\nshow variable [render - filler? v]\nreset timer\nset [lastruntimemovement v] to [0]\nforever\n    if <(lastRunTime) < (Runtime Controller)> then\n        PlayerVelocity\n        if <(Controls) = [1]> then\n            CameraVelocity\n            Camera Movement\n        end\n        Camera Restrictions\n        Player Movement\n        set [lastruntimemovement v] to (timer)\n        if <(level) < [8]> then\n            set [timer v] to (timer)\n        end\n    end\nend\n\ndefine PlayerVelocity\nif <<(Controls) = [0]> or <(Controls) = [1]>> then\n    if <key (w v) pressed?> then\n        if <not <(Player - Yv) = [1]>> then\n            if <(Player - Yv) > [1]> then\n                set [player - yv v] to [1]\n            else\n                change [player - yv v] by ((4) * ((timer) - (lastRunTimeMovement)))\n            end\n        end\n    else\n        if <key (s v) pressed?> then\n            if <not <(Player - Yv) = [-1]>> then\n                if <(Player - Yv) < [-1]> then\n                    set [player - yv v] to [-1]\n                else\n                    change [player - yv v] by ((-4) * ((timer) - (lastRunTimeMovement)))\n                end\n            end\n        else\n            if <not <(Player - Yv) = [0]>> then\n                if <([abs v] of (Player - Yv) ) < ((4) * ((timer) - (lastRunTimeMovement)))> then\n                    set [player - yv v] to [0]\n                else\n                    change [player - yv v] by (((Player - Yv) / ([abs v] of (Player - Yv) )) * ((-5) * ((timer) - (lastRunTimeMovement))))\n                end\n            end\n        end\n    end\n    if <key (a v) pressed?> then\n        if <not <(Player - Xv) = [1]>> then\n            if <(Player - Xv) > [1]> then\n                set [player - xv v] to [1]\n            else\n                change [player - xv v] by ((-4) * ((timer) - (lastRunTimeMovement)))\n            end\n        end\n    else\n        if <key (d v) pressed?> then\n            if <not <(Player - Xv) = [-1]>> then\n                if <(Player - Xv) < [-1]> then\n                    set [player - xv v] to [-1]\n                else\n                    change [player - xv v] by ((4) * ((timer) - (lastRunTimeMovement)))\n                end\n            end\n        else\n            if <not <(Player - Xv) = [0]>> then\n                if <([abs v] of (Player - Xv) ) < ((4) * ((timer) - (lastRunTimeMovement)))> then\n                    set [player - xv v] to [0]\n                else\n                    change [player - xv v] by (((Player - Xv) / ([abs v] of (Player - Xv) )) * ((-4) * ((timer) - (lastRunTimeMovement))))\n                end\n            end\n        end\n    end\n    if <(Player - \[Z- Collision\]) = [true]> then\n        if <<key (space v) pressed?> and <(Player - \[Z+ Collision\]) = [false]>> then\n            set [player - zv v] to [1]\n        end\n    else\n        if <not <(Player - Zv) = [-1]>> then\n            if <(Player - Zv) < [-5]> then\n                set [player - zv v] to [-5]\n            else\n                change [player - zv v] by ((-2) * ((timer) - (lastRunTimeMovement)))\n            end\n        end\n    end\nelse\n    set [player - yv v] to (Control - Movement Y)\n    set [player - xv v] to (Control - Movement X)\n    if <(Player - \[Z- Collision\]) = [true]> then\n        if <<(Control - Jump?) = [true]> and <(Player - \[Z+ Collision\]) = [false]>> then\n            set [player - zv v] to [1]\n        end\n    else\n        if <not <(Player - Zv) = [-1]>> then\n            if <(Player - Zv) < [-5]> then\n                set [player - zv v] to [-5]\n            else\n                change [player - zv v] by ((-2) * ((timer) - (lastRunTimeMovement)))\n            end\n        end\n    end\nend\n\ndefine CameraVelocity\nif <key (right arrow v) pressed?> then\n    if <not <(Player - YawV) = [1]>> then\n        if <(Player - YawV) > [1]> then\n            set [player - yawv v] to [1]\n        else\n            change [player - yawv v] by ((5) * ((timer) - (lastRunTimeMovement)))\n        end\n    end\nelse\n    if <key (left arrow v) pressed?> then\n        if <not <(Player - YawV) = [-1]>> then\n            if <(Player - YawV) < [-1]> then\n                set [player - yawv v] to [-1]\n            else\n                change [player - yawv v] by ((-5) * ((timer) - (lastRunTimeMovement)))\n            end\n        end\n    else\n        if <not <(Player - YawV) = [0]>> then\n            if <([abs v] of (Player - YawV) ) < ((10) * ((timer) - (lastRunTimeMovement)))> then\n                set [player - yawv v] to [0]\n            else\n                change [player - yawv v] by (((Player - YawV) / ([abs v] of (Player - YawV) )) * ((-10) * ((timer) - (lastRunTimeMovement))))\n            end\n        end\n    end\nend\nif <key (up arrow v) pressed?> then\n    if <not <(Player - PitchV) = [1]>> then\n        if <(Player - PitchV) > [1]> then\n            set [player - pitchv v] to [1]\n        else\n            change [player - pitchv v] by ((5) * ((timer) - (lastRunTimeMovement)))\n        end\n    end\nelse\n    if <key (down arrow v) pressed?> then\n        if <not <(Player - PitchV) = [-1]>> then\n            if <(Player - PitchV) < [-1]> then\n                set [player - pitchv v] to [-1]\n            else\n                change [player - pitchv v] by ((-5) * ((timer) - (lastRunTimeMovement)))\n            end\n        end\n    else\n        if <not <(Player - PitchV) = [0]>> then\n            if <([abs v] of (Player - PitchV) ) < ((10) * ((timer) - (lastRunTimeMovement)))> then\n                set [player - pitchv v] to [0]\n            else\n                change [player - pitchv v] by (((Player - PitchV) / ([abs v] of (Player - PitchV) )) * ((-10) * ((timer) - (lastRunTimeMovement))))\n            end\n        end\n    end\nend\n\ndefine Camera Movement\nchange [player - yaw v] by ((Player - YawV) * ((180) * ((timer) - (lastRunTimeMovement))))\nchange [player - pitch v] by ((Player - PitchV) * ((180) * ((timer) - (lastRunTimeMovement))))\n\ndefine Player Movement\nchange [player - x v] by (((Player - Yv) * (((6) * ((timer) - (lastRunTimeMovement))) * ([sin v] of (Player - Yaw) ))) + ((Player - Xv) * (((3) * ((timer) - (lastRunTimeMovement))) * ([sin v] of ((Player - Yaw) + (90)) ))))\nchange [player - y v] by (((Player - Yv) * (((6) * ((timer) - (lastRunTimeMovement))) * ([cos v] of (Player - Yaw) ))) + ((Player - Xv) * (((3) * ((timer) - (lastRunTimeMovement))) * ([cos v] of ((Player - Yaw) + (90)) ))))\nchange [player - z v] by ((Player - Zv) * ((5) * ((timer) - (lastRunTimeMovement))))\ncheckCollision\nif <(Player - \[Z- Collision\]) = [true]> then\n    set [player - z v] to ([ceiling v] of ((Player - Z) - (0.25)) )\n    set [player - zv v] to [0]\n    checkCollision\nelse\n    if <(Player - \[Z+ Collision\]) = [true]> then\n        set [player - z v] to (([floor v] of (Player - Z) ) + (0.2))\n        set [player - zv v] to [0]\n        checkCollision\n    end\nend\nif <not <<(Player - Feet X+) = [air]> and <<(Player - Torso X+) = [air]> and <(Player - Head X+) = [air]>>>> then\n    set [player - x v] to (([ceiling v] of (Player - X) ) - (0.5))\n    set [player - xv v] to [0]\n    checkCollision\nelse\n    if <not <<(Player - Feet X-) = [air]> and <<(Player - Torso X-) = [air]> and <(Player - Head X-) = [air]>>>> then\n        set [player - x v] to (([floor v] of (Player - X) ) + (0.5))\n        set [player - xv v] to [0]\n        checkCollision\n    end\nend\nif <not <<(Player - Feet Y+) = [air]> and <<(Player - Torso Y+) = [air]> and <(Player - Head Y+) = [air]>>>> then\n    set [player - y v] to (([ceiling v] of (Player - Y) ) - (0.5))\n    set [player - yv v] to [0]\nelse\n    if <not <<(Player - Feet Y-) = [air]> and <<(Player - Torso Y-) = [air]> and <(Player - Head Y-) = [air]>>>> then\n        set [player - y v] to (([floor v] of (Player - Y) ) + (0.5))\n        set [player - yv v] to [0]\n    end\nend\n\ndefine checkCollision\nset [player - feet z- last check v] to (Player - Feet Z-)\ngetBlock (Player - X) (Player - Y) ((Player - Z) - (0.01))\nset [player - feet z- v] to (BlockTypeReturn)\ngetBlock (Player - X) (Player - Y) ((Player - Z) + (1.81))\nset [player - head z+ v] to (BlockTypeReturn)\ngetBlock ((Player - X) + (0.49)) (Player - Y) ((Player - Z) + (0.1))\nset [player - feet x+ v] to (BlockTypeReturn)\ngetBlock ((Player - X) + (0.49)) (Player - Y) ((Player - Z) + (0.9))\nset [player - torso x+ v] to (BlockTypeReturn)\ngetBlock ((Player - X) + (0.49)) (Player - Y) ((Player - Z) + (1.8))\nset [player - head x+ v] to (BlockTypeReturn)\ngetBlock ((Player - X) - (0.49)) (Player - Y) ((Player - Z) + (0.1))\nset [player - feet x- v] to (BlockTypeReturn)\ngetBlock ((Player - X) - (0.49)) (Player - Y) ((Player - Z) + (0.9))\nset [player - torso x- v] to (BlockTypeReturn)\ngetBlock ((Player - X) - (0.49)) (Player - Y) ((Player - Z) + (1.8))\nset [player - head x- v] to (BlockTypeReturn)\ngetBlock (Player - X) ((Player - Y) + (0.49)) ((Player - Z) + (0.1))\nset [player - feet y+ v] to (BlockTypeReturn)\ngetBlock (Player - X) ((Player - Y) + (0.49)) ((Player - Z) + (0.9))\nset [player - torso y+ v] to (BlockTypeReturn)\ngetBlock (Player - X) ((Player - Y) + (0.49)) ((Player - Z) + (1.8))\nset [player - head y+ v] to (BlockTypeReturn)\ngetBlock (Player - X) ((Player - Y) - (0.49)) ((Player - Z) + (0.1))\nset [player - feet y- v] to (BlockTypeReturn)\ngetBlock (Player - X) ((Player - Y) - (0.49)) ((Player - Z) + (0.9))\nset [player - torso y- v] to (BlockTypeReturn)\ngetBlock (Player - X) ((Player - Y) - (0.49)) ((Player - Z) + (1.8))\nset [player - head y- v] to (BlockTypeReturn)\ndelete all of [touching v]\nset [player - \[z- collision\] v] to [false]\nset [player - \[z+ collision\] v] to [false]\nset [collisioniteratori v] to [-0.25]\nrepeat (2)\n    set [collisioniteratorj v] to [-0.25]\n    repeat (2)\n        getBlock ((Player - X) - (collisionIteratorI)) ((Player - Y) - (collisionIteratorJ)) ((Player - Z) - (0.01))\n        add (BlockTypeReturn) to [touching v]\n        if <not <(BlockTypeReturn) = [air]>> then\n            set [player - \[z- collision\] v] to [true]\n        end\n        change [collisioniteratorj v] by (0.5)\n    end\n    change [collisioniteratori v] by (0.5)\nend\nset [collisioniteratori v] to [-0.25]\nrepeat (2)\n    set [collisioniteratorj v] to [-0.25]\n    repeat (2)\n        getBlock ((Player - X) - (collisionIteratorI)) ((Player - Y) - (collisionIteratorJ)) ((Player - Z) + (1.81))\n        add (BlockTypeReturn) to [touching v]\n        if <not <(BlockTypeReturn) = [air]>> then\n            set [player - \[z+ collision\] v] to [true]\n        end\n        change [collisioniteratorj v] by (0.5)\n    end\n    change [collisioniteratori v] by (0.5)\nend\n\ndefine drawLine - 3D (x1) (y1) (z1) (x2) (y2) (z2) (pensize)\n3D point -> 2D point (x1) (y1) (z1)\nset [x1 v] to (2D - X)\nset [y1 v] to (2D - Y)\nif <(2D - Visible?) = [false]> then\n    stop [this script v]\nend\n3D point -> 2D point (x2) (y2) (z2)\nset [x2 v] to (2D - X)\nset [y2 v] to (2D - Y)\nif <(2D - Visible?) = [false]> then\n    stop [this script v]\nend\nif <not <(pensize) = [-1]>> then\n    set [pensize v] to (pensize)\nelse\n    set [pensize v] to ([ceiling v] of ((10) / (([sqrt v] of (((((x1) - (Rendered Player - X)) * ((x1) - (Rendered Player - X))) + (((y1) - (Rendered Player - Y)) * ((y1) - (Rendered Player - Y)))) + (((z1) - (Rendered Player - Z)) * ((z1) - (Rendered Player - Z)))) ) + ([sqrt v] of (((((x2) - (Rendered Player - X)) * ((x2) - (Rendered Player - X))) + (((y2) - (Rendered Player - Y)) * ((y2) - (Rendered Player - Y)))) + (((z2) - (Rendered Player - Z)) * ((z2) - (Rendered Player - Z)))) ))) )\nend\ndrawLine - 2D (X1) (Y1) (X2) (Y2) (penSize)\n\nwhen flag clicked\nset size to (join [Infinity] []) %\nset [ghost v] effect to (100)\nhide variable [setting - fps limit v]\nhide variable [runtime controller v]\nhide variable [setting - camera x offset v]\nhide variable [setting - camera y offset v]\nhide variable [setting - camera z offset v]\nhide variable [setting - fov v]\nhide variable [player - x v]\nhide variable [player - y v]\nhide variable [player - z v]\nhide variable [lastruntime v]\nhide variable [lastruntimemovement v]\nhide variable [linedensity v]\nhide variable [line pixel iterator v]\nhide variable [block - yaw offset v]\nhide variable [block - pitch offset v]\nhide variable [drawer - blockselector v]\nhide variable [lastruntime v]\nhide variable [player - pitch v]\nhide variable [player - yaw v]\nhide variable [player - xv v]\nhide variable [player - yv v]\nhide variable [player - zv v]\nhide variable [player - pitchv v]\nhide variable [player - yawv v]\nhide variable [timer v]\nhide variable [render - filler? v]\nset [setting - view factor v] to [100]\nset [player - pitch v] to [0]\nset [player - yaw v] to [0]\nset [player - x v] to [0.5]\nset [player - y v] to [0.5]\nset [player - z v] to [0]\nset [player - pitchv v] to [0]\nset [player - yawv v] to [0]\nset [player - xv v] to [0]\nset [player - yv v] to [0]\nset [player - zv v] to [0]\nset [line pixel iterator v] to [0]\nset [lastruntime v] to [0]\nset [setting - camera x offset v] to [0]\nset [setting - camera y offset v] to [0]\nset [setting - camera z offset v] to [1.5]\nset [setting - view factor v] to [120]\nset [setting - fps limit v] to [30]\nforever\n    renderFrame\nend\n\ndefine drawFace (x1) (y1) (z1) (x2) (y2) (z2) (x3) (y3) (z3) (x4) (y4) (z4)\n3D point -> 2D point (x1) (y1) (z1)\nset [x1 v] to (2D - X)\nset [y1 v] to (2D - Y)\nif <(2D - Visible?) = [false]> then\n    stop [this script v]\nend\n3D point -> 2D point (x3) (y3) (z3)\nset [x2 v] to (2D - X)\nset [y2 v] to (2D - Y)\nif <(2D - Visible?) = [false]> then\n    stop [this script v]\nend\n3D point -> 2D point (x2) (y2) (z2)\nset [x3 v] to (2D - X)\nset [y3 v] to (2D - Y)\nif <(2D - Visible?) = [false]> then\n    stop [this script v]\nend\n3D point -> 2D point (x4) (y4) (z4)\nset [x4 v] to (2D - X)\nset [y4 v] to (2D - Y)\nif <(2D - Visible?) = [false]> then\n    stop [this script v]\nend\nset [pensize v] to ([ceiling v] of ((10) / (([sqrt v] of (((((x1) - (Rendered Player - X)) * ((x1) - (Rendered Player - X))) + (((y1) - (Rendered Player - Y)) * ((y1) - (Rendered Player - Y)))) + (((z1) - (Rendered Player - Z)) * ((z1) - (Rendered Player - Z)))) ) + ([sqrt v] of (((((x2) - (Rendered Player - X)) * ((x2) - (Rendered Player - X))) + (((y2) - (Rendered Player - Y)) * ((y2) - (Rendered Player - Y)))) + (((z2) - (Rendered Player - Z)) * ((z2) - (Rendered Player - Z)))) ))) )\nif <(Render - Filler?) = [0]> then\n    drawLine - 2D (X1) (Y1) (X2) (Y2) (penSize)\n    drawLine - 2D (X3) (Y3) (X4) (Y4) (penSize)\nelse\n    fill (X1) (Y1) (X2) (Y2) (X3) (Y3) resolution: (penSize)\n    fill (X2) (Y2) (X1) (Y1) (X4) (Y4) resolution: (penSize)\nend\n\ndefine drawLine - 2D (x1) (y1) (x2) (y2) (pensize)\nset pen size to (pensize)\ngo to x: (x1) y: (y1)\npen down\ngo to x: (x2) y: (y2)\npen up\n\ndefine set3DPoints (x) (y) (z)\nset [3d - x v] to (x)\nset [3d - y v] to (y)\nset [3d - z v] to (z)\n\ndefine 3D point -> 2D point (x) (y) (z)\nset3DPoints ((x) - (Rendered Player - X)) ((y) - (Rendered Player - Y)) ((z) - (Rendered Player - Z))\nset3DPoints (((3D - Y) * (sin Y)) + ((3D - X) * (cos Y))) (((3D - Y) * (cos Y)) - ((3D - X) * (sin Y))) (3D - Z)\nset3DPoints (3D - X) (((3D - Z) * (sin X)) + ((3D - Y) * (cos X))) (((3D - Z) * (cos X)) - ((3D - Y) * (sin X)))\nset [2d - visible? v] to <(3D - Y) > [0]>\nset [2d - x v] to ((Setting - View Factor) * ((3D - X) / (3D - Y)))\nset [2d - y v] to ((Setting - View Factor) * ((3D - Z) / (3D - Y)))\n\ndefine Camera Restrictions\nif <(Player - Pitch) > [75]> then\n    set [player - pitch v] to [75]\nend\nif <(Player - Pitch) < [-75]> then\n    set [player - pitch v] to [-75]\nend\nif <(Player - Yaw) > [180]> then\n    set [player - yaw v] to ((-180) + ((Player - Yaw) - (180)))\nend\nif <(Player - Yaw) < [-180]> then\n    set [player - yaw v] to ((180) + ((Player - Yaw) + (180)))\nend\n\n@brokenStudios\n\nwhen flag clicked\nhide\ngo to x: (0) y: (0)\npoint in direction (90)\nhide variable [clone id v]\nset [clone id v] to [0]\ncreate clone of (_myself_ v)\nset [clone id v] to [1]\ncreate clone of (_myself_ v)\nset [clone id v] to [2]\ncreate clone of (_myself_ v)\nset [clone id v] to [3]\ncreate clone of (_myself_ v)\n\nwhen I receive [animation finalize v]\nwait (1) seconds\nif <(clone id) = [2]> then\n    go to x: (0) y: (-130)\n    switch costume to (costume3 v)\n    set [ghost v] effect to (100)\n    show\n    repeat (10)\n        change [ghost v] effect by (-10)\n    end\n    broadcast (End Animation v)\nend\n\nwhen I receive [end animation v]\nwait until <mouse down?>\nset [start v] to [1]\n\nwhen I start as a clone\nif <(clone id) = [0]> then\n    go to x: (-70) y: (180)\n    switch costume to (costume1 v)\n    wait (0.75) seconds\n    show\n    glide (0.2) secs to x: (-70) y: (70)\nend\nif <(clone id) = [1]> then\n    go to x: (-72.5) y: (180)\n    point in direction (90)\n    switch costume to (costume2 v)\n    wait (0.78) seconds\n    show\n    glide (0.1) secs to x: (-72.5) y: (70)\n    set [c v] to [0]\n    repeat (18)\n        change [c v] by (0.1)\n        turn right (20) degrees\n        change y by ((-10) * ((1) + ((c) * (1.33))))\n    end\n    hide\n    wait (0.8) seconds\n    go to x: (-72.5) y: (70)\n    point in direction (90)\n    broadcast (Animation Finalize v)\n    set [ghost v] effect to (100)\n    show\n    repeat (15)\n        change [ghost v] effect by (-7.5)\n    end\nend\nif <(clone id) = [3]> then\n    go to [back v] layer\n    switch costume to (costume4 v)\n    show\nend\n\nwhen I receive [finishedloading v]\nwait (0.01) seconds\nhide\n\n@FPS\n\nwhen flag clicked\nset [count v] to [0]\nset [lastupdate v] to (timer)\nforever\n    change [count v] by (1)\n    if <((LastUpdate) + (1)) < (timer)> then\n        set [fps v] to (Count)\n        set [count v] to [0]\n        set [lastupdate v] to (timer)\n    end\nend\n\n@Tutorial\n\nwhen flag clicked\nhide\nswitch costume to (level 1 v)\nset [polarity v] to [1]\nset [animationrotation v] to [0]\nset [tutorialvisible? v] to [1]\nset [translationpolarity v] to [1]\nset [animationtranslation v] to [0]\n\nwhen I receive [finishedloading v]\nshow\nforever\n    wait (0.01) seconds\n    go to x: (0) y: ((100) + (animationTRANSLATION))\n    point in direction ((90) + ((animationROTATION) * (0.25)))\n    change [animationrotation v] by (polarity)\n    change [animationtranslation v] by (TranslationPolarity)\n    if <([abs v] of (animationROTATION) ) > [7]> then\n        set [polarity v] to ((0) - (polarity))\n    end\n    if <([abs v] of (animationTRANSLATION) ) > [5]> then\n        set [translationpolarity v] to ((0) - (TranslationPolarity))\n    end\n    if <not <(level) = (lastCheckLevel)>> then\n        switch costume to (no tutorial v)\n        if <(level) = [1]> then\n            switch costume to (level 1 v)\n        end\n        if <(level) = [2]> then\n            switch costume to (level 2 v)\n        end\n        if <(level) = [3]> then\n            switch costume to (level 3 v)\n        end\n        if <(level) = [4]> then\n            switch costume to (level 4 v)\n        end\n        if <(level) = [8]> then\n            switch costume to (level 8 v)\n            set [tutorialvisible? v] to [1]\n            broadcast (runFinished v)\n            broadcast (update highscores v)\n        end\n    end\n    if <(TutorialVisible?) = [1]> then\n        show\n    else\n        hide\n    end\n    set [lastchecklevel v] to (level)\nend\n\nwhen [t v] key pressed\nset [tutorialvisible? v] to ((0) - (TutorialVisible?))\n\n@Leaderboard\n\nwhen I receive [initialise highscores v]\nget username\nset [all characters v] to [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_]\ndelete all of [all characters v]\nset [index v] to [1]\nrepeat (length of (all characters))\n    add (letter (index) of (all characters)) to [all characters v]\n    change [index v] by (1)\nend\nset [high score number v] to [5]\ndelete all of [high scores v]\ndelete all of [high score names v]\nrepeat (high score number)\n    add [ScratchCat] to [high score names v]\n    add [100] to [high scores v]\nend\ndecode high scores\n\nwhen I receive [update highscores v]\nset [updated? v] to [false]\ndecode high scores\nset [index v] to [1]\nrepeat (high score number)\n    if <(round ((timer) * (100))) < (item (index) of [high scores v])> then\n        set [updated? v] to [true]\n        insert (round ((timer) * (100))) at (index) of [high scores v] \n        insert (username) at (index) of [high score names v] \n        change [index v] by (1)\n        repeat until <(index) > (high score number)>\n            if <(item (index) of [high score names v]) = (username)> then\n                delete (index) of [high score names v]\n                delete (index) of [high scores v]\n                encode high scores\n                stop [this script v]\n            end\n            change [index v] by (1)\n        end\n        delete ((high score number) + (1)) of [high scores v]\n        delete ((high score number) + (1)) of [high score names v]\n        encode high scores\n        stop [this script v]\n    else\n        if <(item (index) of [high score names v]) = (username)> then\n            stop [this script v]\n        end\n    end\n    change [index v] by (1)\nend\n\ndefine get username\nset [username v] to []\nset [index v] to [1]\nrepeat (20)\n    set [username v] to (join (username) (letter (index) of (username)))\n    change [index v] by (1)\n    if <(index) > (length of (username))> then\n        stop [this script v]\n    end\nend\n\ndefine encode high scores\nif <(connected?) = [true]> then\n    set [cloud data v] to []\n    set [highscore index v] to [1]\n    repeat (high score number)\n        encode name (item (highscore index) of [high score names v])\n        encode score (item (highscore index) of [high scores v])\n        change [highscore index v] by (1)\n    end\n    set [☁ highscores v] to (cloud data)\nend\ndecode high scores\n\ndefine encode name (name)\nset [index v] to [1]\nrepeat (length of (name))\n    set [character v] to (letter (index) of (name))\n    set [character number v] to (item # of (character) in [all characters v])\n    if <(character number) < [10]> then\n        set [character number v] to (join [0] (character number))\n    end\n    set [cloud data v] to (join (cloud data) (character number))\n    change [index v] by (1)\nend\nrepeat ((20) - (length of (name)))\n    set [cloud data v] to (join (cloud data) [00])\nend\n\ndefine encode score (score)\nset [score v] to ((score) mod (100000))\nrepeat until <(length of (score)) = [5]>\n    set [score v] to (join [0] (score))\nend\nset [cloud data v] to (join (cloud data) (score))\n\ndefine decode high scores\nset [cloud data v] to (☁ Highscores)\nif <(cloud data) = [0]> then\n    set [connected? v] to [false]\nelse\n    set [index v] to [1]\n    set [connected? v] to [true]\n    set [highscore index v] to [1]\n    repeat (high score number)\n        decode name\n        decode score\n        replace item (highscore index) of [high score names v] with (decoded name)\n        replace item (highscore index) of [high scores v] with (decoded score)\n        change [highscore index v] by (1)\n    end\nend\n\ndefine decode name\nset [decoded name v] to []\nrepeat (20)\n    set [character number v] to (join (letter (index) of (cloud data)) (letter ((index) + (1)) of (cloud data)))\n    if <(character number) > [0]> then\n        set [character v] to (item (character number) of [all characters v])\n        set [decoded name v] to (join (decoded name) (character))\n    end\n    change [index v] by (2)\nend\n\ndefine decode score\nset [decoded score v] to []\nrepeat (5)\n    set [decoded score v] to (join (decoded score) (letter (index) of (cloud data)))\n    change [index v] by (1)\nend\n\nwhen flag clicked\nbroadcast (initialise highscores v)\n\n@Touchscreen\n\nwhen flag clicked\nhide\nhide variable [controls v]\nhide variable [control name v]\nset [touchscreen - mousedownleftfield v] to [false]\nset [touchscreen - joystick x v] to [-170]\nset [touchscreen - joystick y v] to [-80]\nset [controls - id v] to [1]\ncreate clone of (_myself_ v)\nset [controls - id v] to [2]\ncreate clone of (_myself_ v)\nset [controls - id v] to [3]\ncreate clone of (_myself_ v)\nset [controls v] to [0]\nforever\n    if <(Controls) = [0]> then\n        if <<mouse down?> and <(mouseDownPrevious?) = [false]>> then\n            set [control - last recorded mouse x v] to (mouse x)\n            set [control - last recorded mouse y v] to (mouse y)\n            repeat until <<not <mouse down?>> or <<((mouse x) - (Control - Last Recorded Mouse X)) > [100]> or <((mouse y) - (Control - Last Recorded Mouse Y)) > [100]>>>\n                change [player - yaw v] by (((mouse x) - (Control - Last Recorded Mouse X)) * (0.75))\n                change [player - pitch v] by (((mouse y) - (Control - Last Recorded Mouse Y)) * (0.75))\n                set [control - last recorded mouse x v] to (mouse x)\n                set [control - last recorded mouse y v] to (mouse y)\n            end\n        end\n        set [mousedownprevious? v] to <mouse down?>\n    end\n    if <(Controls) = [2]> then\n        set [touchscreen - show? v] to [true]\n        if <<mouse down?> and <(mouseDownPrevious?) = [false]>> then\n            if <(mouse x) < [0]> then\n                set [touchscreen - mousedownleftfield v] to [true]\n                set [touchscreen - joystick x v] to (mouse x)\n                set [touchscreen - joystick y v] to (mouse y)\n                if <(Touchscreen - Joystick X) < [-180]> then\n                    set [touchscreen - joystick x v] to [-180]\n                end\n                if <(Touchscreen - Joystick X) > [-45]> then\n                    set [touchscreen - joystick x v] to [-45]\n                end\n                if <(Touchscreen - Joystick Y) < [-120]> then\n                    set [touchscreen - joystick y v] to [-120]\n                end\n                if <(Touchscreen - Joystick Y) > [0]> then\n                    set [touchscreen - joystick y v] to [0]\n                end\n                wait until <not <mouse down?>>\n                set [touchscreen - mousedownleftfield v] to [false]\n                set [touchscreen - joystick x v] to [-170]\n                set [touchscreen - joystick y v] to [-80]\n            else\n                set [control - last recorded mouse x v] to (mouse x)\n                set [control - last recorded mouse y v] to (mouse y)\n                repeat until <<not <mouse down?>> or <<((mouse x) - (Control - Last Recorded Mouse X)) > [100]> or <((mouse y) - (Control - Last Recorded Mouse Y)) > [100]>>>\n                    change [player - yaw v] by (((mouse x) - (Control - Last Recorded Mouse X)) * (0.75))\n                    change [player - pitch v] by (((mouse y) - (Control - Last Recorded Mouse Y)) * (0.75))\n                    set [control - last recorded mouse x v] to (mouse x)\n                    set [control - last recorded mouse y v] to (mouse y)\n                end\n            end\n        end\n        set [mousedownprevious? v] to <mouse down?>\n    else\n        set [touchscreen - show? v] to [false]\n    end\nend\n\nwhen I receive [finishedloading v]\nshow variable [controls v]\nshow variable [control name v]\n\nwhen I start as a clone\nif <(Controls - ID) = [1]> then\n    switch costume to (outer circle v)\n    set [ghost v] effect to (75)\n    forever\n        if <(Touchscreen - Show?) = [true]> then\n            show\n            go to x: (Touchscreen - Joystick X) y: (Touchscreen - Joystick Y)\n            point towards (mouse-pointer v)\n            set [touchscreen - joystick direction v] to (direction)\n            point in direction (90)\n            set [control - distancetomouse v] to (distance to [mouse-pointer v])\n        else\n            hide\n        end\n    end\nend\nif <(Controls - ID) = [2]> then\n    switch costume to (inner circle v)\n    set [ghost v] effect to (25)\n    go to [front v] layer\n    forever\n        if <(Touchscreen - Show?) = [true]> then\n            show\n            if <(Touchscreen - MouseDownLeftField) = [true]> then\n                if <(Control - DistanceToMouse) < [50]> then\n                    go to x: (mouse x) y: (mouse y)\n                    set [control - movement x v] to (((mouse x) - (Touchscreen - Joystick X)) / (50))\n                    set [control - movement y v] to (((mouse y) - (Touchscreen - Joystick Y)) / (50))\n                else\n                    go to x: ((Touchscreen - Joystick X) + (([cos v] of ((Touchscreen - Joystick Direction) - (90)) ) * (50))) y: ((Touchscreen - Joystick Y) + (([sin v] of ((Touchscreen - Joystick Direction) + (90)) ) * (50)))\n                    set [control - movement x v] to ([cos v] of ((Touchscreen - Joystick Direction) - (90)) )\n                    set [control - movement y v] to ([sin v] of ((Touchscreen - Joystick Direction) + (90)) )\n                end\n            else\n                go to x: (Touchscreen - Joystick X) y: (Touchscreen - Joystick Y)\n                set [control - movement x v] to [0]\n                set [control - movement y v] to [0]\n            end\n        else\n            hide\n        end\n    end\nend\nif <(Controls - ID) = [3]> then\n    go to x: (180) y: (-50)\n    point in direction (90)\n    switch costume to (jump v)\n    set [ghost v] effect to (25)\n    go to [front v] layer\n    forever\n        if <(Touchscreen - Show?) = [true]> then\n            show\n            if <<mouse down?> and <touching (mouse-pointer v)?>> then\n                set [control - jump? v] to [true]\n            else\n                set [control - jump? v] to [false]\n            end\n        else\n            hide\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(Controls) = [0]> then\n        set [control name v] to [Keyboard & Mouse]\n    else\n        if <(Controls) = [1]> then\n            set [control name v] to [   Keyboard Only    ]\n        else\n            set [control name v] to [     Touchscreen     ]\n        end\n    end\nend\n\n@Thumbnail\n\nwhen flag clicked\nhide\n\n@crosshair\n\nwhen flag clicked\nhide\n\nwhen I receive [finishedloading v]\ngo to [front v] layer\ngo to x: (0) y: (0)\nset size to (50) %\nshow\n\n