Pizza Platformer Dash

Instructions: Arrow keys to move.\nGet pizza safely across the levels!\nDon't run into blob monsters.\nJump on there heads to squash them!\nCollect all the coins to go to the next level.\nYou may have to wait a bit for moving platforms.\n\nInspired by @griffpatch's Coin Dash.\nCreated by @skidsteerloader\nFeel free to take code or sprites but please give credit!\nMusic by OpenGameArt.org\n \nScratch On\n     -skidsteerloader

@Stage\n\nwhen [space v] key pressed\nset [mouse v] to (join ((mouse x) + (SCROLL X)) (join [, ] ((mouse y) + (SCROLL Y))))\n\n@Bank\n\n@Pizza\n\nwhen flag clicked\n\ndefine Controls - Jump, Crouch\nif <<key (w v) pressed?> or <key (up arrow v) pressed?>> then\n    if <(falling) < [4]> then\n        set [sy v] to [12]\n    end\nend\nif <<key (s v) pressed?> or <key (down arrow v) pressed?>> then\n    set [in platform v] to [2]\nend\n\ndefine Reset Level\nset [sx v] to [0]\nset [sy v] to [0]\nset [x v] to [1010]\nset [y v] to [0]\nset [frame v] to [0]\nset [direction v] to [90]\nset [player die v] to [0]\nset [player win v] to [0]\nset [scroll x v] to (x)\nset [scroll y v] to [0]\nshow\n\ndefine Gravity\nif <touching color (#006bff)?> then\n    set [sy v] to ((sy) * (0.6))\n    set [sx v] to ((sx) * (0.6))\nend\nchange [sy v] by (-1)\nchange [y v] by (sy)\nchange [falling v] by (1)\nGet Touching \n\ndefine Collision Floor Ceiling <up?>\nif <(touch) = [0]> then\n    set [in platform v] to [1]\nelse\n    if <<up?> and <(touch) = [1]>> then\n        set [in platform v] to [2]\n    end\nend\nrepeat until <(touch) < (in platform)>\n    if <up?> then\n        change [y v] by (-1)\n    else\n        change [y v] by (1)\n        set [falling v] to [0]\n    end\n    set [sy v] to [0]\n    Get Touching <not <up?>>\nend\n\ndefine Get Touching <check platform>\ngo to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\nif <touching (ground v)?> then\n    set [touch v] to [9]\nelse\n    if <touching (moving platforms v)?> then\n        set [touch v] to [5]\n    else\n        if <<check platform> and <touching (platforms v)?>> then\n            set [touch v] to [1]\n        else\n            set [touch v] to [0]\n        end\n    end\nend\n\ndefine Keys - Left Right\nif <<key (a v) pressed?> or <key (left arrow v) pressed?>> then\n    set [pushed sx v] to [-1]\nelse\n    if <<key (d v) pressed?> or <key (right arrow v) pressed?>> then\n        set [pushed sx v] to [1]\n    else\n        set [pushed sx v] to [0]\n    end\nend\n\ndefine Walk Dir Left Right (speed) (slope)\nchange [x v] by (speed)\nset [slope v] to [1]\nGet Touching <(in platform) = [1]>\nrepeat until <<(slope) > (slope)> or <(touch) = [0]>>\n    change [y v] by (1)\n    change [slope v] by (1)\n    Get Touching <(in platform) = [1]>\nend\nif <(slope) > (slope)> then\n    change [x v] by ((0) - (speed))\n    change [y v] by ((0) - (slope))\n    if <<(touch) = [1]> and <(in platform) = [1]>> then\n        set [in platform v] to [2]\n        Walk Dir Left Right (speed) (slope)\n        if <(sx) = [0]> then\n            set [in platform v] to [1]\n        end\n    else\n        set [sx v] to [0]\n    end\nend\n\ndefine Set Player Costume\nif <(frame) = [0]> then\n    switch costume to (stand pizza1 v)\nelse\n    switch costume to ([floor v] of ((4) + ((frame) mod (16))) )\nend\nswitch costume to (pizza v)\n\ndefine Get scroll (string)\nif <(y) < [-180]> then\n    stop all sounds\n    broadcast (Die v)\n    hide\n    wait (2) seconds\n    broadcast (Play Music v)\n    broadcast (Reset v) and wait\n    broadcast (Clone Level v) and wait\n    Reset Level\nend\nif <(PLAYER DIE) = [1]> then\n    stop all sounds\n    broadcast (Die v)\n    hide\n    wait (0) seconds\n    broadcast (Play Music v)\n    broadcast (Reset v) and wait\n    broadcast (Clone Level v) and wait\n    Reset Level\nend\nif <(PLAYER WIN) = [1]> then\n    change [level v] by (1)\n    stop all sounds\n    broadcast (Die v)\n    hide\n    wait (0) seconds\n    broadcast (Play Music v)\n    broadcast (Reset v) and wait\n    broadcast (Clone Level v) and wait\n    Reset Level\nend\nchange [scroll x v] by (round (((x) - (string)) * (0.5)))\nGet Touching \n\nbroadcast (Reset v) and wait\nbroadcast (Clone Level v) and wait\nReset Level\n\nbroadcast (Reset v) and wait\nbroadcast (Clone Level v) and wait\nReset Level\n\nwhen I receive [bounce v]\nset [sy v] to [10]\nset [falling v] to [0]\n\nwhen I receive [play game v]\nset [level v] to [1]\nbroadcast (Reset v) and wait\nbroadcast (Clone Level v) and wait\ngo to [front v] layer\nshow\nReset Level\nbroadcast (Play Music v)\nforever\n    point in direction (90)\n    switch costume to (hitbox2 v)\n    Controls - Jump, Crouch\n    Gravity\n    Collision Floor Ceiling <(sy) > [0]>\n    Keys - Left Right\n    if <(pushed sx) > [0]> then\n        change [sx v] by (1.5)\n        change [frame v] by (0.6)\n        set [direction v] to [90]\n    else\n        if <(pushed sx) < [0]> then\n            change [sx v] by (-1.5)\n            change [frame v] by (0.6)\n            set [direction v] to [-90]\n        else\n            set [frame v] to [0]\n        end\n    end\n    set [sx v] to ((sx) * (0.8))\n    Walk Dir Left Right ((sx) + (PLATFORM SX)) [12]\n    set rotation style [left-right v]\n    point in direction (direction)\n    Get scroll (SCROLL X)\n    Set Player Costume\n    broadcast (Tick v) and wait\nend\n\nbroadcast (Play Game v) and wait\n\n@Ground\n\nwhen I receive [clone level v]\nSetup\n\nwhen I receive [reset v]\nchange [clone limit v] by (-1)\ndelete this clone\n\ndefine Setup\nhide\ngo to x: (0) y: (0)\nset [level x v] to [0]\nif <(LEVEL) = [1]> then\n    switch costume to (ground4 v)\n    set [costume v] to [1]\nelse\n    switch costume to (1ground1 v)\n    set [costume v] to [10]\nend\nchange [clone limit v] by (1)\ncreate clone of (_myself_ v)\nchange [level x v] by (460)\nchange [costume v] by (1)\nnext costume\n\nwhen I receive [tick v]\nPosition (round ((level x) - (SCROLL X))) [0]\n\ndefine Position (x) (y)\nif <(x) < [-460]> then\n    hide\n    repeat until <not <(round ((level x) - (SCROLL X))) < [-460]>>\n        change [level x v] by (920)\n        change [costume v] by (2)\n    end\n    switch costume to (costume)\n    Position (round ((level x) - (SCROLL X))) [1]\nelse\n    if <(x) > [460]> then\n        hide\n        repeat until <not <(round ((level x) - (SCROLL X))) > [460]>>\n            change [level x v] by (-920)\n            change [costume v] by (-2)\n        end\n        switch costume to (costume)\n        Position (round ((level x) - (SCROLL X))) [1]\n    else\n        go to x: (x) y: (y)\n        if <(x) = (x position)> then\n            show\n        else\n            hide\n        end\n    end\nend\n\n@Platforms\n\nwhen I receive [clone level v]\nSetup\n\nwhen I receive [reset v]\nchange [clone limit v] by (-1)\ndelete this clone\n\nwhen I receive [tick v]\nPosition (round ((level x) - (SCROLL X))) [0]\n\ndefine Position (x) (y)\nif <(x) < [-460]> then\n    hide\n    repeat until <not <(round ((level x) - (SCROLL X))) < [-460]>>\n        change [level x v] by (920)\n        change [costume v] by (2)\n    end\n    switch costume to (costume)\n    Position (round ((level x) - (SCROLL X))) [1]\nelse\n    if <(x) > [460]> then\n        hide\n        repeat until <not <(round ((level x) - (SCROLL X))) > [460]>>\n            change [level x v] by (-920)\n            change [costume v] by (-2)\n        end\n        switch costume to (costume)\n        Position (round ((level x) - (SCROLL X))) [1]\n    else\n        go to x: (x) y: (y)\n        if <(x) = (x position)> then\n            show\n        else\n            hide\n        end\n    end\nend\n\ndefine Setup\nhide\ngo to x: (0) y: (0)\nset [level x v] to [0]\nif <(LEVEL) = [1]> then\n    switch costume to (ground4 v)\n    set [costume v] to [1]\nelse\n    switch costume to (1ground1 v)\n    set [costume v] to [10]\nend\nchange [clone limit v] by (1)\ncreate clone of (_myself_ v)\nchange [level x v] by (460)\nchange [costume v] by (1)\nnext costume\n\n@Visual\n\nwhen I receive [clone level v]\nSetup\n\nwhen I receive [reset v]\nchange [clone limit v] by (-1)\ndelete this clone\n\nwhen I receive [tick v]\nPosition (round ((level x) - (SCROLL X))) [0]\n\ndefine Position (x) (y)\nif <(x) < [-460]> then\n    hide\n    repeat until <not <(round ((level x) - (SCROLL X))) < [-460]>>\n        change [level x v] by (920)\n        change [costume v] by (2)\n    end\n    switch costume to (costume)\n    Position (round ((level x) - (SCROLL X))) [1]\nelse\n    if <(x) > [460]> then\n        hide\n        repeat until <not <(round ((level x) - (SCROLL X))) > [460]>>\n            change [level x v] by (-920)\n            change [costume v] by (-2)\n        end\n        switch costume to (costume)\n        Position (round ((level x) - (SCROLL X))) [1]\n    else\n        go to x: (x) y: (y)\n        if <(x) = (x position)> then\n            show\n        else\n            hide\n        end\n    end\nend\n\ndefine Setup\nhide\ngo to x: (0) y: (0)\nset [level x v] to [0]\nif <(LEVEL) = [1]> then\n    switch costume to (ground4 v)\n    set [costume v] to [1]\nelse\n    switch costume to (1ground1 v)\n    set [costume v] to [10]\nend\nchange [clone limit v] by (1)\ncreate clone of (_myself_ v)\nchange [level x v] by (460)\nchange [costume v] by (1)\nnext costume\n\n@Moving Platforms\n\nwhen I receive [clone level v]\nif <(LEVEL) = [1]> then\n    switch costume to (platform 1 v)\n    set [x v] to [3446]\n    set [y v] to [-106]\n    set [min x v] to [3446]\n    set [max x v] to [3836]\n    set [lift speed x v] to [2]\n    create clone of (_myself_ v)\nelse\n    switch costume to (platform 1 v)\n    set [x v] to [2104]\n    set [y v] to [-33]\n    set [min x v] to [2073]\n    set [max x v] to ((2104) + (400))\n    set [lift speed x v] to [2]\n    create clone of (_myself_ v)\nend\nset [x v] to [-999999]\n\nwhen I receive [tick v]\nchange [x v] by (lift speed x)\nif <(x) > (max x)> then\n    set [lift speed x v] to ((0) - (lift speed x))\nelse\n    if <(x) < (min x)> then\n        set [lift speed x v] to ((0) - (lift speed x))\n    end\nend\ngo to x: ((x) - (SCROLL X)) y: (((y) + (10)) - (SCROLL Y))\nif <touching (pizza v)?> then\n    set [platform sx v] to (lift speed x)\nelse\n    set [platform sx v] to [0]\nend\ngo to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\nif <((x) - (SCROLL X)) = (x position)> then\n    show\nelse\n    hide\nend\n\nset [lift speed x v] to ((0) - (lift speed x))\n\nwhen I receive [reset v]\nchange [clone limit v] by (-1)\ndelete this clone\n\n@Music\n\nwhen I receive [play music v]\nforever\n    if <(LEVEL) = [1]> then\n        play sound [GameMusicPackLevel3 v] until done\n    else\n        play sound [Juhani Junkala \[Retro Game Music Pack\] Level 1 v] until done\n    end\nend\n\nwhen I receive [die v]\nstop [other scripts in sprite v]\n\nwhen I receive [music tick v]\n\nplay sound [GameMusicPackLevel3 v] until done\nplay sound [Juhani Junkala \[Retro Game Music Pack\] Ending v] until done\n\nstop [other scripts in sprite v]\nplay sound [Juhani Junkala \[Retro Game Music Pack\] Level 1 v] until done\n\nforever\nend\n\n@Enemy\n\nwhen I receive [clone level v]\nif <(LEVEL) = [1]> then\n    Create an enemy [1625] [2065] [1861] [20] [-2]\n    Create an enemy [1625] [2065] [1625] [20] [2]\n    Create an enemy [2587] [3044] [3044] [144] [2]\nelse\n    if <(LEVEL) = [2]> then\n        Create an enemy [1179] [1477] [1179] [37] [-2]\n        Create an enemy [1179] [1477] [1477] [37] [-2]\n        Create an enemy [1675] [1971] [1971] [30] [-2]\n        Create an enemy [1675] [1971] [1675] [30] [2]\n    end\nend\nset [x v] to [-999999]\n\nwhen I receive [tick v]\ngo to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\nset rotation style [left-right v]\npoint in direction (((lift speed x) / (2)) * (90))\nif <((x) - (SCROLL X)) = (x position)> then\n    if <(- die) = [0]> then\n        Move up (lift speed x)\n        if <(x) > (max x)> then\n            set [lift speed x v] to ((0) - (lift speed x))\n        else\n            if <(x) < (min x)> then\n                set [lift speed x v] to ((0) - (lift speed x))\n            end\n        end\n        go to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\n        change [sy v] by (-1)\n        change [y v] by (sy)\n        go to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\n        Acreen refresh\n    end\n    show\n    set [no viz v] to [0]\nelse\n    if <(- die) = [1]> then\n        set [- die v] to [0]\n        change [y v] by (20)\n        clear graphic effects\n    end\n    hide\n    set [no viz v] to [1]\n    set [- die v] to [0]\n    switch costume to (enemy v)\nend\ngo to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\nif <touching (pizza v)?> then\n    if <([falling v] of [pizza v]) > [3]> then\n        if <(- die) = [0]> then\n            broadcast (Bounce v)\n        end\n        set [- die v] to [1]\n        switch costume to (enemy2 v)\n        set [tick v] to [100]\n    else\n        if <(- die) = [0]> then\n            set [player die v] to [1]\n        end\n    end\nend\nif <<(- die) = [1]> and <(tick) > [1]>> then\n    change [ghost v] effect by (10)\n    change [tick v] by (-1)\nend\n\nstart sound [pop v]\n\n\n    set [y v] to [20]\nend\n\ndefine Move up (sx)\nchange [x v] by (sx)\ngo to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\nif <touching (ground v)?> then\n    repeat (10)\n        change [y v] by (1)\n        go to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\n        if <not <touching (ground v)?>> then\n            stop [this script v]\n        end\n    end\n    change [y v] by (-10)\nend\n\ndefine Create an enemy (min) (max) (x) (y) (speed)\nswitch costume to (enemy v)\nset [x v] to (x)\nset [y v] to (y)\nset [min x v] to (min)\nset [max x v] to (max)\nset [lift speed x v] to (speed)\nset [sy v] to [0]\nset [- die v] to [0]\nclear graphic effects\ncreate clone of (_myself_ v)\n\ndefine Acreen refresh\nrepeat until <not <touching (ground v)?>>\n    change [y v] by (1)\n    set [sy v] to [0]\n    go to x: ((x) - (SCROLL X)) y: ((y) - (SCROLL Y))\nend\n\nset [sty v] to [0]\n\nwhen I receive [reset v]\ndelete this clone\n\n@Coins\n\nwhen I receive [tick v]\nswitch costume to ((costume [number v]) + (1))\nPosition ((x) - (SCROLL X)) ((y) - (SCROLL Y))\nif <touching (pizza v)?> then\n    change [collected v] by (1)\n    if <(COLLECTED) = (COLLECTED MAX)> then\n        set [player win v] to [1]\n    end\n    delete this clone\nend\n\ndefine Position (x) (y)\ngo to x: (x) y: (y)\nif <(x) = (x position)> then\n    show\nelse\n    hide\nend\n\nwhen I receive [reset v]\ndelete this clone\n\nwhen I receive [clone level v]\nset [collected v] to [0]\nset [collected max v] to [0]\nif <(LEVEL) = [1]> then\n    Create coin [910] [133]\n    Create coin [1220] [-18]\n    Create coin [1429] [57]\n    Create coin [1596] [148]\n    Create coin [1846] [115]\n    Create coin [2571] [25]\n    Create coin [2800] [98]\n    Create coin [3105] [20]\n    Create coin [3348] [-8]\n    Create coin [3624] [39]\n    Create coin [4082] [36]\nelse\n    Create coin [678] [57]\n    Create coin [1228] [93]\n    Create coin [1390] [81]\n    Create coin [1574] [155]\n    Create coin [1571] [-136]\n    Create coin [2341] [61]\n    Create coin [2753] [142]\n    Create coin [3097] [29]\n    Create coin [3394] [37]\nend\nset [x v] to [-99999]\n\ndefine Create coin (x) (y)\nset [x v] to (x)\nset [y v] to (y)\ncreate clone of (_myself_ v)\nchange [collected max v] by (1)\n\n@up\n\nwhen I receive [clone level v]\nhide\nswitch costume to (costume1 v)\nif <(LEVEL) = [3]> then\n    stop all sounds\n    go to [front v] layer\n    show\n    go to x: (0) y: (0)\n    set size to (0) %\n    repeat (10)\n        change size by (10)\n    end\n    forever\nend\n\nbroadcast (Music tick v) and wait\n\nplay sound [Juhani Junkala \[Retro Game Music Pack\] Level 1 v] until done\nplay sound [GameMusicPackLevel3 v] until done\n\nplay sound [Juhani Junkala \[Retro Game Music Pack\] Ending v] until done\n\n@Play Game\n\nwhen flag clicked\nshow\ngo to [front v] layer\nswitch costume to (costume1 v)\ncreate clone of (_myself_ v)\nswitch costume to (costume2 v)\nforever\n    if <touching (mouse-pointer v)?> then\n        set [brightness v] effect to (10)\n        if <mouse down?> then\n            broadcast (Play Game v) and wait\n        end\n    else\n        clear graphic effects\n    end\nend\n\nwhen I receive [play game v]\nhide\nstop [other scripts in sprite v]\n\nwhen I start as a clone\nforever\n    play sound [Juhani Junkala \[Retro Game Music Pack\] Title Screen v] until done\nend\n\nstop all sounds\n\nset [ghost v] effect to (0)\n\n@Hey\n\nwhen flag clicked\nset [ghost v] effect to (100)\ngo to [front v] layer\n\n