CUBETALE - scrolling platformer


@Stage\n\nwhen flag clicked\nbroadcast (Start v)\n\nwhen I receive [start v]\nforever\n    play sound [Specification v] until done\nend\n\n@Player\n\ndefine Setup\nif <(Stage) = [10]> then\n    go to x: (180) y: (-50)\nelse\n    go to x: (((((Stage) mod (2)) * (2)) - (1)) * (-200)) y: (-50)\nend\nset [player_x v] to [0]\nset [player_y v] to [0]\nset [player_jump v] to [0]\nset [ghost v] effect to (100)\nshow\n\ndefine Stage? (i) (x_speed) (y_jumping power)\nset [player_walljump? v] to [0]\nset [i v] to [0]\nrepeat until <<(i) < (i)> or <not <touching (stage v)?>>>\n    change y by (1)\n    change [i v] by (1)\nend\nif <(i) < (i)> then\n    change x by (() - (Player_x))\n    change y by (() - (i))\n    if <<<key (up arrow v) pressed?> or <key (w v) pressed?>> or <<mouse down?> and <[0] < (mouse y)>>> then\n        set [player_walljump? v] to (((Player_x) / ([abs v] of (Player_x) )) * (15))\n        set [player_x v] to (((Player_x) / ([abs v] of (Player_x) )) * ((x_speed) * (-1)))\n        set [player_y v] to (y_jumping power)\n    end\nend\n\nset [player_y v] to [0]\n\ndefine Plat (x_speed) (x_friction) (y_gravity) (y_jumping power)\nchange [player_y v] by (y_gravity)\nif <[0] < (Player_walljump?)> then\n    change [player_walljump? v] by (-1)\nelse\n    if <(Player_walljump?) < [0]> then\n        change [player_walljump? v] by (1)\n    else\n        set [player_walljump? v] to [0]\n    end\nend\nif <<<key (right arrow v) pressed?> or <key (d v) pressed?>> or <<mouse down?> and <[0] < (mouse x)>>> then\n    if <([abs v] of (Player_walljump?) ) < [1]> then\n        change [player_x v] by ((x_speed) * (1))\n    end\nend\nif <<<key (left arrow v) pressed?> or <key (a v) pressed?>> or <<mouse down?> and <(mouse x) < [0]>>> then\n    if <([abs v] of (Player_walljump?) ) < [1]> then\n        change [player_x v] by ((x_speed) * (-1))\n    end\nend\nif <(Player_walljump?) = [0]> then\n    set [player_x v] to ((Player_x) * (x_friction))\nend\nchange x by (Player_x)\nif <<[210] < ([abs v] of (x position) )> and <(Stage) < [10]>> then\n    set x to (((x position) / ([abs v] of (x position) )) * (210))\nend\nif <touching (stage v)?> then\n    Stage? [5] [5] [10]\nend\nchange y by (Player_y)\nif <touching (stage v)?> then\n    change y by (() - (Player_y))\n    set [player_walljump? v] to [0]\n    set [player_y v] to [0]\nend\nchange y by (-1)\nif <touching (stage v)?> then\n    if <<<key (up arrow v) pressed?> or <key (w v) pressed?>> or <<mouse down?> and <[0] < (mouse y)>>> then\n        broadcast (jump v)\n        change [player_jump v] by (1)\n        set [player_y v] to (y_jumping power)\n    end\nend\nchange y by (1)\nif <<<(y position) < [-175]> or <<touching (spike v)?> or <touching (magma v)?>>> or <key (r v) pressed?>> then\n    wait until <not <key (r v) pressed?>>\n    start sound [Oops v]\n    broadcast (delete v) and wait\n    create clone of (player_ v)\n    Setup\n    set [player? v] to [y]\n    broadcast (Player wait v)\n    broadcast (re v)\nend\nif <<[235] < (x position)> and <(Stage) = [10]>> then\n    broadcast (delete v) and wait\n    set [clear? v] to [y]\n    broadcast (clear v)\nend\n\nwhen I receive [start v]\nset [clear? v] to [n]\nset [stage v] to [1]\nSetup\nbroadcast (message1 v)\n\nwhen flag clicked\nhide\n\nwhen I receive [message1 v]\nPlat [6] [0.5] [-1] [13]\nbroadcast (message2 v)\n\nwhen I receive [ready v]\nSetup\nset [player? v] to [y]\nbroadcast (Player wait v)\n\nwhen I receive [clear v]\ngo to x: (-240) y: (-95)\npoint in direction (90)\nglide (2) secs to x: (0) y: (y position)\nwait (1) seconds\npoint in direction (-90)\nwait (0.5) seconds\nbroadcast (end v)\ncreate clone of (! v)\nwait (1) seconds\npoint in direction (90)\nglide (2) secs to x: (240) y: (y position)\nbroadcast (... v)\nhide\n\nwhen I receive [player wait v]\nwait (0.5) seconds\nset [player? v] to [n]\n\n@Player_\n\ndefine Setup\ngo to (player v)\nshow\n\nwhen I receive [start v]\nSetup\n\nwhen flag clicked\nhide\n\nwhen I start as a clone\nswitch costume to (x v)\nset [ghost v] effect to (50)\nset [clone_y v] to [5]\nrepeat until <touching (_edge_ v)?>\n    change y by (Clone_y)\n    turn right (4) degrees\n    change [clone_y v] by (-1)\nend\ndelete this clone\n\nwhen I receive [message2 v]\nif <(costume [name v]) = [-]> then\n    if <(Player?) = [n]> then\n        go to x: ([x position v] of [player v]) y: ([y position v] of [player v])\n    else\n        change x by ((([x position v] of [player v]) - (x position)) / (2))\n        change y by ((([y position v] of [player v]) - (y position)) / (2))\n    end\nend\n\nwhen I receive [clear v]\nforever\n    go to (player v)\nend\n\nwhen I receive [... v]\nhide\n\n@Player_eyes\n\ndefine Setup\ngo to (player v)\ngo to [front v] layer\nshow\nset [eyes_x v] to [0]\nset [eyes_y v] to [0]\n\nwhen I receive [start v]\nSetup\n\nwhen flag clicked\nhide\n\nwhen I receive [message2 v]\nchange [eyes_x v] by (((Player_x) - (eyes_x)) / (5))\nchange [eyes_y v] by (((Player_y) - (eyes_y)) / (5))\nif <(Player?) = [n]> then\n    go to x: (([x position v] of [player v]) + ((eyes_x) * (1.2))) y: (([y position v] of [player v]) + ((eyes_y) * (1.2)))\nelse\n    change x by (((([x position v] of [player v]) + (eyes_x)) - (x position)) / (2))\n    change y by (((([y position v] of [player v]) + (eyes_y)) - (y position)) / (2))\nend\nif <(Clear?) = [n]> then\n    broadcast (message1 v)\nend\n\nwhen I receive [clear v]\nforever\n    go to (player v)\n    change x by ((([direction v] of [player v]) / (90)) * (5))\nend\n\nwhen I receive [... v]\nhide\n\n@Stage\n\nwhen I receive [start v]\ngo to [front v] layer\nswitch costume to (stage0 v)\nshow\n\nwhen I receive [re v]\ngo to x: (0) y: (0)\nswitch costume to ((21) + (Stage))\ncreate clone of (_myself_ v)\nswitch costume to ((11) + (Stage))\ncreate clone of (_myself_ v)\nswitch costume to ((1) + (Stage))\n\nwhen I receive [delete v]\ndelete this clone\n\nwhen I start as a clone\nif <(costume [number v]) < [21]> then\n    if <(Stage) = [2]> then\n        wait until <<([x position v] of [player v]) < [30]> and <(Player_y) = [0]>>\n        wait (0.3) seconds\n        repeat until <([x position v] of [player v]) < [-100]>\n            change y by (((-100) - (y position)) / (5))\n        end\n        \n            change y by (((0) - (y position)) / (5))\n        end\n    else\n        if <(Stage) = [3]> then\n            wait until <[0] < (Player_jump)>\n            repeat until <(Player_y) < [0]>\n                change y by (((-100) - (y position)) / (5))\n            end\n            \n                change y by (((0) - (y position)) / (5))\n            end\n        else\n            if <(Stage) = [5]> then\n                \n                    go to x: (pick random (-1) to (1)) y: (pick random (-1) to (1))\n                end\n            else\n                if <(Stage) = [6]> then\n                    wait until <[0] < (Player_jump)>\n                    wait until <(Player_y) < [0]>\n                    \n                        change y by (((-100) - (y position)) / (5))\n                    end\n                else\n                    if <(Stage) = [7]> then\n                        repeat (2)\n                            wait until <[-100] < ([x position v] of [player v])>\n                            wait until <(Player_y) < [-5]>\n                        end\n                        repeat until <(Player_y) = [0]>\n                            change x by (((-50) - (x position)) / (5))\n                        end\n                        \n                            change x by (((0) - (x position)) / (5))\n                        end\n                    else\n                        if <(Stage) = [8]> then\n                            set [mine v] to (days since 2000)\n                            wait until <[2] < (((days since 2000) - (Mine)) * (86400))>\n                            repeat until <<([x position v] of [player v]) < [-30]> and <[100] < (y position)>>\n                                change y by (((150) - (y position)) / (5))\n                            end\n                            \n                                change y by (((0) - (y position)) / (3))\n                            end\n                        else\n                            if <(Stage) = [9]> then\n                                wait until <[30] < ([x position v] of [player v])>\n                                wait until <[0] < (Player_y)>\n                                repeat until <(Player_y) < [0]>\n                                    change y by (((-100) - (y position)) / (5))\n                                end\n                                \n                                    change y by (((0) - (y position)) / (5))\n                                end\n                            end\n                        end\n                    end\n                end\n            end\n        end\n    end\n    delete this clone\nend\n\nwhen I receive [go v]\nswitch costume to (stage1 v)\n\nwhen I start as a clone\nif <[20] < (costume [number v])> then\n    if <(Stage) = [3]> then\n        wait until <[0] < (Player_jump)>\n        wait until <(Player_y) < [0]>\n        repeat until <[30] < ([x position v] of [player v])>\n            change y by (((-100) - (y position)) / (5))\n        end\n        \n            change y by (((0) - (y position)) / (5))\n        end\n    else\n        if <(Stage) = [5]> then\n            go to x: (0) y: (300)\n            hide\n            set [mine v] to [-20]\n            wait until <[50] < ([x position v] of [player v])>\n            wait (0.2) seconds\n            show\n            repeat until <(y position) < [0]>\n                change y by (Mine)\n                change [mine v] by (-1)\n            end\n            set [mine v] to [5]\n            repeat until <(y position) < [-100]>\n                change y by (Mine)\n                change [mine v] by (-1)\n            end\n        else\n            if <(Stage) = [6]> then\n                repeat until <[0] < (Player_jump)>\n                    set x to ([x position v] of [player v])\n                end\n                wait until <(Player_y) < [0]>\n                \n                    change y by (((-100) - (y position)) / (5))\n                end\n            else\n                if <(Stage) = [7]> then\n                    repeat (2)\n                        wait until <[-100] < ([x position v] of [player v])>\n                        wait until <(Player_y) < [-5]>\n                    end\n                    repeat until <(Player_y) = [0]>\n                        change x by (((50) - (x position)) / (5))\n                    end\n                    \n                        change x by (((0) - (x position)) / (5))\n                    end\n                else\n                    if <(Stage) = [9]> then\n                        wait until <[30] < ([x position v] of [player v])>\n                        wait until <[0] < (Player_y)>\n                        wait until <(Player_y) < [0]>\n                        repeat until \n                            change y by (((-100) - (y position)) / (5))\n                        end\n                    end\n                end\n            end\n        end\n    end\n    delete this clone\nend\n\nwhen I receive [clear v]\nswitch costume to (stage0 v)\n\nwhen flag clicked\nhide\n\n@Spike\n\nwhen I receive [go v]\nshow\n\nwhen I receive [re v]\ngo to x: (0) y: (-38)\npoint in direction (90)\nswitch costume to (Stage)\nhide\nif <(Stage) = [4]> then\n    wait until <[0] < (Player_jump)>\n    wait until <(Player_y) < [0]>\n    show\n    repeat until <(Player_y) = [0]>\n        change y by (((0) - (y position)) / (5))\n    end\n    \n        change y by (((-38) - (y position)) / (5))\n    end\nelse\n    if <(Stage) = [5]> then\n        go to x: (0) y: (300)\n        hide\n        set [mine v] to [-20]\n        wait until <[50] < ([x position v] of [player v])>\n        wait (0.2) seconds\n        show\n        repeat until <(y position) < [0]>\n            change y by (Mine)\n            change [mine v] by (-1)\n        end\n        set [mine v] to [5]\n        repeat until <(y position) < [-100]>\n            change y by (Mine)\n            change [mine v] by (-1)\n        end\n    else\n        if <(Stage) = [8]> then\n            go to x: (0) y: (-150)\n            point in direction (90)\n            hide\n            set [mine v] to (days since 2000)\n            wait until <[4] < (((days since 2000) - (Mine)) * (86400))>\n            go to [back v] layer\n            show\n            repeat (90)\n                turn right (2) degrees\n            end\n        else\n            if <(Stage) = [9]> then\n                go to x: (0) y: (-130)\n                go to [back v] layer\n                show\n                repeat until <[-50] < ([x position v] of [player v])>\n                    turn right (2) degrees\n                end\n                repeat until <[30] < ([x position v] of [player v])>\n                    turn left (4) degrees\n                end\n                \n                    change y by (-5)\n                    turn right (2) degrees\n                end\n            end\n        end\n    end\nend\ndelete this clone\n\nwhen I receive [start v]\ngo to x: (0) y: (0)\nswitch costume to (stage1 v)\n\nwhen I receive [delete v]\nhide\nstop [other scripts in sprite v]\ndelete this clone\n\nwhen flag clicked\nhide\n\n@Magma\n\nwhen I receive [go v]\nshow\n\nwhen I receive [start v]\ngo to x: (0) y: (0)\nswitch costume to (stage1 v)\n\nwhen flag clicked\nhide\n\nwhen I receive [end v]\nwait (1) seconds\nswitch costume to (stage2 v)\ngo to x: (-450) y: (0)\nglide (6) secs to x: (320) y: (0)\n\n@TN\n\nwhen flag clicked\nset [ghost v] effect to (100)\nshow\nforever\n    go to [front v] layer\nend\n\n@C25\n\nwhen flag clicked\nhide\n\nwhen I receive [start v]\ngo to x: (200) y: (-140)\nset [ghost v] effect to (50)\nset size to (0) %\nshow\nforever\n    change size by (((40) - (size)) / (5))\n    if <touching (mouse-pointer v)?> then\n        set [ghost v] effect to (25)\n        repeat until <not <touching (mouse-pointer v)?>>\n            change size by (((50) - (size)) / (5))\n        end\n        set [ghost v] effect to (50)\n    end\n    go to [front v] layer\n    go [backward v] (1) layers\nend\n\nwhen I receive [end v]\nstop [other scripts in sprite v]\nrepeat (50)\n    change [ghost v] effect by (2)\nend\nhide\n\n@exposition\n\nwhen flag clicked\nhide\n\nwhen I receive [start v]\ngo to x: (0) y: (50)\nswitch costume to (stage1 v)\nset [ghost v] effect to (100)\ngo to [front v] layer\nshow\nset [player_x v] to [0]\nrepeat until <[0] < ([abs v] of (Player_x) )>\n    change y by ((() - (y position)) / (5))\n    change [ghost v] effect by (-10)\nend\ng\nrepeat until <[1] < (Player_y)>\n    change y by ((() - (y position)) / (5))\n    change [ghost v] effect by (-10)\nend\ng\nbroadcast (ready v) and wait\nbroadcast (go v)\nrepeat until <[0] < ([x position v] of [player v])>\n    change y by ((() - (y position)) / (5))\n    change [ghost v] effect by (-10)\nend\ng\nwait until <[190] < ([x position v] of [player v])>\nrepeat until <([x position v] of [player v]) < [40]>\n    change y by ((() - (y position)) / (5))\n    change [ghost v] effect by (-10)\nend\ng\nhide\n\ndefine g\nrepeat (5)\n    change y by ((() - (y position)) / (5))\n    change [ghost v] effect by (-20)\nend\nrepeat (5)\n    change y by (-3)\n    change [ghost v] effect by (20)\nend\nnext costume\n\n@Wall\n\nwhen flag clicked\ngo to x: (-240) y: (0)\nhide\n\nwhen I receive [go v]\nshow\nrepeat (9)\n    repeat until <<[190] < ([abs v] of ([x position v] of [player v]) )> and <(([x position v] of [player v]) / ([abs v] of ([x position v] of [player v]) )) = ((((Stage) mod (2)) * (2)) - (1))>>\n        if <([abs v] of ([x position v] of [player v]) ) < [190]> then\n            change x by (((((((Stage) mod (2)) * (2)) - (1)) * (-260)) - (x position)) / (5))\n        else\n            change x by (((((((Stage) mod (2)) * (2)) - (1)) * (-230)) - (x position)) / (5))\n        end\n        change y by (((0) - (y position)) / (5))\n    end\n    change [stage v] by (1)\n    set [player_jump v] to [0]\n    broadcast (delete v) and wait\n    broadcast (re v)\n    set x to (((((Stage) mod (2)) * (2)) - (1)) * (-230))\n    set y to (-300)\nend\nhide\n\nset [stage v] to [1]\n\n@end\n\nwhen flag clicked\nhide\n\nwhen I receive [end v]\nswitch costume to (1 v)\nset [ghost v] effect to (100)\ngo to [front v] layer\nshow\nrepeat until <[239] < ([x position v] of [player v])>\n    set [ghost v] effect to ((([x position v] of [player v]) * ((-100) / (240))) + (100))\n    go to [front v] layer\nend\nclear graphic effects\nwait (3) seconds\nrepeat (50)\n    change [brightness v] effect by (-2)\nend\nstop [all v]\n\n@!\n\nwhen I start as a clone\ngo to x: (0) y: (-60)\nshow\nrepeat (20)\n    change [ghost v] effect by (5)\n    change y by (((-25) - (y position)) / (5))\nend\ndelete this clone\n\n