A Scrolling Platformer, (Marble's adventure)

Instructions: Press arrows to move\nDon't touch red or purple\nCollect orbs, to open portal (only in level 1)\n3 levels\nGo through portal, \npress m to mute music

@Stage\n\nwhen [m v] key pressed\nif <(volume) = [100]> then\n    repeat (10)\n        change volume by (-10)\n        wait (0.05) seconds\n    end\nelse\n    repeat (10)\n        change volume by (10)\n        wait (0.05) seconds\n    end\nend\n\nset [mouse v] to (join ((mouse x) + (SCROLL X)) (join [, ] ((mouse y) + (SCROLL Y))))\n\nwhen flag clicked\nset volume to (100) %\nforever\n    play sound [Britt_Nicole_-_Headphones_Instrumental-loM1W-C_DVM v] until done\nend\n\n@Player\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)\n    broadcast (set-up v)\n    game on\n    repeat until <(EXIT) > []>\n        tick\n        broadcast (tick v) and wait\n    end\n    if <(EXIT) = [next level]> then\n        next level\n    else\n        Game - die\n    end\nend\n\ndefine game on\nset [in air v] to [0]\nset [x 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 []\nshow\nset size to (100) %\nset [ghost v] effect to (0)\n\ndefine tick\nif <key (left arrow v) pressed?> then\n    Change player x by [-8]\nend\nif <key (right arrow v) pressed?> then\n    Change player x by [8]\nend\nif <key (up arrow v) pressed?> then\n    if <(in air) < [4]> then\n        set [sy v] to [16]\n    end\nend\nchange [sy v] by (-2)\nChange Player Y by (sy)\ntest - die\nset [scroll x v] to (x)\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) < [-180]> then\n    set [exit v] to [dead]\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 (12)\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 (-12)\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 [exit v] to []\nrepeat (5)\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 [dead]\nend\n\ndefine next level\nrepeat (50)\n    point towards (portal v)\n    turn right (65) degrees\n    move ((distance to [portal v]) / (2)) steps\n    set size to (-1) %\n    change [ghost v] effect by (2)\nend\nchange [level v] by (1)\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 [set-up 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]\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: [325]\n        Clone at x: [350] y: [200]\n    else\n        if <(LEVEL) = [3]> then\n            switch costume to (level 3 1 v)\n            Clone at x: [360] y: [0]\n            Clone at x: [360] y: [0]\n            Clone at x: [360] y: [0]\n            Clone at x: [360] y: [0]\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@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 [set-up 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]\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: [325]\n        Clone at x: [350] y: [200]\n    else\n        if <(LEVEL) = [3]> then\n            switch costume to (level 3 1 v)\n            Clone at x: [360] y: [0]\n            Clone at x: [360] y: [0]\n            Clone at x: [360] y: [0]\n            Clone at x: [360] y: [0]\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@Collectibles\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    change [collected v] by (1)\n    if <(COLLECTED) = (COLLECTED MAX)> then\n        broadcast (opening v)\n    end\n    delete this clone\nend\n\nwhen I receive [set-up v]\ngo to [front v] layer\nhide\nset [collected v] to [0]\nset [collected max v] to [0]\nset [x v] to [0]\nset [y v] to [0]\nif <(LEVEL) = [1]> then\n    switch costume to (doy v)\n    Clone at x: [50] y: [0]\n    Clone at x: [369] y: [50]\n    Clone at x: [624] y: [2]\n    Clone at x: [750] y: [51]\nend\nset [x v] to [-99999]\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\n@Portal\n\nwhen I receive [green flag v]\nshow variable [collected v]\nhide\n\nwhen I receive [tick v]\nPosition ((x) - (SCROLL X)) ((y) - (SCROLL Y))\nif <<(costume [number v]) = [2]> and <touching (player v)?>> then\n    set [exit v] to [next level]\nend\n\nwhen I receive [set-up v]\ngo to [front v] layer\nhide\nset [collected v] to [0]\nset [x v] to [0]\nset [y v] to [0]\nif <(LEVEL) = [1]> then\n    switch costume to (closed v)\n    Clone at x: [1300] y: [40]\nelse\n    if <(LEVEL) = [2]> then\n        hide variable [collected v]\n        switch costume to (open v)\n        Clone at x: [622] y: [655]\n    else\n        if <(LEVEL) = [3]> then\n            switch costume to (open v)\n            Clone at x: [1700] y: [40]\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 [opening v]\nswitch costume to (open v)\n\nwhen flag clicked\nforever\n    if <<(LEVEL) = [3]> and <touching (player v)?>> then\n        broadcast (you won v)\n    end\nend\n\n@Sprite1\n\nwhen flag clicked\nhide\n\nwhen I receive [you won v]\ngo to [front v] layer\nshow\nstop [all v]\n\n@Sprite2\n\nwhen flag clicked\nforever\n    hide\nend\n\n