Griffpatch's Scrolling Platformer Engine +

Instructions: Play My New Game: s/place https://scratch.mit.edu/projects/670363874/\n\nGRIFFPATCH'S SCROLLING PLATFORMER ENGINE\n___________________+_______________________\nYou can go into the code and change stuff to your liking. Change animations with the animation options, Change the physics with the gameplay options and change the levels, and coins and exit portal with the clone scripts and costumes. 

@Stage\n\nwhen [space v] key pressed\nset [mouse x,y v] to (join ((mouse x) + (SCROLL X)) (join [,] ((mouse y) + (SCROLL Y))))\n\nwhen flag clicked\ndelete all of [layers v]\nadd [Thumbnail] to [layers v]\nadd [Player] to [layers v]\nadd [Platforms] to [layers v]\nadd [Danger Area] to [layers v]\nadd [Collectables] to [layers v]\nadd [Exit] to [layers v]\nbroadcast (Green Flag v) and wait\nbroadcast (Play Game v) and wait\n\n@Thumbnail\n\nwhen flag clicked\nshow\nset [ghost v] effect to (100)\nforever\n    go to [front v] layer\nend\n\n@Player\n\ndefine Animate\nif <<key (right arrow v) pressed?> or <<<key (d v) pressed?> or <key (left arrow v) pressed?>> or <key (a v) pressed?>>> then\n    if <(frame) < (item (5) of [animation options v])> then\n        set [frame v] to (item (5) of [animation options v])\n    end\n    change [frame v] by (item (7) of [animation options v])\n    if <(frame) > (item (6) of [animation options v])> then\n        set [frame v] to (item (5) of [animation options v])\n    end\nend\nif <<not <<key (left arrow v) pressed?> or <<key (right arrow v) pressed?> or <<key (a v) pressed?> or <key (d v) pressed?>>>>> or <<<<key (left arrow v) pressed?> and <key (right arrow v) pressed?>> or <<key (a v) pressed?> and <key (d v) pressed?>>> or <<<key (left arrow v) pressed?> and <key (d v) pressed?>> or <<key (a v) pressed?> and <key (right arrow v) pressed?>>>>> then\n    if <(frame) < (item (2) of [animation options v])> then\n        set [frame v] to (item (2) of [animation options v])\n    end\n    change [frame v] by (item (4) of [animation options v])\n    if <(frame) > (item (3) of [animation options v])> then\n        set [frame v] to (item (2) of [animation options v])\n    end\nend\nif <<(sy) > [1]> and <(in air) > [1]>> then\n    if <(frame) < (item (8) of [animation options v])> then\n        set [frame v] to (item (8) of [animation options v])\n    end\n    change [frame v] by (item (10) of [animation options v])\n    if <(frame) > (item (9) of [animation options v])> then\n        set [frame v] to (item (8) of [animation options v])\n    end\nend\nif <<(sy) < [3]> and <(in air) > [3]>> then\n    if <(frame) < (item (11) of [animation options v])> then\n        set [frame v] to (item (11) of [animation options v])\n    end\n    change [frame v] by (item (13) of [animation options v])\n    if <(frame) > (item (12) of [animation options v])> then\n        set [frame v] to (item (11) of [animation options v])\n    end\nend\nswitch costume to (frame)\n\nwhen I receive [green flag v]\nSet Animation Options\nLayer (item # of [Player] in [layers v])\nhide\ngo to [front v] layer\n\nwhen I receive [play game v]\nset [level v] to [1]\nforever\n    broadcast (Reset v) and wait\n    broadcast (Setup v) and wait\n    Game On\n    repeat until <(EXIT) > []>\n        Tick\n        broadcast (Tick v) and wait\n    end\n    if <(EXIT) = [Win]> then\n        Game - Win\n    end\n    if <(EXIT) = [Death]> then\n        Game - Die\n    end\nend\n\ndefine Game On\nset [x v] to [0]\nset [y v] to [0]\nset [scroll x v] to [0]\nset [scroll y v] to [0]\nset [sx v] to [0]\nset [sy v] to [0]\nset [in air v] to [0]\nset [exit v] to []\nset [zoom v] to [100]\nSet Gameplay Options\nset rotation style [left-right v]\npoint in direction (90)\nset size to (100) %\nclear graphic effects\nshow\n\ndefine Tick\nswitch costume to (item (1) of [animation options v])\nif <<key (left arrow v) pressed?> or <key (a v) pressed?>> then\n    point in direction (90)\n    if <(acceleration) = [0]> then\n        set [sx v] to ((max speed) * (-1))\n    else\n        change [sx v] by ((acceleration) * (-1))\n    end\nend\nif <<key (right arrow v) pressed?> or <key (d v) pressed?>> then\n    point in direction (-90)\n    if <(acceleration) = [0]> then\n        set [sx v] to (max speed)\n    else\n        change [sx v] by (acceleration)\n    end\nend\nif <<key (up arrow v) pressed?> or <key (w v) pressed?>> then\n    if <(in air) < [4]> then\n        set [sy v] to (jump height)\n    end\nend\nchange [sy v] by (gravity)\nFriction\nif <(sx) > (max speed)> then\n    set [sx v] to (max speed)\nend\nif <(sx) < ((max speed) * (-1))> then\n    set [sx v] to ((max speed) * (-1))\nend\nif <(sy) < (max fall speed)> then\n    set [sy v] to (max fall speed)\nend\nChange Player X By (sx)\nChange Player Y By (sy)\nPosition\nExit Check\nchange [scroll x v] by (round (((x) - (SCROLL X)) / (scrolling smoothness)))\nchange [scroll y v] by (round (((y) - (SCROLL Y)) / (scrolling smoothness)))\nCamera Lock\nPosition\nExit Check\nAnimate\n\ndefine Change Player Y By (sy)\nchange [y v] by (sy)\nchange [in air v] by (1)\nPosition\nrepeat until <not <touching (platforms v)?>>\n    if <(sy) > [0]> then\n        change [y v] by (-1)\n    else\n        change [y v] by (1)\n        set [in air v] to [0]\n    end\n    Position\n    set [sy v] to [0]\nend\n\ndefine Position\ngo to x: (((x) - (SCROLL X)) * ((ZOOM) / (100))) y: (((y) - (SCROLL Y)) * ((ZOOM) / (100)))\nif <<(((x) - (SCROLL X)) * ((ZOOM) / (100))) = (x position)> and <(((y) - (SCROLL Y)) * ((ZOOM) / (100))) = (y position)>> then\n    show\nelse\n    hide\nend\nset size to (ZOOM) %\n\ndefine Change Player X By (sx)\nchange [x v] by (sx)\nPosition\nExit Check\nif <touching (platforms v)?> then\n    repeat (9)\n        change [y v] by (1)\n        Position\n        Exit Check\n        if <not <touching (platforms v)?>> then\n            stop [this script v]\n        end\n    end\n    change [y v] by (-8)\n    repeat until <not <touching (platforms v)?>>\n        if <(sx) > [0]> then\n            change [x v] by (-1)\n        else\n            change [x v] by (1)\n        end\n        set [sx v] to [0]\n        Position\n    end\nend\n\ndefine Game - Die\nset [exit v] to []\nrepeat (5)\n    hide\n    wait (0.1) seconds\n    show\n    wait (0.1) seconds\nend\nhide\nwait (1) seconds\n\ndefine Exit Check\nif <(y) < [-180]> then\n    set [exit v] to [Death]\nend\nif <touching (danger area v)?> then\n    set [exit v] to [Death]\nend\nif <touching (exit v)?> then\n    set [exit v] to [Win]\nend\n\ndefine Game - Win\nswitch costume to (idle 1 v)\nset rotation style [all around v]\nrepeat (75)\n    point towards (exit v)\n    turn right (65) degrees\n    move ((distance to [exit v]) / (2.5)) steps\n    change size by (-0.8)\n    change [ghost v] effect by (2.5)\nend\nchange [level v] by (1)\nhide\nwait (1) seconds\n\ndefine Set Animation Options\ndelete all of [animation options v]\nadd [1] to [animation options v]\nadd [2] to [animation options v]\nadd [2] to [animation options v]\nadd [0.25] to [animation options v]\nadd [3] to [animation options v]\nadd [3] to [animation options v]\nadd [0.25] to [animation options v]\nadd [4] to [animation options v]\nadd [4] to [animation options v]\nadd [0.25] to [animation options v]\nadd [5] to [animation options v]\nadd [5] to [animation options v]\nadd [0.25] to [animation options v]\n\ndefine Camera Lock X1 (left) : (x1) X2 (right) : (x2) Y1 (up) : (y1) Y2 (down) : (y2)\nif <(SCROLL X) < (x1)> then\n    set [scroll x v] to (x1)\nend\nif <(SCROLL X) > (x2)> then\n    set [scroll x v] to (x2)\nend\nif <(SCROLL Y) > (y1)> then\n    set [scroll y v] to (y1)\nend\nif <(SCROLL Y) < (y2)> then\n    set [scroll y v] to (y2)\nend\n\ndefine Camera Lock\nif <(LEVEL) = [1]> then\n    Camera Lock X1 (left) : [-10] X2 (right) : [970] Y1 (up) : [10] Y2 (down) : [-10]\nend\nif <(LEVEL) = [2]> then\n    Camera Lock X1 (left) : [-50] X2 (right) : [1150] Y1 (up) : [500] Y2 (down) : [-14]\nend\n\ndefine Set Gameplay Options\nset [friction v] to [4]\nset [acceleration v] to [11]\nset [max speed v] to [10]\nset [jump height v] to [17]\nset [max fall speed v] to [-20]\nset [scrolling smoothness v] to [5]\nset [gravity v] to [-2]\n\ndefine Friction\nif <(friction) = [0]> then\n    if <not <<<key (left arrow v) pressed?> or <key (a v) pressed?>> or <<key (right arrow v) pressed?> or <key (d v) pressed?>>>> then\n        set [sx v] to [0]\n    end\nelse\n    if <(sx) > [0]> then\n        change [sx v] by ((friction) * (-1))\n    end\n    if <(sx) < [0]> then\n        change [sx v] by (friction)\n    end\n    if <<(sx) > ((friction) * (-1))> and <(sx) < (friction)>> then\n        set [sx v] to [0]\n    end\nend\n\ndefine Layer (#)\ngo to [front v] layer\ngo [backward v] ((#) - (1)) layers\n\n@Platforms\n\nwhen I receive [green flag v]\nhide\nLayer (item # of [Platforms] in [layers v])\n\nwhen I receive [tick v]\nPosition X: (((x) - (SCROLL X)) * ((ZOOM) / (100))) Y: (((y) - (SCROLL Y)) * ((ZOOM) / (100)))\n\nwhen I receive [setup v]\nif <(LEVEL) = [1]> then\n    Level 1\nend\nif <(LEVEL) = [2]> then\n    Level 2\nend\nif <(LEVEL) = [3]> then\n    Level 3\nend\nset [y v] to [999999999]\n\ndefine Clone at Round X: (x) Y: (y) Level: (level) Tile: (tile)\nshow\nset [x v] to ((x) * (420))\nset [y v] to ((y) * (360))\nswitch costume to (join [level] (join [ ] (join (level) (join [ ] (tile)))))\ncreate clone of (_myself_ v)\nhide\n\ndefine Level 1\nClone at Round X: [0] Y: [0] Level: [1] Tile: [1]\nClone at Round X: [1] Y: [0] Level: [1] Tile: [2]\nClone at Round X: [2] Y: [0] Level: [1] Tile: [3]\n\ndefine Position X: (x) Y: (y)\ngo to x: (x) y: (y)\nif <<(x) = (x position)> and <(y) = (y position)>> then\n    show\nelse\n    hide\nend\nset size to (ZOOM) %\n\nwhen I receive [reset v]\ndelete this clone\n\ndefine Level 2\nClone at Round X: [0] Y: [0.3] Level: [2] Tile: [1]\nClone at Round X: [1] Y: [1] Level: [2] Tile: [2]\nClone at Round X: [2] Y: [1] Level: [2] Tile: [3]\nClone at Round X: [2.5] Y: [1] Level: [2] Tile: [4]\n\ndefine Level 3\nClone at Round X: [0] Y: [0] Level: [3] Tile: [1]\n\ndefine Layer (#)\ngo to [front v] layer\ngo [backward v] ((#) - (1)) layers\n\n@Danger Area\n\nwhen I receive [green flag v]\nhide\nLayer (item # of [Danger Area] in [layers v])\n\nwhen I receive [tick v]\nPosition X: (((x) - (SCROLL X)) * ((ZOOM) / (100))) Y: (((y) - (SCROLL Y)) * ((ZOOM) / (100)))\n\nwhen I receive [setup v]\nif <(LEVEL) = [1]> then\n    Level 1\nend\nif <(LEVEL) = [2]> then\n    Level 2\nend\nset [y v] to [999999999]\n\ndefine Clone at Round X: (x) Y: (y) Level: (level) Tile: (tile)\nshow\nset [x v] to ((x) * (420))\nset [y v] to ((y) * (360))\nswitch costume to (join [level] (join [ ] (join (level) (join [ ] (tile)))))\ncreate clone of (_myself_ v)\nhide\n\ndefine Level 1\nClone at Round X: [2] Y: [0] Level: [1] Tile: [3]\n\ndefine Position X: (x) Y: (y)\ngo to x: (x) y: (y)\nif <<(x) = (x position)> and <(y) = (y position)>> then\n    show\nelse\n    hide\nend\nset size to (ZOOM) %\n\nwhen I receive [reset v]\ndelete this clone\n\ndefine Clone at X: (x) Y: (y) Level: (level) Tile: (tile)\nshow\nset [x v] to ((x) * (420))\nset [y v] to ((y) * (360))\nswitch costume to (join [level] (join [ ] (join (level) (join [ ] (tile)))))\ncreate clone of (_myself_ v)\nhide\n\ndefine Level 2\nClone at Round X: [2] Y: [1] Level: [2] Tile: [3]\n\ndefine Layer (#)\ngo to [front v] layer\ngo [backward v] ((#) - (1)) layers\n\n@Collectables\n\nwhen I receive [green flag v]\nhide\nLayer (item # of [Collectables] in [layers v])\n\nwhen I receive [tick v]\nPosition X: (((x) - (SCROLL X)) * ((ZOOM) / (100))) Y: (((y) - (SCROLL Y)) * ((ZOOM) / (100)))\nif <touching (player v)?> then\n    change [coins v] by (1)\n    delete this clone\nend\n\nwhen I receive [setup v]\nset [coins v] to [0]\nif <(LEVEL) = [1]> then\n    Level 1\nend\nset [y v] to [999999999]\n\ndefine Clone at X: (x) Y: (y) Collectable # (collectable #)\nshow\nset [x v] to (x)\nset [y v] to (y)\nswitch costume to (collectable #)\ncreate clone of (_myself_ v)\nhide\n\ndefine Level 1\nClone at X: [431] Y: [91] Collectable # [1]\nClone at X: [619] Y: [64] Collectable # [1]\n\ndefine Position X: (x) Y: (y)\ngo to x: (x) y: (y)\nif <<(x) = (x position)> and <(y) = (y position)>> then\n    show\nelse\n    hide\nend\nset size to (ZOOM) %\n\nwhen I receive [reset v]\ndelete this clone\n\ndefine Layer (#)\ngo to [front v] layer\ngo [backward v] ((#) - (1)) layers\n\n@Exit\n\nwhen I receive [green flag v]\nhide\nLayer (item # of [Exit] in [layers v])\n\nwhen I receive [tick v]\nPosition X: (((x) - (SCROLL X)) * ((ZOOM) / (100))) Y: (((y) - (SCROLL Y)) * ((ZOOM) / (100)))\n\nwhen I receive [setup v]\nif <(LEVEL) = [1]> then\n    Go to X: [1040] Y: [45]\nend\nif <(LEVEL) = [2]> then\n    Go to X: [1230] Y: [370]\nend\nif <(LEVEL) = [3]> then\n    Go to X: [0] Y: [9999]\nend\n\ndefine Go to X: (x) Y: (y)\nshow\nset [x v] to (x)\nset [y v] to (y)\nswitch costume to (exit open v)\nhide\n\ndefine Position X: (x) Y: (y)\ngo to x: (x) y: (y)\nif <<(x) = (x position)> and <(y) = (y position)>> then\n    show\nelse\n    hide\nend\nset size to (ZOOM) %\n\nwhen I receive [reset v]\ndelete this clone\n\ndefine Layer (#)\ngo to [front v] layer\ngo [backward v] ((#) - (1)) layers\n\n