(Finally Scrolling) Platformer Engine

Instructions: CONTROLS:\n   - left/right arrow keys or A/D to move\n   - up arrow key, W, Z, or Space to jump\n\nYou should make a platformer game with this engine! Remix, backpack all the sprites, or download to get started. There are lots of comments inside to help you.\n\nPlease give me credit if you use this engine!\n\nNon-scrolling platformer engine: https://scratch.mit.edu/projects/238636950/

@Stage\n\n@player\n\nwhen flag clicked\nreset\nset [walljumping v] to [0]\nset [slopeheight v] to [0]\nreset timer\nfps init\nforever\n    go to [front v] layer\n    mode\n    check for actions\n    slopes\n    collide (xvel) (yvel)\n    special collide\n    gravity\n    actions\n    fps calc\n    scroll (min_x) (max_x) (min_y) (max_y) <(x_limits) = [true]> <(y_limits) = [true]>\nend\n\ndefine mode\nif <(wallsliding) = [1]> then\n    set [mode v] to [wall sliding]\nend\nif <(walljumping) = [1]> then\n    set [mode v] to [wall jumping]\nend\nset [slopeheight v] to [0]\nif <(ground) = [1]> then\n    if <<(xvel) > [0]> or <(xvel) < [0]>> then\n        if <<key (right arrow v) pressed?> or <key (left arrow v) pressed?>> then\n            set [mode v] to [walking]\n        else\n            set [mode v] to [sliding]\n        end\n    else\n        set [mode v] to [standing]\n    end\nelse\n    if <(yvel) > [-1]> then\n        if <(walljumping) = [0]> then\n            set [mode v] to [jumping]\n        end\n    else\n        if <<(wallsliding) = [0]> and <(slope) = [0]>> then\n            set [mode v] to [falling]\n        end\n    end\nend\n\ndefine fps init\nset [previoustime v] to (timer)\nset [framecount v] to [0]\nset [fps v] to [0]\n\ndefine fps calc\nchange [framecount v] by (1)\nif <(timer) > ((previoustime) + (0.1))> then\n    set [fps v] to (round ((framecount) / ((timer) - (previoustime))))\n    set [previoustime v] to (timer)\n    set [framecount v] to [0]\nend\n\ndefine None\ncheck for collision\nif <(collide) = [1]> then\n    set [walljumping v] to [0]\nend\nchange y by (yvel)\nif <(yvel) < [0]> then\n    check for collision\n    repeat until <(collide) = [0]>\n        set [jumped v] to [0]\n        set [yvel v] to [0]\n        change y by (1)\n        check for collision\n    end\nend\nif <(yvel) > [0]> then\n    check for collision\n    repeat until <(collide) = [0]>\n        set [yvel v] to [0]\n        change y by (-1)\n        check for collision\n    end\nend\nset [slopeheight v] to [0]\nchange x by (xvel)\ncheck for collision\nrepeat until <<(collide) = [0]> or <(slopeheight) = [9]>>\n    change y by (1)\n    change [slopeheight v] by (1)\n    set [walljumping v] to [0]\n    check for collision\nend\nif <(slopeheight) = [9]> then\n    change y by ((0) - (slopeheight))\n    check for collision\n    repeat until <(collide) = [0]>\n        change x by (((0) - (xvel)) / ([abs v] of (xvel) ))\n        check for collision\n    end\n    if <(action-jump) = [1]> then\n        set [yvel v] to [10]\n        if <(xvel) > [0]> then\n            set [xvel v] to [-6]\n        else\n            set [xvel v] to [6]\n        end\n        set [walljumping v] to [1]\n    else\n        if <(yvel) < [0]> then\n            set [wallsliding v] to [1]\n        end\n    end\nelse\n    set [wallsliding v] to [0]\nend\n\ndefine actions\nif <(action-rightwalk) = [1]> then\n    change [xvel v] by (1)\n    point in direction (90)\nend\nif <(action-leftwalk) = [1]> then\n    change [xvel v] by (-1)\n    point in direction (-90)\nend\nif <<<(action-rightwalk) = [0]> and <(action-leftwalk) = [0]>> or <<(action-rightwalk) = [1]> and <(action-leftwalk) = [1]>>> then\n    if <(xvel) > [0]> then\n        change [xvel v] by (-1)\n    end\n    if <(xvel) < [0]> then\n        change [xvel v] by (1)\n    end\nend\nif <<(action-jump) = [1]> and <(jumped) = [0]>> then\n    set [jumped v] to [1]\n    set [yvel v] to [12]\nend\nif <(xvel) > [5]> then\n    change [xvel v] by (-1)\nend\nif <(xvel) < [-5]> then\n    change [xvel v] by (1)\nend\n\ndefine check for collision\nif <<touching (ground v)?> or <touching (_edge_ v)?>> then\n    set [collide v] to [1]\nelse\n    set [collide v] to [0]\nend\n\ndefine special collide\nif <touching (death v)?> then\n    reset\nend\n\ndefine check for actions\nif <<<key (up arrow v) pressed?> or <key (w v) pressed?>> or <<key (z v) pressed?> or <key (space v) pressed?>>> then\n    set [action-jump v] to [1]\nelse\n    set [action-jump v] to [0]\nend\nif <<key (right arrow v) pressed?> or <key (d v) pressed?>> then\n    set [action-rightwalk v] to [1]\nelse\n    set [action-rightwalk v] to [0]\nend\nif <<key (left arrow v) pressed?> or <key (a v) pressed?>> then\n    set [action-leftwalk v] to [1]\nelse\n    set [action-leftwalk v] to [0]\nend\n\ndefine None\nchange [x v] by (x position)\nchange [y v] by (y position)\nset [scrollx v] to ((0) - (x))\nset [scrolly v] to ((0) - (y))\nif <x limits?> then\n    if <(scrollx) < ((0) - ((min x) * (480)))> then\n        if <(scrollx) > ((0) - ((max x) * (480)))> then\n            set x to (0)\n        else\n            set [scrollx v] to ((0) - ((max x) * (480)))\n            set [x v] to (((480) * (max x)) + (x position))\n        end\n    else\n        set [scrollx v] to ((0) - ((min x) * (480)))\n        set [x v] to (((min x) * (480)) + (x position))\n    end\nelse\n    set x to (0)\nend\nif <y limits?> then\n    if <(scrolly) < ((0) - ((min y) * (360)))> then\n        if <(scrolly) > ((0) - ((max y) * (360)))> then\n            set y to (0)\n        else\n            set [scrolly v] to ((0) - ((max y) * (360)))\n            set [y v] to (((max y) * (360)) + (y position))\n        end\n    else\n        set [scrolly v] to ((0) - ((min y) * (360)))\n        set [y v] to (((min y) * (360)) + (y position))\n    end\nelse\n    set y to (0)\nend\n\ndefine gravity\nif <<(action-jump) = [1]> or <(yvel) < [4]>> then\n    change [yvel v] by (-1)\nelse\n    change [yvel v] by (-3)\nend\nif <(yvel) > [0]> then\n    set [up v] to [1]\nelse\n    set [up v] to [0]\nend\nif <(yvel) < [-1]> then\n    set [down v] to [1]\nelse\n    set [down v] to [0]\nend\nif <<(up) = [0]> and <(down) = [0]>> then\n    if <(jumped) = [0]> then\n        set [ground v] to [1]\n    end\nelse\n    set [ground v] to [0]\nend\nif <(ground) = [0]> then\n    set [jumped v] to [1]\nend\n\ndefine reset\ngo to x: (0) y: (0)\npoint in direction (90)\nset [jumped v] to [1]\nset [yvel v] to [0]\nset [xvel v] to [0]\nset [x v] to [0]\nset [y v] to [0]\nset [min_x v] to [0]\nset [max_x v] to [1]\nset [min_y v] to [0]\nset [max_y v] to [1]\nset [x_limits v] to [true]\nset [y_limits v] to [true]\nset [scrollx v] to ((0) - (x))\nset [scrolly v] to ((0) - (y))\nscroll (min_x) (max_x) (min_y) (max_y) <(x_limits) = [true]> <(y_limits) = [true]>\n\ndefine slopes\ncheck for collision\nrepeat until <<(collide) = [1]> or <(slopeheight) = [9]>>\n    change y by (-1)\n    change [slopeheight v] by (1)\n    check for collision\nend\nif <<(slopeheight) = [9]> or <(yvel) < [-1]>> then\n    set [slope v] to [0]\n    change y by (slopeheight)\nelse\n    set [slope v] to [1]\nend\n\n@ground\n\nwhen flag clicked\nshow\nforever\n    broadcast (clear v)\n    render (0) (0) (1)\n    render (1) (0) (1)\n    render (0) (1) (1)\n    render (1) (1) (1)\n    broadcast (update v)\nend\n\nwhen I receive [clear v]\ndelete this clone\n\ndefine render (x) (y) (level)\nswitch costume to (join (join (x) (y)) (join [-] (level)))\nmove (able to move off screen) to ((scrollx) + ((480) * (x))) ((scrolly) + ((360) * (y)))\nif <<(x position) < [490]> and <<(x position) > [-490]> and <<(y position) < [370]> and <(y position) > [-370]>>>> then\n    create clone of (_myself_ v)\nend\n\ndefine move (able to move off screen) to (x) (y)\nset [temp v] to (costume [number v])\nswitch costume to (offscreen_rect v)\ngo to x: (x) y: (y)\nswitch costume to (temp)\n\n@thumb\n\nwhen flag clicked\nhide\n\n@ball\n\nwhen I receive [clear v]\ndelete this clone\n\nwhen flag clicked\nshow\nset [x v] to [455]\nset [y v] to [455]\n\nwhen flag clicked\nset [count v] to [0]\nforever\n    change [x v] by ([sin v] of (count) )\n    change [count v] by (1)\nend\n\ndefine None\nset [temp v] to (costume [number v])\nswitch costume to (offscreen_rect v)\ngo to x: (x) y: (y)\nswitch costume to (temp)\n\nwhen I receive [update v]\nmove (able to move off screen) to ((scrollx) + (x)) ((scrolly) + (y))\nif <<(x position) < [490]> and <<(x position) > [-490]> and <<(y position) < [370]> and <(y position) > [-370]>>>> then\n    create clone of (_myself_ v)\nend\n\n@death\n\nwhen flag clicked\nshow\nforever\n    render (1) (0) (1)\nend\n\nwhen I receive [clear v]\ndelete this clone\n\ndefine None\nswitch costume to (join (join (x) (y)) (join [-] (level)))\nmove (able to move off screen) to ((scrollx) + ((480) * (x))) ((scrolly) + ((360) * (y)))\nif <<(x position) < [490]> and <<(x position) > [-490]> and <<(y position) < [370]> and <(y position) > [-370]>>>> then\n    create clone of (_myself_ v)\nend\n\ndefine None\nset [temp v] to (costume [number v])\nswitch costume to (offscreen_rect v)\ngo to x: (x) y: (y)\nswitch costume to (temp)\n\n