-Going to home- A scrolling platformer

Instructions: Hello!\nArrow keys to move and jump\n--Hold up arrow more time to jump more--\nIn this game you lost way to home \ncomplete the game as soon as possible\nComment bugs if you found!\nIf stuck press R

@Stage\n\nwhen [w v] key pressed\nset [mouse v] to (join ((mouse x) + (Scroll x)) (join [.] ((mouse y) + (Scroll y))))\nshow variable [mouse v]\n\nwhen stage clicked\nhide variable [mouse v]\n\nwhen I receive [play game v]\nforever\n    play sound (pick random (1) to (2)) until done\nend\n\nwhen flag clicked\nstop all sounds\n\n@empty\n\n@player\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    else\n        Game -die\n    end\nend\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) < [2]> then\n        start sound [Low Whoosh v]\n        change [sy v] by (12)\n    end\nend\nchange [sy v] by (-2)\nchange player y by (sy)\ntest-die\nchange [scroll x v] by (round (((x) - (Scroll x)) / (10)))\nif <(Scroll x) < [0]> then\n    set [scroll x v] to [0]\nend\nchange [scroll y v] by (round (((y) - (Scroll y)) / (5)))\nif <(Scroll y) < [0]> then\n    set [scroll y v] to [0]\nend\nposition\nif <(y) < [-180]> then\n    set [exit v] to [die]\nend\n\ndefine Game on\nset [x v] to [0]\nset [y v] to [0]\nset [sy v] to [0]\nset [in air v] to [0]\nset [exit v] to []\npoint in direction (90)\nset size to (100) %\nswitch costume to (costume1 v)\nclear graphic effects\nshow\n\nwhen I receive [green flag v]\nhide\ngo to [front v] layer\n\ndefine change player y by (y)\nchange [y v] by (y)\nchange [in air v] by (1)\nposition\nrepeat until <not <touching (platform v)?>>\n    if <(y) > [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\nrepeat (8)\n    change [y v] by (1)\n    position\n    if <not <touching (platform v)?>> then\n        stop [this script v]\n    end\nend\nchange [y v] by (-8)\nif <touching (platform v)?> then\n    repeat until <not <touching (platform 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\nswitch costume to (costume2 v)\nset volume to (120) %\nstart sound [die v]\nset [exit v] to [die]\nwait (1) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\nend\n\ndefine test-die\nif <touching (danger v)?> then\n    set [exit v] to [die]\nend\n\ndefine Game win\nrepeat (10)\n    point towards (exit v)\n    turn right (65) degrees\n    move ((distance to [exit v]) / (2)) steps\n    change size by (-2)\n    change [ghost v] effect by (4)\nend\nhide\nchange [level v] by (1)\nwait (1) seconds\n\nwhen I receive [intro done v]\nset [scroll x v] to (Scroll x)\nbroadcast (green flag v) and wait\nbroadcast (play game v) and wait\n\nwhen flag clicked\nhide\n\nwhen [r v] key pressed\nGame -die\n\n@Platform\n\nwhen I receive [green flag v]\nhide\n\nwhen I receive [tick v]\nposition x ((x) - (Scroll x)) y ((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 (1-1 v)\n    clone at x: [470] y: [0]\n    clone at x: [470] y: [0]\nelse\n    if <(level) = [2]> then\n        switch costume to (2-1 v)\n        clone at x: [650] y: [0]\n        clone at x: [650] y: [0]\n    else\n        if <(level) = [3]> then\n            switch costume to (3-1 v)\n            clone at x: [650] y: [0]\n            clone at x: [400] y: [0]\n        else\n            if <(level) = [4]> then\n                switch costume to (3-4 v)\n                set [x v] to [80]\n                set [y v] to [0]\n            end\n        end\n    end\nend\n\ncreate clone of (_myself_ v)\nchange [x v] by (470)\nnext costume\ncreate clone of (_myself_ v)\nchange [x v] by (470)\nnext costume\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\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 ((x) - (Scroll x)) y ((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 (costume1 v)\n    clone at x: [470] y: [0]\n    clone at x: [470] y: [0]\nelse\n    if <(level) = [2]> then\n        switch costume to (2-1 v)\n        clone at x: [470] y: [0]\n        clone at x: [520] y: [0]\n    else\n        if <(level) = [3]> then\n            switch costume to (3-1 v)\n            clone at x: [650] y: [0]\n            clone at x: [400] y: [0]\n        else\n            if <(level) = [4]> then\n                switch costume to (4 v)\n            end\n        end\n    end\nend\n\ncreate clone of (_myself_ v)\nchange [x v] by (470)\nnext costume\ncreate clone of (_myself_ v)\nchange [x v] by (470)\nnext costume\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\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\nswitch costume to (2-1 v)\n\n@collectables\n\nwhen I receive [green flag v]\nhide\n\nwhen I receive [tick v]\nposition x ((x) - (Scroll x)) y ((y) - (Scroll y))\nnext costume\nif <touching (player v)?> then\n    start sound (pick random (1) to (2))\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 [collected max v] to [-1]\nset [collected v] to [0]\nset [x v] to [0]\nset [y v] to [0]\nif <(level) = [1]> then\n    switch costume to (1 v)\n    clone at x: [165] y: [-20]\n    clone at x: [406] y: [10]\n    clone at x: [616] y: [-40]\n    clone at x: [700] y: [32]\n    clone at x: [888] y: [-13]\n    clone at x: [966] y: [66]\nelse\n    if <(level) = [2]> then\n        switch costume to (1 v)\n        clone at x: [124] y: [-60]\n        clone at x: [220] y: [-60]\n        clone at x: [360] y: [20]\n        clone at x: [430] y: [-22]\n        clone at x: [460] y: [-90]\n        clone at x: [504] y: [-90]\n        clone at x: [566] y: [-74]\n        clone at x: [671] y: [-5]\n        clone at x: [-803] y: [-90]\n        clone at x: [764] y: [-95]\n        clone at x: [828] y: [-79]\n        clone at x: [920] y: [20]\n        clone at x: [1010] y: [-96]\n    else\n        if <(level) = [3]> then\n            switch costume to (1 v)\n            clone at x: [316] y: [-50]\n            clone at x: [422] y: [-106]\n            clone at x: [515] y: [-53]\n            clone at x: [605] y: [5]\n            clone at x: [710] y: [65]\n            clone at x: [800] y: [70]\n            clone at x: [905] y: [70]\n            clone at x: [970] y: [0]\n            clone at x: [1160] y: [-50]\n        end\n    end\nend\nset [x v] to [-99999]\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\n\nwhen I receive [reset v]\ndelete this clone\n\ndefine clone at x: (x) y: (y)\nchange [collected max v] by (1)\nset [x v] to (x)\nset [y v] to (y)\ncreate clone of (_myself_ v)\n\nwhen flag clicked\n\n@EXIT\n\nwhen I receive [green flag v]\nhide\n\nwhen I receive [tick v]\nposition x ((x) - (Scroll x)) y ((y) - (Scroll y))\nif <<(costume [number v]) = [2]> and <touching (player v)?>> then\n    set [exit v] to [win]\nend\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 (costume1 v)\n    clone at x: [1260] y: [-7]\nelse\n    if <(level) = [2]> then\n        switch costume to (costume1 v)\n        clone at x: [1260] y: [-7]\n    else\n        if <(level) = [3]> then\n            switch costume to (costume1 v)\n            clone at x: [1260] y: [-7]\n        else\n            switch costume to (costume1 v)\n            clone at x: [100000000000000000000000000] y: [-7]\n        end\n    end\nend\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\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 (costume2 v)\n\nwhen I receive [tick v]\nshow variable [coins v]\nset [coins v] to (join (collected) (join [ / ] (collected max)))\n\nwhen flag clicked\nhide variable [coins v]\n\n@bg\n\nwhen I receive [green flag v]\nhide\n\nwhen I receive [tick v]\nposition x ((x) - (Scroll x)) y ((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 (1 v)\n    clone at x: [0] y: [64]\n    next costume\n    clone at x: [404] y: [65]\n    next costume\n    clone at x: [680] y: [35]\n    next costume\n    clone at x: [1080] y: [100]\nelse\n    if <(level) = [2]> then\n        switch costume to (2-1 v)\n        clone at x: [0] y: [64]\n        next costume\n        clone at x: [780] y: [64]\n    else\n        if <(level) = [3]> then\n            switch costume to (3-1 v)\n        else\n            if <(level) = [4]> then\n                switch costume to (end v)\n            end\n        end\n    end\nend\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\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)\ncreate clone of (_myself_ v)\n\n@intro\n\nwhen flag clicked\nhide\nswitch costume to (circle v)\nwait (0.5) seconds\nrepeat (4)\n    create clone of (_myself_ v)\n    next costume\n    wait (0.1) seconds\nend\nwait (2) seconds\nswitch costume to (logo v)\ncreate clone of (_myself_ v)\nswitch costume to (name v)\ncreate clone of (_myself_ v)\nwait (4) seconds\nswitch costume to (end v)\ncreate clone of (_myself_ v)\n\nwhen I start as a clone\ngo to [front v] layer\nshow\nset size to (0) %\nif <(costume [number v]) = [1]> then\n    go to x: (0) y: (180)\n    repeat (20)\n        change y by (((0) - (y position)) * (0.2))\n        change size by (((160) - (size)) * (0.1))\n    end\nend\nif <(costume [number v]) = [2]> then\n    hide\n    wait (1) seconds\n    go to [front v] layer\n    show\n    go to x: (0) y: (-180)\n    repeat (20)\n        change y by (((-100) - (y position)) * (0.2))\n        change size by (((120) - (size)) * (0.1))\n    end\nend\nif <(costume [number v]) = [3]> then\n    clear graphic effects\n    hide\n    go to x: (0) y: (0)\n    show\n    set size to (10) %\n    repeat (40)\n        change size by (((900) - (size)) * (0.3))\n    end\nend\nif <(costume [number v]) = [4]> then\n    clear graphic effects\n    hide\n    wait (0.2) seconds\n    go to x: (0) y: (0)\n    show\n    set size to (10) %\n    repeat (40)\n        change size by (((700) - (size)) * (0.3))\n    end\nend\nif <(costume [number v]) = [5]> then\n    clear graphic effects\n    hide\n    wait (0.2) seconds\n    go to x: (0) y: (0)\n    show\n    set size to (10) %\n    repeat (40)\n        change size by (((500) - (size)) * (0.3))\n    end\nend\nif <(costume [number v]) = [6]> then\n    clear graphic effects\n    hide\n    wait (0.2) seconds\n    go to x: (0) y: (0)\n    show\n    set size to (10) %\n    repeat (40)\n        change size by (((200) - (size)) * (0.3))\n    end\nend\nif <(costume [number v]) = [7]> then\n    set size to (100) %\n    go to [front v] layer\n    show\n    go to x: (600) y: (0)\n    repeat (50)\n        change x by (((0) - (x position)) * (0.1))\n        broadcast (volume v)\n    end\nend\n\nwhen flag clicked\nset volume to (100) %\nstart sound [Avicii - Levels 2 v]\n\nwhen I receive [volume v]\nchange volume by (-2)\n\nwhen flag clicked\nwait (12) seconds\nbroadcast (intro done v)\n\nwhen I receive [intro done v]\ndelete this clone\n\n@Thumbnail\n\nwhen I receive [tick v]\nshow variable [coins v]\ngo to [front v] layer\ngo to x: (0) y: (0)\nset [ghost v] effect to (100)\n\n