Slope detection platformer engine

Instructions: Try this on turbowarp: https://turbowarp.org/123747757?fps=60\nUse arrow keys, hold down to slide on slopes\nUse this for your projects if you like, but please give credit.

@Stage\n\n@Player\n\nwhen flag clicked\ngo to [front v] layer\nset [lasttime v] to (timer)\nset [yvel v] to [0]\nset [xvel v] to [0]\nset [cam v] to [0]\nset [player_width v] to [20]\npoint in direction (90)\ngo to x: (0) y: (0)\nset rotation style [all around v]\nforever\n    if <((timer) - (lastTime)) < [0.0001]> then\n        wait (0.0001) seconds\n    end\n    set [deltatime v] to (((timer) - (lastTime)) * (30))\n    set [lasttime v] to (timer)\n    set [control::xmove v] to (<key (right arrow v) pressed?> - <key (left arrow v) pressed?>)\n    set [control::jump v] to <key (up arrow v) pressed?>\n    set [control::slide v] to <key (down arrow v) pressed?>\n    if <mouse down?> then\n        if <(mouse x) > [40]> then\n            change [control::xmove v] by (((mouse x) - (40)) / (40))\n        else\n            if <(mouse x) < [-40]> then\n                change [control::xmove v] by (((mouse x) + (40)) / (40))\n            end\n        end\n        if <(mouse y) > [20]> then\n            set [control::jump v] to [true]\n        else\n            if <<(mouse y) < [-120]> and <([abs v] of (mouse x) ) < [80]>> then\n                set [control::slide v] to [true]\n            end\n        end\n    end\n    inputMove\n    set rotation style [don't rotate v]\n    switch costume to (sidesense v)\n    set [ssd v] to ((PLAYER_WIDTH) - (2))\n    set [oldx v] to (x position)\n    set [oldy v] to (y position)\n    set [downtest v] to [false]\n    set x to ((oldX) - (((PLAYER_WIDTH) / (2)) - (2)))\n    sideSense [1]\n    set x to ((oldX) + ((PLAYER_WIDTH) / (2)))\n    sideSense [2]\n    set x to (oldX)\n    set rotation style [all around v]\n    senseMove\n    costume\n    camera\nend\n\ndefine sideSense (s)\nif <(s) = [1]> then\n    set [1wall v] to [0]\nelse\n    set [2wall v] to [0]\nend\nset [i v] to [0]\nset [j v] to [0]\nset [ddt v] to [0]\nrepeat until <<(j) > [0]> or <(i) > ((PLAYER_WIDTH) - (2))>>\n    if <touching (level v)?> then\n        set [ddt v] to [1]\n        repeat until <<(j) > [15]> or <not <touching (level v)?>>>\n            change [j v] by (1)\n            change y by (1)\n        end\n    else\n        repeat until <<(j) > [7]> or <touching (level v)?>>\n            change [j v] by (1)\n            change y by (-1)\n        end\n        if <touching (level v)?> then\n            if <(j) = [1]> then\n                set [ddt v] to [1]\n            end\n            change y by (1)\n        end\n    end\n    if <<(j) > [15]> or <<(j) > [7]> and <(ddt) = [0]>>> then\n        set [j v] to [0]\n        change [i v] by (1)\n        if <(ddt) = [1]> then\n            set [xvel v] to [0]\n            if <(s) = [1]> then\n                set [1wall v] to [1]\n            else\n                set [2wall v] to [1]\n            end\n        end\n        if <(s) = [2]> then\n            change x by (-1)\n            if <(ddt) = [1]> then\n                change [oldx v] by (-1)\n            end\n            change [ssd v] by (-1)\n        else\n            change x by (1)\n            if <(ddt) = [1]> then\n                change [oldx v] by (1)\n            end\n        end\n        set y to (oldY)\n        set [ddt v] to [0]\n    end\nend\nif <(s) = [1]> then\n    set [y1 v] to (round (y position))\nelse\n    set [y2 v] to (round (y position))\nend\nif <(ddt) = [1]> then\n    set [downtest v] to [true]\nend\nset y to (oldY)\n\ndefine costume\nswitch costume to (forward v)\nif <(control::slide) = [true]> then\n    if <(xVel) > [0]> then\n        switch costume to (right v)\n    else\n        if <(xVel) < [0]> then\n            switch costume to (left v)\n        end\n    end\nelse\n    if <(control::xMove) > [0]> then\n        switch costume to (right v)\n    else\n        if <(control::xMove) < [0]> then\n            switch costume to (left v)\n        end\n    end\nend\n\ndefine upSense\nswitch costume to (upsense v)\nif <<touching (level v)?> and <(downTest) = [false]>> then\n    set [yvel v] to [0]\n    set [i v] to [0]\n    repeat until <<not <touching (level v)?>> or <(i) > [50]>>\n        change [i v] by (1)\n        change y by (-1)\n    end\n    if <touching (level v)?> then\n        change y by (50)\n        repeat until <<not <touching (level v)?>> or <(i) < [1]>>\n            change [i v] by (-1)\n            change y by (1)\n        end\n    end\nend\n\ndefine camera\nif <([abs v] of (x position) ) > [60]> then\n    if <(x position) > [0]> then\n        change [cam v] by ((-1) * ((x position) - (60)))\n        set x to (60)\n    else\n        change [cam v] by ((-1) * ((x position) + (60)))\n        set x to (-60)\n    end\n    set [cam v] to ((round (cam)) mod (960))\nend\n\ndefine inputMove\nif <(downTest) = [true]> then\n    if <(control::slide) = [true]> then\n        if <([abs v] of ([cos v] of (direction) ) ) > [.18]> then\n            change [xvel v] by ((([cos v] of (direction) ) * (-2.5)) * (deltatime))\n            if <([cos v] of (direction) ) < [0]> then\n                change [xvel v] by ((-.1) * (deltatime))\n            else\n                change [xvel v] by ((.1) * (deltatime))\n            end\n        end\n        set [xvel v] to ((xVel) * ([e ^ v] of (([ln v] of (.92) ) * (deltatime)) ))\n    else\n        if <([abs v] of ([cos v] of (direction) ) ) > [0.55]> then\n            change [xvel v] by ((([cos v] of (direction) ) * (-5.9)) * (deltatime))\n        end\n        set [xvel v] to ((xVel) * ([e ^ v] of (([ln v] of (.6) ) * (deltatime)) ))\n    end\n    if <(control::jump) = [true]> then\n        change [xvel v] by (([sin v] of ((direction) - (90)) ) * (12))\n        change [yvel v] by (([cos v] of ((direction) - (90)) ) * (12))\n    end\nelse\n    set [yvel v] to (((yVel) * ([e ^ v] of (([ln v] of (.98) ) * (deltatime)) )) - ((1) * (deltatime)))\n    set [xvel v] to ((xVel) * ([e ^ v] of (([ln v] of (.7) ) * (deltatime)) ))\nend\nif <(control::slide) = [false]> then\n    if <<<(control::xMove) < [0]> and <(1wall) = [0]>> or <<(control::xMove) > [0]> and <(2wall) = [0]>>> then\n        if <not <(control::xMove) < [1]>> then\n            change [xvel v] by ((2.5) * (deltatime))\n        else\n            if <not <(control::xMove) > [-1]>> then\n                change [xvel v] by ((-2.5) * (deltatime))\n            else\n                change [xvel v] by (((control::xMove) * (2.5)) * (deltatime))\n            end\n        end\n    end\nend\nchange y by ((([cos v] of (direction) ) * (xVel)) * (deltatime))\nchange y by ((yVel) * (deltatime))\nupSense\nchange x by ((([sin v] of (direction) ) * (xVel)) * (deltatime))\n\ndefine senseMove\nif <(downTest) = [true]> then\n    set [yvel v] to [0]\n    set y to (((y1) + (y2)) / (2))\n    if <(y1) = (y2)> then\n        point in direction (90)\n    else\n        point in direction ([atan v] of ((ssd) / ((y2) - (y1))) )\n        if <(y1) > (y2)> then\n            turn right (180) degrees\n        end\n    end\nelse\n    if <((direction) - (90)) > [-180]> then\n        turn left (((direction) - (90)) / (5)) degrees\n    else\n        turn left (((direction) + (360)) / (5)) degrees\n    end\nend\n\n@Level\n\nwhen flag clicked\nhide\nswitch costume to (move v)\nnext costume\nrepeat until <(costume [number v]) = [1]>\n    set [i v] to (costume [number v])\n    create clone of (_myself_ v)\n    next costume\nend\n\nwhen I start as a clone\nshow\nif <(i) = [2]> then\n    forever\n        switch costume to (move v)\n        go to x: (cam) y: (0)\n        if <(cam) > ((cam) mod (480))> then\n            go to x: (((cam) mod (960)) - (960)) y: (0)\n        end\n        switch costume to (i)\n    end\nelse\n    forever\n        switch costume to (move v)\n        go to x: ((cam) - (480)) y: (0)\n        switch costume to (i)\n    end\nend\n\n