Scrolling Platformer engine/tutorial UPDATED
@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]\nhide\ngo to [front v] layer\ngo [backward v] (1) layers\n\ndefine prepare\nset [cam x v] to [-100]\nset [cam y v] to [150]\nset [player status v] to []\nset [xpos v] to [-100]\nset [ypos v] to [150]\nset [x velocity v] to [0]\nset [frame script? v] to [0]\nset [y velocity v] to [0]\nset [falling v] to [0]\nclear graphic effects\ngo to [front v] layer\nset size to (100) %\nshow\nset rotation style [left-right v]\npoint in direction (90)\n\ndefine Tick <right> <left> <jump>\nRead keys y velocity: [16] <jump> <left> <right>\nMomentum limit [1.3]\nMove x: ((x velocity) * (7)) y: (y velocity)\nGravity [-1.7]\nScroll change ((xpos) - (CAM X)) ((ypos) - (CAM Y)) [10] [0] [-20]\nDanger test\nposition\nAnimate <jump> <<right> and <not <jump>>> <<left> and <not <jump>>>\n\ndefine restart\nset [player status 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\nwhen I receive [begin! v]\nforever\n    broadcast (reset v) and wait\n    broadcast (setup v) and wait\n    prepare\n    repeat until <not <(PLAYER STATUS) = []>>\n        broadcast (tick v) and wait\n    end\n    restart\nend\n\ndefine position\ngo to x: ((xpos) - (CAM X)) y: (((ypos) - (CAM Y)) - (0))\n\ndefine Change X vel. by (xvel.)\npoint in direction ((([abs v] of (xvel.) ) / (xvel.)) * (90))\nchange [x velocity v] by (xvel.)\nif <(Frame) = [off]> then\n    set [frame v] to [on]\nend\nif <(Frame) = [on]> then\n    set [frame v] to [after]\nend\n\nwhen I receive [frame it v]\nset [frame script? v] to [1]\nif <(Frame) = [8]> then\n    set [frame v] to [1]\nelse\n    change [frame v] by (1)\nend\nwait (0.035) seconds\nset [frame script? v] to [0]\n\ndefine Animate <jump> <left> <right>\nif <<<left> or <right>> and <<not <(Frame) = [15]>> and <not <jump>>>> then\n    if <(Frame script?) = [0]> then\n        broadcast (frame it v)\n    end\nelse\n    set [frame v] to [1]\nend\nif <(falling) < [4]> then\n    set [jump? v] to [0]\nelse\n    set [jump? v] to [1]\nend\nif <(jump?) = [0]> then\n    switch costume to (join [walk] (Frame))\nelse\n    if <(y velocity) > [0]> then\n        switch costume to (jump v)\n    else\n        switch costume to (walk1 v)\n    end\nend\nif <touching (exit point v)?> then\n    set [player status v] to [win]\nend\n\ndefine Momentum limit (limit)\nif <(x velocity) > (limit)> then\n    set [x velocity v] to (limit)\nend\nif <(x velocity) < ((limit) * (-1))> then\n    set [x velocity v] to ((limit) * (-1))\nend\n\ndefine Scroll change (x input) (y input) (delay) (maximun x scroll) (maximun y scroll)\nchange [cam x v] by (round ((x input) / (delay)))\nchange [cam y v] by (round ((y input) / (delay)))\nif <(CAM Y) < (maximun y scroll)> then\n    set [cam y v] to (maximun y scroll)\nend\nif <(CAM X) < (maximun x scroll)> then\n    set [cam x v] to (maximun x scroll)\nend\n\ndefine Danger test\nif <(y position) < [-184]> then\n    set [player status v] to [die]\nend\n\ndefine Gravity (gravity)\nchange [y velocity v] by (gravity)\n\ndefine Move x: (x) y: (y)\nchange [xpos v] by (x)\nposition\nif <touching (platforms v)?> then\n    repeat (10)\n        change [ypos v] by (1)\n        change [xpos v] by ((direction) / (90))\n        position\n        if <not <touching (platforms v)?>> then\n            stop [this script v]\n        end\n    end\n    change [ypos v] by (-10)\n    repeat until <not <touching (platforms v)?>>\n        if <(x) > [0]> then\n            change [xpos v] by (-1)\n        else\n            change [xpos v] by (((x velocity) / (5)) * (-1))\n        end\n        position\n    end\nend\nchange [x velocity v] by (() - ((x velocity) / (3)))\nchange [ypos v] by (y)\nchange [falling v] by (1)\nposition\nif <touching (platforms v)?> then\n    repeat until <not <touching (platforms v)?>>\n        if <(y) > [0]> then\n            change [ypos v] by (-1)\n        else\n            change [ypos v] by (1)\n            set [falling v] to [0]\n        end\n        set [y velocity v] to [0]\n        position\n    end\nend\nposition\n\ndefine Read keys y velocity: (yv) <jump?> <left?> <right?>\nswitch costume to (hitbox v)\nif <right?> then\n    Change X vel. by [0.6]\nelse\n    if <left?> then\n        Change X vel. by [-0.6]\n    else\n        set [frame v] to [off]\n    end\nend\nif <<(falling) < [4]> and <jump?>> then\n    set [y velocity v] to (yv)\nend\n\nwhen I receive [tick v]\nTick <<<key (d v) pressed?> or <key (right arrow v) pressed?>> or <<mouse down?> and <(mouse x) > [10]>>> <<<key (a v) pressed?> or <key (left arrow v) pressed?>> or <<mouse down?> and <(mouse x) < [-10]>>> <<<key (w v) pressed?> or <key (up arrow v) pressed?>> or <<mouse down?> and <(mouse y) > (y position)>>>\n\nwait until \n\n@platforms\n\nwhen I receive [tick v]\nset [brightness v] effect to ((0) - ([abs v] of (((letter (length of (current [second v])) of (current [second v])) / (1)) * (5)) ))\nposition ((x) - (CAM X)) ((y) - (CAM 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\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]\ngo to [back v] layer\ngo [forward v] (1) layers\nclear graphic effects\nhide\ndelete this clone\n\nwhen I receive [setup v]\nset [x v] to [0]\nset [y v] to [0]\nswitch costume to (1 v)\nclone at x: [1975] y: [2]\n\ngo to x: (0) y: (0)\n\nwhen I receive [green flag v]\nswitch costume to (1 v)\n\n@thumbnail\n\nwhen flag clicked\nhide\n\n
TERA TRANCE (scrolling platformer) RESHARED!!! https://scratch.mit.edu/projects/399452232/\nThis is my new version of my last engine! It also includes animation. This one is supposed to be simpler and easier to understand and change things. However it's still from @griffpatch a bit. This one is just an update of the player and is 90% by me.\n\nTHIS IS ALSO FOR TERA TRANCE!!!