Scrolling Platformer Engine (UPDATED)
@Stage\n\n@Sprite1\n\ndefine physics | controls on? <controls?> | speed: (speed) | friction: (friction) | jump height: (height) | gravity: (gravity)\nchange y by (-5)\nif <<controls?> and <key (right arrow v) pressed?>> then\n    change [x vel v] by ((speed) * (-1))\nend\nif <<controls?> and <key (left arrow v) pressed?>> then\n    change [x vel v] by (speed)\nend\nchange y by (y vel)\nif <touching (ground v)?> then\n    repeat ([abs v] of (y vel) )\n        if <touching (ground v)?> then\n            change y by ((-1) * (([abs v] of (y vel) ) / (y vel)))\n        end\n    end\n    if <<controls?> and <<<key (space v) pressed?> or <key (up arrow v) pressed?>> and <not <[0] > (y vel)>>>> then\n        set [jumping? v] to [1]\n        set [y vel v] to ((-1) * (height))\n    else\n        set [y vel v] to [0]\n        set [jumping? v] to [0]\n    end\nelse\n    change [y vel v] by (gravity)\nend\nchange x by (x vel)\nif <touching (ground v)?> then\n    set [old y v] to (y position)\n    repeat (([abs v] of (x vel) ) + (1))\n        if <touching (ground v)?> then\n            change y by (-1)\n        end\n    end\n    if <touching (ground v)?> then\n        set y to (old y)\n        repeat ([ceiling v] of ([abs v] of (x vel) ) )\n            if <touching (ground v)?> then\n                change x by ((-1) * (([abs v] of (x vel) ) / (x vel)))\n            end\n        end\n    end\nend\nset [x vel v] to ((x vel) * (friction))\nchange y by (5)\n\nwhen flag clicked\nswitch costume to (costume1 v)\nset size to (500) %\nswitch costume to (costume2 v)\nset [x vel v] to [0]\nset [y vel v] to [0]\ndie\nforever\n    physics | controls on? <[true] = [true]> | speed: [2] | friction: [0.8] | jump height: [10] | gravity: [1]\nend\n\nif <<key (up arrow v) pressed?> and <controls?>> then\n    set [y vel v] to ((-1) * (height))\n    set [jumping? v] to [1]\n    set [x vel v] to ((([abs v] of (x vel) ) / (x vel)) * (-20))\nelse\n    set [x vel v] to [0]\nend\n\ndefine die\ngo to x: (0) y: (-40)\n\nwhen [r v] key pressed\ndie\n\n@Ground\n\nwhen flag clicked\ngo to x: (0) y: (0)\n\n@Sprite2\n\nwhen flag clicked\nhide\n\nwhen [p v] key pressed\ngo to x: (0) y: (0)\nshow\n\n