Scrolling platformer engine/tutorial
@Stage\n\n@player\n\nwhen flag clicked\nbroadcast (green flag v) and wait\nbroadcast (begin! v) and wait\n\nwhen I receive [green flag v]\nset [latest checkpoint x v] to [0]\nset [latest checkpoint y v] to [0]\nhide\ngo to [front v] layer\ngo [backward v] (1) layers\n\ndefine prepare\nset [scroll x v] to (latest checkpoint x)\nset [scroll y v] to (latest checkpoint y)\nset [lives v] to [3]\nset [exit v] to []\nset [x v] to [0]\nset [y v] to [0]\nset [invincible? v] to [off]\nset [xspeed v] to [0]\nset [yspeed v] to [0]\nset [falling v] to [0]\nset rotation style [left-right v]\npoint in direction (90)\nswitch costume to (sky v)\nclear graphic effects\nset size to (45) %\nshow\n\ndefine Tick\nif <<<key (d v) pressed?> or <key (right arrow v) pressed?>> or <<mouse down?> and <(mouse x) > [10]>>> then\n    change [xspeed v] by (0.6)\nelse\n    if <<<key (a v) pressed?> or <key (left arrow v) pressed?>> or <<mouse down?> and <(mouse x) < [-10]>>> then\n        change [xspeed v] by (-0.6)\n    end\nend\nif <(xspeed) > [1.3]> then\n    set [xspeed v] to [1.3]\nend\nif <(xspeed) < [-1.3]> then\n    set [xspeed v] to [-1.3]\nend\nif <not <(xspeed) = [0]>> then\n    change x by ((xspeed) * (7))\nend\nif <<<key (w v) pressed?> or <key (up arrow v) pressed?>> or <<mouse down?> and <(mouse y) > (y position)>>> then\n    if <(falling) < [4]> then\n        set [yspeed v] to [16]\n    end\nend\nchange [yspeed v] by (-1.7)\nchange y by (yspeed)\ntest die\nif <(SCROLL X) < [0]> then\n    set [scroll x v] to [0]\nend\nif <(SCROLL Y) < [0]> then\n    set [scroll y v] to [0]\nend\nchange [scroll x v] by (round (((x) - (SCROLL X)) / (10)))\nchange [scroll y v] by (round (((y) - (SCROLL Y)) / (5)))\nposition\nif <(y position) < [-190]> then\n    set [exit v] to [die]\nend\nif <<touching (enemy v)?> or <touching (enemy2 v)?>> then\n    set [exit v] to [hurt]\nend\nif <<(EXIT) = [hurt]> and <(invincible?) = [off]>> then\n    broadcast (hurt v)\nend\n\ndefine change y by (y)\nchange [y v] by (y)\nchange [falling v] by (1)\nposition\nrepeat until <not <touching (platforms v)?>>\n    if <(y) > [0]> then\n        change [y v] by (-1)\n    else\n        change [y v] by (1)\n        set [falling v] to [0]\n    end\n    position\n    set [yspeed v] to [0]\nend\n\ndefine change x by (x)\nif <(x) > [0]> then\n    point in direction (90)\nelse\n    point in direction (-90)\nend\nchange [x v] by (x)\nposition\nif <touching (platforms v)?> then\n    repeat (10)\n        change [y v] by (1)\n        position\n        if <not <touching (platforms v)?>> then\n            stop [this script v]\n        end\n    end\n    change [y v] by (-10)\n    repeat until <not <touching (platforms v)?>>\n        if <(x) > [0]> then\n            change [x v] by (-1)\n        else\n            change [x v] by (1)\n        end\n        position\n    end\nend\nchange [xspeed v] by (((xspeed) / (5)) * (-1))\n\ndefine lose\nset [exit v] to []\nrepeat (5)\n    set [ghost v] effect to (100)\n    wait (0.1) seconds\n    clear graphic effects\n    wait (0.1) seconds\nend\nhide\nwait (0.5) seconds\n\ndefine test die\nif <touching (danger v)?> then\n    set [exit v] to [die]\nend\n\ndefine win\nset [scroll x v] to [0]\nset [scroll y v] to [0]\nchange [level v] by (1)\nhide\n\nwhen I receive [begin! v]\nset [level v] to [1]\nforever\n    broadcast (reset v) and wait\n    broadcast (setup v) and wait\n    prepare\n    set [yspeed v] to [0]\n    repeat until <<(EXIT) = [win]> or <(EXIT) = [die]>>\n        Tick\n        broadcast (tick v) and wait\n    end\n    if <(EXIT) = [win]> then\n        win\n    else\n        lose\n    end\nend\n\ndefine position\ngo to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\n\nwhen I receive [hurt v]\nif <(SCROLL X) > [0]> then\n    set [invincible? v] to [on]\n    wait until <(distance to [platforms v]) < [700]>\n    set [color v] effect to (84)\n    set [yspeed v] to [10]\n    repeat (20)\n        change [x v] by (((direction) / (90)) * (-8))\n    end\n    change [lives v] by (-1)\n    wait (0.2) seconds\n    clear graphic effects\n    set [exit v] to []\n    set [invincible? v] to [off]\nend\nif <(LIVES) = [0]> then\n    set [exit v] to [die]\nend\n\n\n\nwhen I receive [false v]\nchange [x v] by (10)\n\nbroadcast (setup v)\n\n@platforms\n\nwhen I receive [tick v]\nposition ((x) - (SCROLL X)) ((y) - (SCROLL Y))\n\ndefine position (x) (y)\ngo to x: (x) y: (y)\nif <<(x) = (x position)> and <(y) = (y position)>> then\n    show\nelse\n    hide\nend\n\nset x to ((x position) + (5))\n\ndefine clone at x: (x) y: (y)\ncreate clone of (_myself_ v)\nchange [x v] by (x)\nchange [y v] by (y)\nnext costume\n\nwhen I receive [reset v]\nset [x v] to [0]\nset [y v] to [0]\ngo to [back v] layer\ngo [forward v] (1) layers\nclear graphic effects\nhide\ndelete this clone\n\nwhen I receive [setup v]\nif <(LEVEL) = [1]> then\n    switch costume to (1 v)\n    clone at x: [479] y: [-1]\n    clone at x: [0] y: [360]\n    clone at x: [479] y: [-360]\n    clone at x: [0] y: [360]\n    clone at x: [-480] y: [360]\n    clone at x: [950] y: [-721]\n    clone at x: [0] y: [205]\n    clone at x: [0] y: [360]\n    clone at x: [480] y: [0]\n    clone at x: [0] y: [-360]\n    clone at x: [-2] y: [-206]\n    clone at x: [0] y: [925]\n    clone at x: [480] y: [-360]\nend\n\nclone at x: [480] y: [0]\nclone at x: [0] y: [360]\n\nwhen I start as a clone\nshow\n\n@border\n\nwhen I receive [green flag v]\nhide\nset size to (100) %\ngo to [front v] layer\n\nwhen I receive [setup v]\nshow\ngo to x: (0) y: (0)\n\n@thumbnail\n\nwhen I receive [tick v]\nshow\ngo to [front v] layer\nset [ghost v] effect to (100)\ngo to x: (0) y: (0)\n\n
-----UPDATED FOR SCRATCH 3.0- PLEASE READ----\n--------------------------------CONTAINS--------------------------\nMy added features-\n-Momentum script \n-Mobile controls\nMy edited features-\n-Platform cloning\n-Player deaths \nParts not by me-\n-Wall detection (horizontal+vertical)\n-Scroll \n------------------------KNOWN GLITCHES----------------------\n-If you play the whole thing there is a chance that when you run into a wall it will glitch. This is simply because the walls are not straight at all. So- if you use this just make those walls straight and sturdy