Scrolling Platformer

Instructions: Directions:\n*WASD or ARROW KEYS to move\n*Don't touch the spikes/saws!\n*Try to collect all the coins\n=========================================

@Stage\n\nwhen flag clicked\nforever\n    broadcast (Update v)\nend\n\n@Player\n\nwhen flag clicked\nbroadcast (Start v)\n\nwhen I receive [start v]\nset [xv v] to [0]\nset [yv v] to [0]\nset [slope v] to [5]\nset [can jump v] to [yes]\nset [scrollx v] to [0]\nset [scrolly v] to [0]\nshow\nrepeat (4)\n    set [ghost v] effect to (100)\n    wait (0.2) seconds\n    clear graphic effects\n    wait (0.05) seconds\nend\n\ndefine Movement\nswitch costume to (hitbox v)\nset rotation style [don't rotate v]\nif <<key (right arrow v) pressed?> or <key (d v) pressed?>> then\n    change [xv v] by (1)\n    point in direction (90)\nend\nif <<key (left arrow v) pressed?> or <key (a v) pressed?>> then\n    change [xv v] by (-1)\n    point in direction (-90)\nend\nset [xv v] to ((Xv) * (.9))\nX-Collision\nchange [yv v] by (-1)\nY-Collision <(Yv) > [0]>\nchange [scrollx v] by ((x position) * (-1))\nchange [scrolly v] by ((y position) * (-1))\ngo to x: (0) y: (0)\n\nwhen I receive [start v]\nforever\n    Movement\nend\n\ndefine X-Collision\nchange x by (Xv)\nrepeat until <<(Slope) > [8]> or <not <<touching (ground v)?> or <touching (moving platform v)?>>>>\n    change [slope v] by (1)\n    change y by (1)\nend\nif <<touching (ground v)?> or <touching (moving platform v)?>> then\n    change y by ((Slope) * (-1))\n    set [slope v] to [0]\n    change x by ((Xv) * (-1))\n    set [xv v] to [0]\nend\n\ndefine Y-Collision <going up?>\nchange y by (Yv)\nif <<touching (ground v)?> or <touching (moving platform v)?>> then\n    set [can jump v] to [yes]\n    set [yv v] to [0]\n    repeat until <not <<touching (ground v)?> or <touching (moving platform v)?>>>\n        if <going up?> then\n            change y by (-1)\n        else\n            change y by (1)\n        end\n    end\n    if <<key (up arrow v) pressed?> or <key (w v) pressed?>> then\n        if <<(Can Jump) = [yes]> and <not <going up?>>> then\n            set [yv v] to [15]\n            set [can jump v] to [no]\n        end\n    end\nend\nset rotation style [left-right v]\nswitch costume to (Animation #)\n\nwhen I receive [start v]\nforever\n    set [animation # v] to [2]\n    wait (pick random (3) to (5)) seconds\n    set [animation # v] to [3]\n    wait (0.02) seconds\n    set [animation # v] to [4]\n    wait (0.02) seconds\n    set [animation # v] to [5]\n    wait (0.04) seconds\n    set [animation # v] to [6]\n    wait (0.03) seconds\nend\n\nwhen I receive [start v]\nwait (1) seconds\nforever\n    if <<touching (water v)?> or <touching (obstacles v)?>> then\n        set rotation style [all around v]\n        stop [other scripts in sprite v]\n        set [yv v] to [10]\n        repeat until <touching (_edge_ v)?>\n            go to [front v] layer\n            turn left (3) degrees\n            change y by (Yv)\n            change [yv v] by (-1)\n        end\n        hide\n        wait (1) seconds\n        broadcast (Start v)\n    end\nend\n\n@Ground\n\nwhen I receive [update v]\nif <(Ground Clone #) = [0]> then\n    go to x: (ScrollX) y: (ScrollY)\n    switch costume to (mid v)\nelse\n    if <(Ground Clone #) = [1]> then\n        go to x: ((ScrollX) + (485)) y: (ScrollY)\n        switch costume to (right v)\n    else\n        if <(Ground Clone #) = [2]> then\n            go to x: ((ScrollX) - (485)) y: (ScrollY)\n            switch costume to (left v)\n        end\n    end\nend\n\nwhen I receive [start v]\ngo to [front v] layer\nswitch costume to (mid v)\nset [ground clone # v] to [0]\nrepeat (2)\n    change [ground clone # v] by (1)\n    create clone of (_myself_ v)\nend\nset [ground clone # v] to [0]\n\n@Tree BACKGROUND\n\nwhen I receive [update v]\ngo to x: ((ScrollX) * (.2)) y: ((ScrollY) * (.2))\ngo [backward v] (2) layers\n\n@Mountain BACKGROUND\n\nwhen I receive [update v]\ngo to x: ((ScrollX) * (.1)) y: ((ScrollY) * (.1))\ngo [backward v] (3) layers\n\n@Ground1 Bushes\n\nwhen I receive [update v]\ngo to x: (ScrollX) y: (ScrollY)\ngo [backward v] (1) layers\n\n@Ground2 Bushes\n\nwhen I receive [update v]\ngo to x: ((ScrollX) + (485)) y: (ScrollY)\ngo [backward v] (1) layers\n\n@Ground3 Bushes\n\nwhen I receive [update v]\ngo to x: ((ScrollX) - (485)) y: (ScrollY)\ngo [backward v] (1) layers\n\n@Obstacles\n\nwhen I receive [start v]\nhide\nrepeat (10)\n    delete this clone\nend\nset [obstacle type v] to [Spike]\ncreate clone of (_myself_ v)\nwait (0.1) seconds\nset [obstacle type v] to [Saw]\ncreate clone of (_myself_ v)\n\nwhen I receive [update v]\nif <(Obstacle Type) = [Spike]> then\n    switch costume to (spike r v)\n    go to x: ((ScrollX) + (485)) y: (ScrollY)\nelse\n    if <(Obstacle Type) = [Saw]> then\n        switch costume to (saw l v)\n        go to x: ((ScrollX) - (190)) y: ((ScrollY) + (60))\n    end\nend\n\nwhen I start as a clone\nshow\nif <(Obstacle Type) = [Saw]> then\n    forever\n        turn right (15) degrees\n    end\nend\n\n@Water\n\nwhen I receive [start v]\nset [water x v] to [-485]\nset [water y v] to [0]\nforever\n    repeat (10)\n        change [water y v] by (.5)\n    end\n    repeat (10)\n        change [water y v] by (-.5)\n    end\nend\n\nwhen I receive [update v]\ngo to x: ((water X) + (ScrollX)) y: ((water Y) + (ScrollY))\n\n@Moving Platform\n\nwhen I receive [update v]\ngo to x: ((Moving Platform X) + (ScrollX)) y: ((Moving Platform Y) + (ScrollY))\n\nwhen I receive [start v]\nset [moving platform x v] to [-50]\nset [moving platform y v] to [130]\nforever\n    repeat (75)\n        change [moving platform x v] by (2)\n    end\n    repeat (75)\n        change [moving platform x v] by (-2)\n    end\nend\n\n@Coins\n\nwhen I receive [start v]\nhide\nrepeat (10)\n    delete this clone\nend\nCreate Coin At: [-165] [-50]\nCreate Coin At: [220] [215]\nCreate Coin At: [-650] [-50]\nCreate Coin At: [-470] [50]\nCreate Coin At: [485] [-15]\n\ndefine Create Coin At: (x) (y)\nset [coinx v] to (x)\nset [coiny v] to (y)\ncreate clone of (_myself_ v)\n\nwhen I start as a clone\nshow\nswitch costume to (coin1 v)\nset size to (100) %\nforever\n    if <not <(costume [number v]) = [10]>> then\n        next costume\n        if <(costume [number v]) > [8]> then\n            switch costume to (coin1 v)\n        end\n    end\n    go to x: ((ScrollX) + (CoinX)) y: ((ScrollY) + (CoinY))\nend\n\nwhen I start as a clone\nforever\n    if <touching (player v)?> then\n        switch costume to (sparkle v)\n        repeat (10)\n            change [ghost v] effect by (10)\n            change size by (4)\n        end\n        delete this clone\n    end\nend\n\nwhen I start as a clone\nforever\n    repeat (10)\n        change [coiny v] by (.5)\n    end\n    repeat (10)\n        change [coiny v] by (-.5)\n    end\nend\n\n@Outline\n\nwhen I receive [start v]\nshow\ngo to x: (0) y: (0)\nforever\n    go to [front v] layer\nend\n\nwhen [timer v] > (0.1)\nhide\n\n@Thumbnail\n\nwhen flag clicked\nhide\nforever\n    go to [front v] layer\n    reset timer\nend\n\nwhen [timer v] > (0.1)\nshow\ngo to [front v] layer\n\n