Scrolling Platformer


@Stage\n\n@Platforms\n\nwhen flag clicked\nshow\nswitch costume to (level 1 1 v)\nforever\n    go to x: ((scrollx) * (-1)) y: ((scrolly) * (-1))\nend\n\nwhen I receive [next v]\nnext costume\n\n@Exit\n\nwhen flag clicked\ngo to [front v] layer\ngo [backward v] (10) layers\nforever\n    go to x: (((scrollx) * (-1)) + (100)) y: (0)\nend\n\nwhen flag clicked\nswitch costume to (exit v)\nforever\n    set [exit? v] to [0]\n    if <touching (player v)?> then\n        broadcast (2 v)\n        set [exit? v] to [1]\n        switch costume to (exit v)\n        repeat (7)\n            next costume\n            wait (0.02) seconds\n        end\n        broadcast (message1 v)\n        wait (1) seconds\n        repeat (7)\n            switch costume to ((costume [number v]) - (1))\n            wait (0.02) seconds\n        end\n        switch costume to (exit v)\n    end\nend\n\n@Player\n\nwhen flag clicked\nshow\ngo to x: (-100) y: (0)\nset [scrollx v] to [0]\nset [x v] to [0]\nset [y v] to [0]\nforever\n    if <(exit?) = [0]> then\n        change [y v] by (-1)\n        if <key (left arrow v) pressed?> then\n            change [x v] by (-1)\n        end\n        if <key (right arrow v) pressed?> then\n            change [x v] by (1)\n        end\n        set [x v] to ((x) * (0.9))\n        change [scrollx v] by (x)\n        if <<touching (platforms v)?> and <not <touching color (#ff0000)?>>> then\n            change y by (1)\n        end\n        if <<touching (platforms v)?> and <not <touching color (#ff0000)?>>> then\n            change y by (1)\n        end\n        if <<touching (platforms v)?> and <not <touching color (#ff0000)?>>> then\n            change y by (1)\n        end\n        if <<touching (platforms v)?> and <not <touching color (#ff0000)?>>> then\n            change y by (1)\n        end\n        if <<touching (platforms v)?> and <not <touching color (#ff0000)?>>> then\n            change y by (-4)\n            change [scrollx v] by ((x) * (-1))\n            if <key (up arrow v) pressed?> then\n                set [y v] to [15]\n                if <([abs v] of (x) ) = (x)> then\n                    set [x v] to [-10]\n                else\n                    set [x v] to [10]\n                end\n            else\n                set [x v] to [0]\n            end\n        end\n        change y by (y)\n        if <<touching (platforms v)?> and <not <touching color (#ff0000)?>>> then\n            change y by ((y) - ((y) * (2)))\n            set [y v] to [0]\n        end\n        change y by (-1)\n        if <<key (up arrow v) pressed?> and <<touching (platforms v)?> and <not <touching color (#ff0000)?>>>> then\n            set [y v] to [15]\n        end\n        change y by (1)\n    else\n        set [x v] to [0]\n        set [y v] to [0]\n    end\nend\n\nwhen I receive [next v]\nset [scrollx v] to [0]\n\nwhen flag clicked\nforever\n    if <<<(round (y position)) = [-179]> or <touching color (#ff0000)?>> or <key (r v) pressed?>> then\n        go to x: (-100) y: (0)\n        set [scrollx v] to [0]\n    end\nend\n\n@Sprite1\n\nwhen flag clicked\nset [ghost v] effect to (100)\nforever\n    go to x: (0) y: (0)\n    go to [front v] layer\nend\n\nwhen I receive [2 v]\nrepeat (40)\n    change [ghost v] effect by (-2.5)\nend\nbroadcast (next v)\nrepeat (40)\n    change [ghost v] effect by (2.5)\nend\n\n