Cave Platformer


@Stage\n\nwhen I receive [make terrain v]\n\nwhen flag clicked\nswitch backdrop to (backdrop1 v)\nset [end v] to [0]\nforever\n    if <(end) = [0]> then\n        if <<(Level:) < [9]> and <(Level:) > [3]>> then\n            switch backdrop to (gray v)\n        else\n            switch backdrop to (backdrop1 v)\n        end\n    else\n        switch backdrop to (end v)\n        wait (0.3) seconds\n        stop [this script v]\n    end\nend\n\nnext backdrop\n\nset [terrain gen v] to [1]\n\nstop [other scripts in sprite v]\n\nwait (0.1) seconds\n\n\n\nbroadcast (END v)\n\n@Sprite1\n\ndefine fall at speed (speed)\nset [fv v] to (speed)\nrepeat until <touching (levels  v)?>\n    change y by (join [-] (fv))\n    change [fv v] by (1)\nend\nchange y by (fv)\nset [can i jump? v] to [1]\n\nwhen flag clicked\n\nwhen I receive [spawn v]\nwait until <(begin forever fall) = [1]>\nforever\n    if <(can i jump?) = [1]> then\n        repeat until <touching (levels  v)?>\n            change y by (-3)\n        end\n        set [can i jump? v] to [1]\n    end\nend\n\nwhen I receive [spawn v]\nforever\n    if <key (right arrow v) pressed?> then\n        change x by (6)\n        change y by (3)\n        if <touching (levels  v)?> then\n            change x by (-6)\n        end\n        change y by (-3)\n    end\n    if <key (left arrow v) pressed?> then\n        change x by (-6)\n        change y by (3)\n        if <touching (levels  v)?> then\n            change x by (6)\n        end\n        change y by (-3)\n    end\nend\n\nwhen I receive [spawn v]\nset [begin forever fall v] to [0]\nset [can i jump? v] to [0]\ngo to x: (-200) y: (-20)\nshow\nfall at speed [3]\nset [begin forever fall v] to [1]\nforever\n    if <<key (up arrow v) pressed?> and <(can i jump?) = [1]>> then\n        set [can i jump? v] to [0]\n        set [vel v] to [10]\n        repeat (10)\n            change y by (vel)\n            if <touching (levels  v)?> then\n                change y by (join [-] (vel))\n                repeat until <touching (levels  v)?>\n                    change y by (join [-] (vel))\n                end\n            end\n            change [vel v] by (-0.8)\n        end\n        fall at speed [3]\n    end\nend\n\nwhen I receive [spawn v]\nwait until <touching (goal v)?>\nchange [level: v] by (1)\ngo to x: (-200) y: (-20)\nbroadcast (next level v)\nbroadcast (begin v)\n\nwhen I receive [begin v]\ngo to x: (-200) y: (-20)\nhide\nbroadcast (spawn v)\n\nwhen flag clicked\nhide variable [begin forever fall v]\nhide variable [can i jump? v]\n\nwhen flag clicked\nset [level: v] to [1]\n\nwhen I receive [spawn v]\nwait until <touching (_edge_ v)?>\nbroadcast (begin v)\n\nforever\n\nfall at speed [3]\n\nset y to (152)\n\nset y to (151)\n\nrepeat (2)\n\nwhen I receive [end v]\nrepeat (10)\n    change [ghost v] effect by (10)\nend\nwait (1) seconds\nstop [other scripts in sprite v]\nstop [this script v]\n\nchange x by (40)\n\nchange y by (-10)\n\n@goal\n\nwhen flag clicked\nforever\n    if <(Level:) = [1]> then\n        go to x: (200) y: (-50)\n    end\n    if <(Level:) = [2]> then\n        go to x: (200) y: (40)\n    end\n    if <(Level:) = [3]> then\n        go to x: (200) y: (-140)\n    end\n    if <(Level:) = [4]> then\n        go to x: (200) y: (-115)\n    end\n    if <(Level:) = [5]> then\n        go to x: (205) y: (-115)\n    end\n    if <(Level:) = [6]> then\n        go to x: (205) y: (-105)\n    end\n    if <(Level:) = [7]> then\n        go to x: (205) y: (-105)\n    end\n    if <(Level:) = [8]> then\n        go to x: (205) y: (0)\n    end\n    if <(Level:) = [9]> then\n        go to x: (205) y: (-125)\n    end\n    if <(Level:) = [10]> then\n        go to x: (205) y: (-130)\n    end\n    if <(Level:) = [11]> then\n        go to x: (205) y: (-80)\n    end\n    if <(Level:) = [12]> then\n        broadcast (END v)\n        set [end v] to [1]\n    end\nend\n\nif <(Level:) = [9]> then\n    go to x: (205) y: (-125)\nend\n\nwhen flag clicked\nclear graphic effects\n\nwhen I receive [next level v]\nhide\nset [color v] effect to (pick random (1) to (1000))\nshow\n\nwhen I receive [end v]\nrepeat (10)\n    change [ghost v] effect by (10)\nend\n\n@Levels \n\nwhen I receive [next level v]\nnext costume\n\nwhen flag clicked\ngo to x: (0) y: (0)\nswitch costume to (costume1 v)\n\nwhen I receive [end v]\nrepeat (10)\n    change [ghost v] effect by (10)\nend\n\n@Sprite2\n\nwhen flag clicked\nshow\ngo to x: (0) y: (0)\nwait (6) seconds\nhide\nbroadcast (begin v)\nforever\n    play sound [Chill v] until done\nend\n\n