How to PLATFORMER | Ep. 2


@Stage\n\n@Player\n\ndefine Switch Level\nif <(x) > [240]> then\n    set [x v] to [-240]\n    change [_level x v] by (1)\n    set [_exit v] to [1]\nelse\n    if <(x) < [-240]> then\n        set [x v] to [240]\n        change [_level x v] by (-1)\n        set [_exit v] to [1]\n    end\nend\nif <(y) > [180]> then\n    set [y v] to [-180]\n    change [_level y v] by (1)\n    set [_exit v] to [1]\nelse\n    if <(y) < [-180]> then\n        set [y v] to [180]\n        change [_level y v] by (-1)\n        set [_exit v] to [1]\n    end\nend\n\ndefine Spawn Player\nset size to (50) %\ngo to [front v] layer\nset rotation style [left-right v]\nset [_level x v] to [0]\nset [_level y v] to [0]\nset [x v] to [0]\nset [y v] to [0]\nset [xv v] to [0]\nset [yv v] to [0]\ngo to x: (x) y: (y)\n\nwhen flag clicked\nSpawn Player\nforever\n    set [_exit v] to [0]\n    clear graphic effects\n    broadcast (BEGIN LEVEL v) and wait\n    repeat until <(_EXIT) > [0]>\n        switch costume to (hitbox v)\n        if <<key (right arrow v) pressed?> or <key (d v) pressed?>> then\n            point in direction (90)\n            change [xv v] by (2.5)\n        else\n            if <<key (left arrow v) pressed?> or <key (a v) pressed?>> then\n                point in direction (-90)\n                change [xv v] by (-2.5)\n            end\n        end\n        Change X by (xv)\n        set [xv v] to ((xv) * (0.7))\n        change [yv v] by (-1)\n        if <<key (up arrow v) pressed?> or <key (w v) pressed?>> then\n            if <(in air) < [4]> then\n                set [yv v] to [11]\n            end\n        end\n        change [in air v] by (1)\n        Change Y by (yv)\n        Switch Level\n        if <touching (obstacles v)?> then\n            set [_exit v] to [2]\n        end\n        switch costume to (player v)\n    end\n    if <(_EXIT) = [2]> then\n        repeat (10)\n            change y by (2)\n            change [ghost v] effect by (10)\n        end\n        Spawn Player\n    end\nend\n\ndefine Check Solid\ngo to x: (x) y: (y)\nif <touching (level v)?> then\n    set [solid v] to [1]\nelse\n    set [solid v] to [0]\nend\n\ndefine Change Y by (y)\nchange [y v] by (y)\nCheck Solid\nif <(solid) > [0]> then\n    set [yv v] to [0]\n    if <not <(y) > [0]>> then\n        set [in air v] to [0]\n    end\n    repeat ([ceiling v] of ([abs v] of (y) ) )\n        if <(solid) > [0]> then\n            change [y v] by ((0) - ((y) / ([abs v] of (y) )))\n            Check Solid\n        else\n            stop [this script v]\n        end\n    end\nend\n\ndefine Change X by (x)\nchange [x v] by (x)\nCheck Solid\nif <(solid) > [0]> then\n    set [xv v] to [0]\n    repeat ([ceiling v] of ([abs v] of (x) ) )\n        if <(solid) > [0]> then\n            change [x v] by ((0) - ((x) / ([abs v] of (x) )))\n            Check Solid\n        else\n            stop [this script v]\n        end\n    end\nend\n\n@Level\n\nwhen I receive [begin level v]\nset [costume v] to (join (join [x] (_LEVEL X)) (join [ y] (_LEVEL Y)))\nswitch costume to (costume)\nif <(costume [name v]) = (costume)> then\n    show\nelse\n    hide\nend\n\n@Obstacles\n\nwhen I receive [begin level v]\nset [costume v] to (join (join [x] (_LEVEL X)) (join [ y] (_LEVEL Y)))\nswitch costume to (costume)\nif <(costume [name v]) = (costume)> then\n    show\nelse\n    hide\nend\n\n@Thumbnail\n\nwhen flag clicked\nswitch costume to (costume1 v)\nhide\n\n