Mr.Scratchy - A Scrolling Platformer

Instructions: Use arrow keys or w,a,s,d to move.\nCollect coins, don't fall off or touch lava.\nHope you enjoy!

@Stage\n\nwhen [o v] key pressed\nwait until <not <key (o v) pressed?>>\nset [mouse v] to (join ((mouse x) + (SCROLL X)) (join [, ] ((mouse y) + (SCROLL Y))))\nshow variable [mouse v]\n\nwhen [c v] key pressed\nwait until <not <key (c v) pressed?>>\nhide variable [mouse v]\n\n@Player\n\nwhen flag clicked\nwait (0.2) seconds\nforever\n    if <(in air) > [4]> then\n        switch costume to (jump1 v)\n        start sound [jump v]\n        set volume to (0) %\n        wait until <<[13] > (in air)> and <(in air) > [11]>>\n        switch costume to (jump2 v)\n        wait until <<(in air) = [0]> or <(in air) = [1]>>\n        set volume to (100) %\n        switch costume to (stand v)\n        start sound [footstep v]\n    end\nend\n\nwhen flag clicked\nforever\n    if <<key (right arrow v) pressed?> or <key (d v) pressed?>> then\n        if <<(in air) = [0]> or <(in air) = [1]>> then\n            if <(costume [number v]) = [19]> then\n                switch costume to (run-01 v)\n            else\n                next costume\n            end\n        end\n    end\n    if <<key (left arrow v) pressed?> or <key (a v) pressed?>> then\n        if <<(in air) = [0]> or <(in air) = [1]>> then\n            if <(costume [number v]) = [19]> then\n                switch costume to (run-01 v)\n            else\n                next costume\n            end\n        end\n    end\nend\n\nwhen flag clicked\nset volume to (100) %\nforever\n    if <<<key (right arrow v) pressed?> or <key (d v) pressed?>> and <<(in air) = [0]> or <(in air) = [1]>>> then\n        start sound [footstep v]\n        wait (0.36) seconds\n    end\n    if <<<key (left arrow v) pressed?> or <key (a v) pressed?>> and <<(in air) = [0]> or <(in air) = [1]>>> then\n        start sound [footstep v]\n        wait (0.36) seconds\n    end\nend\n\nwhen flag clicked\nbroadcast (Green Flag v) and wait\nbroadcast (Play Game v) and wait\n\nwhen I receive [green flag 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        Run Program\n        broadcast (Tick v) and wait\n    end\n    if <(EXIT) = [win]> then\n        Game - Win\n    else\n        Game - Die\n    end\nend\n\ndefine Game - On\npoint in direction (90)\nswitch costume to (stand v)\nset [x v] to [0]\nset [in air v] to [0]\nset [y v] to [0]\nset [scroll x v] to [0]\nset [scroll y v] to [0]\nset [sy v] to [0]\nset [exit v] to []\nset size to (60) %\nclear graphic effects\nshow\n\ndefine Run Program\nset [collected showing v] to (join (COLLECTED) (join [/] (COLLECTED MAX)))\nif <<key (left arrow v) pressed?> or <key (a v) pressed?>> then\n    Change Player X by: [-10]\n    point in direction (-90)\nend\nif <<key (right arrow v) pressed?> or <key (d v) pressed?>> then\n    Change Player X by: [10]\n    point in direction (90)\nend\nif <<key (up arrow v) pressed?> or <key (w v) pressed?>> then\n    if <(in air) < [4]> then\n        set [sy v] to [18]\n    end\nend\nchange [sy v] by (-2)\nChange Player Y by: (sy)\nTest - Die\nset [scroll x v] to (x)\nif <(SCROLL X) < [0]> then\n    set [scroll x v] to [0]\nend\nchange [scroll y v] by (round (((y) - (SCROLL Y)) / (10)))\nif <(SCROLL Y) < [0]> then\n    set [scroll y v] to [0]\nend\nPosition\nif <(y) < [-188]> then\n    set [exit v] to [die]\nend\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)) y: ((y) - (SCROLL Y))\n\ndefine Change Player X by: (sx)\nchange [x v] by (sx)\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 <(sx) > [0]> then\n            change [x v] by (-1)\n        else\n            change [x v] by (1)\n        end\n        Position\n    end\nend\n\ndefine Game - Die\nset volume to (100) %\nstart sound [hurt v]\nset [exit v] to []\nrepeat (6)\n    hide\n    wait (0.1) seconds\n    show\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 Game - Win\nrepeat (50)\n    point towards (portal v)\n    turn right (65) degrees\n    move ((distance to [portal v]) / (2)) steps\n    change size by (-1)\n    change [ghost v] effect by (2)\nend\nhide\nchange [level v] by (1)\nwait (1) seconds\n\n@Platforms\n\nwhen I receive [green flag v]\nhide\n\nwhen I receive [tick v]\nPosition ((x) - (SCROLL X)) ((y) - (SCROLL Y))\n\nwhen I receive [setup v]\nhide\nset [x v] to [0]\nset [y v] to [0]\nif <(LEVEL) = [1]> then\n    switch costume to (level 1 1 v)\n    Clone at x: [360] y: [0]\n    Clone at x: [360] y: [0]\nelse\n    if <(LEVEL) = [2]> then\n        switch costume to (level 2 1 v)\n        Clone at x: [0] y: [400]\n        Clone at x: [450] y: [100]\n    else\n        if <(LEVEL) = [3]> then\n            switch costume to (level 3 1 v)\n            Clone at x: [0] y: [400]\n            Clone at x: [0] y: [400]\n            Clone at x: [0] y: [500]\n        else\n            switch costume to (level 5 1 v)\n        end\n    end\nend\n\nClone at x: [0] y: [400]\nClone at x: [0] y: [400]\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\nwhen I receive [reset v]\ndelete this clone\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\n@Danger\n\nwhen I receive [green flag v]\nhide\n\nwhen I receive [tick v]\nPosition ((x) - (SCROLL X)) ((y) - (SCROLL Y))\n\nwhen I receive [setup v]\nhide\nset [x v] to [0]\nset [y v] to [0]\nif <(LEVEL) = [1]> then\n    switch costume to (level 1 1 v)\n    Clone at x: [360] y: [0]\n    Clone at x: [360] y: [0]\nelse\n    if <(LEVEL) = [2]> then\n        switch costume to (level 2 1 v)\n        Clone at x: [0] y: [400]\n        Clone at x: [450] y: [100]\n    else\n        if <(LEVEL) = [3]> then\n            switch costume to (level 3 1 v)\n            Clone at x: [0] y: [400]\n            Clone at x: [0] y: [400]\n            Clone at x: [0] y: [500]\n        else\n            switch costume to (level 4 1 v)\n        end\n    end\nend\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\nwhen I receive [reset v]\ndelete this clone\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\n@Collectables\n\nwhen I receive [green flag v]\nhide\n\nwhen I receive [tick v]\nPosition ((x) - (SCROLL X)) ((y) - (SCROLL Y))\nif <touching (player v)?> then\n    start sound [Collect v]\n    change [collected v] by (1)\n    if <(COLLECTED) = (COLLECTED MAX)> then\n        broadcast (Open Portal v)\n    end\n    delete this clone\nend\n\nwhen I receive [setup v]\nhide\nset [x v] to [0]\nset [collected v] to [0]\nset [y v] to [0]\nset [collected max v] to [0]\nif <(LEVEL) = [1]> then\n    switch costume to (collectable v)\n    Clone at x: [100] y: [0]\n    Clone at x: [180] y: [60]\n    Clone at x: [265] y: [0]\n    Clone at x: [535] y: [25]\n    Clone at x: [725] y: [100]\nelse\n    if <(LEVEL) = [2]> then\n        switch costume to (collectable v)\n        Clone at x: [-105] y: [-25]\n        Clone at x: [220] y: [110]\n        Clone at x: [-40] y: [315]\n        Clone at x: [135] y: [420]\n        Clone at x: [700] y: [720]\n    else\n        if <(LEVEL) = [3]> then\n            switch costume to (collectable v)\n            Clone at x: [208] y: [1283]\n            Clone at x: [-200] y: [1012]\n            Clone at x: [-33] y: [1015]\n            Clone at x: [205] y: [815]\n            Clone at x: [-208] y: [712]\n            Clone at x: [260] y: [570]\n            Clone at x: [138] y: [487]\n            Clone at x: [-10] y: [413]\n            Clone at x: [-40] y: [348]\n            Clone at x: [25] y: [265]\n        else\n            set [x v] to [-999999999999999]\n        end\n    end\nend\nset [x v] to [-999999999999999]\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\nwhen I receive [reset v]\ndelete this clone\n\ndefine Clone at x: (x) y: (y)\nset [x v] to (x)\nset [y v] to (y)\nchange [collected max v] by (1)\ncreate clone of (_myself_ v)\n\nif <(LEVEL) = [4]> then\n    switch costume to (collectable v)\n    Clone at x: [-115] y: [60]\n    Clone at x: [92] y: [137]\n    Clone at x: [-105] y: [220]\n    Clone at x: [90] y: [300]\n    Clone at x: [-120] y: [402]\n    Clone at x: [260] y: [570]\n    Clone at x: [138] y: [487]\n    Clone at x: [-10] y: [413]\n    Clone at x: [-40] y: [348]\n    Clone at x: [25] y: [265]\nend\n\n@Portal\n\nwhen I receive [green flag v]\nhide\n\nwhen I receive [tick v]\nPosition ((x) - (SCROLL X)) ((y) - (SCROLL Y))\nif <<(costume [name v]) = [Open]> and <touching (player v)?>> then\n    set [exit v] to [win]\nend\n\nwhen I receive [setup v]\nswitch costume to (closed v)\nhide\nset [x v] to [0]\nset [y v] to [0]\nset [collected v] to [0]\nif <(LEVEL) = [1]> then\n    Clone at x: [950] y: [-10]\nelse\n    if <(LEVEL) = [2]> then\n        Clone at x: [777] y: [690]\n    else\n        if <(LEVEL) = [3]> then\n            Clone at x: [345] y: [1330]\n        else\n            set [x v] to [-9999999]\n        end\n    end\nend\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\nwhen I receive [reset v]\ndelete this clone\n\ndefine Clone at x: (x) y: (y)\nset [x v] to (x)\nset [y v] to (y)\n\nwhen I receive [open portal v]\nswitch costume to (open v)\n\n@Thumbnail\n\nwhen flag clicked\nhide\nshow variable [collected showing v]\nshow variable [level v]\n\nshow\ngo to [front v] layer\ngo to x: (0) y: (0)\nhide variable [collected showing v]\nhide variable [level v]\n\n