Sticky: a platformer


@Stage\n\nwhen I receive [green flag v]\nforever\n    play sound [Best Day of My Life - American Authors v] until done\nend\n\n@blank\n\n@player\n\nwhen flag clicked\nbroadcast (intro v) and wait\nwait (1) seconds\nbroadcast (green flag v) and wait\n\ndefine tick\nchange [sx v] by ((<key (right arrow v) pressed?> * (2)) - (<key (left arrow v) pressed?> * (2)))\nset [sx v] to ((sx) * (0.8))\nchange x by (sx)\nchange [sy v] by ((<key (up arrow v) pressed?> * (([abs v] of <[-1] < (in air)> ) * (20))) - (2))\nchange y by (sy)\n\ndefine change x by (sx)\nchange [x v] by (sx)\nposition\nif <touching (ground v)?> then\n    repeat (12)\n        change [y v] by (1)\n        position\n        if <not <touching (ground v)?>> then\n            stop [this script v]\n        end\n    end\n    change [y v] by (-12)\n    if <key (up arrow v) pressed?> then\n        if <(sx) > [0]> then\n            set [sx v] to [-16]\n        else\n            set [sx v] to [16]\n        end\n        set [in air v] to [1]\n    else\n        change [x v] by ((sx) * (-1))\n        set [sx v] to [0]\n    end\nend\nposition\n\ndefine position\ngo to x: (x) y: (y)\nif <(y) > [190]> then\n    set [y v] to [190]\nend\nif <(y position) = (y)> then\n    show\nelse\n    hide\nend\n\ndefine change y by (sy)\nchange [y v] by (sy)\nchange [in air v] by (-1)\nposition\nif <touching (ground v)?> then\n    repeat ([ceiling v] of ([abs v] of (sy) ) )\n        set [in air v] to [0]\n        change [y v] by ((sy) * (-1))\n        set [sy v] to [0]\n        position\n    end\nend\n\n\n    position\nend\n\nset [in air v] to [1]\n\nerase all\nswitch costume to (ground v)\nstamp\nswitch costume to (player v)\n\ngo to x: (0) y: (100)\n\nrepeat until <not <touching (ground v)?>>\n    if <[0] < (sy)> then\n        change [y v] by (-1)\n    end\nend\n\ndefine game on\nset [x v] to [-220]\nset [y v] to [-60]\nset [in air v] to [-5]\nset [sx v] to [0]\nset [sy v] to [0]\nset [game v] to []\nshow\nclear graphic effects\nset [ghost v] effect to (0)\n\ngo to x: (0) y: (0)\n\nwhen I receive [green flag v]\nforever\n    game on\n    repeat until <(game) > []>\n        tick\n        position\n        test-win/lose\n    end\n    if <(game) = [win]> then\n        change [level v] by (1)\n        wait until <not <key (s v) pressed?>>\n    else\n        repeat (10)\n            change [ghost v] effect by (10)\n        end\n    end\nend\n\nwhen I receive [intro v]\nhide\n\ndefine test-win/lose\nif <<(x) > [240]> or <key (s v) pressed?>> then\n    set [game v] to [win]\nend\nif <<touching (dangerous stuff v)?> or <key (r v) pressed?>> then\n    set [game v] to [die]\nend\n\nchange [game v] by (1)\n\nset [in air v] to [0]\n\n@ground\n\nwhen I receive [intro v]\nhide\nset [level v] to [1]\ngo to x: (0) y: (0)\n\nwhen I receive [green flag v]\nshow\nforever\n    switch costume to (LEVEL)\nend\n\nswitch backdrop to ( v)\n\n@dangerous stuff\n\nwhen I receive [intro v]\nhide\nset [level v] to [1]\ngo to x: (0) y: (0)\n\nwhen I receive [green flag v]\nshow\nforever\n    switch costume to (LEVEL)\nend\n\nswitch backdrop to ( v)\n\n@text\n\ngo to x: (0) y: (0)\n\nwhen I receive [green flag v]\nshow\nforever\n    switch costume to (LEVEL)\n    change y by (([sin v] of (sin change) ) / (2))\n    change [sin change v] by (5)\nend\n\nwhen I receive [intro v]\nhide\nset [level v] to [1]\nset [sin change v] to [0]\ngo to x: (0) y: (0)\n\nswitch backdrop to ( v)\n\n@Intro\n\nwhen I start as a clone\nswitch costume to (8 v)\nhide\ngo to x: (243) y: (0)\nshow\nrepeat until <[-1] < (x speed)>\n    change x by (x speed)\n    change [x speed v] by (1)\nend\nchange x by (-1)\nrepeat until <(y position) < [-336]>\n    change [y speed v] by (-1)\n    change y by (y speed)\nend\ndelete this clone\n\ndelete this clone\n\n\n\nwhen I receive [intro v]\nstart sound [Intro music - PaulRHJT v]\nset volume to (100) %\nset [x speed v] to [-21]\nset [y speed v] to [0]\ncreate clone of (_myself_ v)\nswitch costume to (s v)\nset [x speed v] to [21]\nset [y speed v] to [0]\ngo to x: (-240) y: (0)\nshow\nrepeat until <(x speed) < [1]>\n    change x by (x speed)\n    change [x speed v] by (-1)\n    show\nend\nchange x by (1)\nrepeat until <(y position) < [-336]>\n    change [y speed v] by (-1)\n    change y by (y speed)\n    show\nend\nbroadcast (Logo v)\nstop [other scripts in sprite v]\nstop [this script v]\n\nswitch costume to (8 v)\ngo to x: (0) y: (0)\nshow\n\n@Enjoy intro\n\nwhen I receive [intro v]\nhide\nset [x speed v] to [-21]\ngo to x: (263) y: (-125)\nset size to (300) %\n\nwhen I receive [enjoy v]\nshow\nrepeat until <[-2] < (x speed)>\n    change x by (x speed)\n    change [x speed v] by (1)\nend\nrepeat (3)\n    change x by (x speed)\nend\nrepeat until <(x position) < [-262]>\n    change x by (x speed)\n    change [x speed v] by (-1)\nend\nhide\n\nchange [x speed v] by (1)\n\nrepeat (20)\n    change x by (x speed)\nend\n\n@Logo intro\n\nwhen I receive [intro v]\ngo to x: (0) y: (296)\nswitch costume to (logo v)\nhide\nset [y speed v] to [-20]\n\nwhen I receive [logo v]\nshow\nrepeat until <[-2] < (y speed)>\n    change [y speed v] by (1)\n    change y by (y speed)\n    show\nend\nbroadcast (enjoy v)\nrepeat (40)\n    change y by (y speed)\nend\nrepeat until <(y position) < [-271]>\n    change [y speed v] by (-1)\n    change y by (y speed)\nend\nhide\nbroadcast (Close window v)\nstop [other scripts in sprite v]\nstop [this script v]\n\n@Close window intro\n\nwhen I receive [intro v]\nhide\ngo to x: (-225) y: (0)\nswitch costume to (costume1 v)\n\nwhen I receive [close window v]\ngo to [front v] layer\ncreate clone of (_myself_ v)\nshow\npoint in direction (90)\nrepeat until <(x position) = [0]>\n    change x by (15)\nend\nwait (0.25) seconds\nrepeat (18)\n    turn right (10) degrees\nend\nbroadcast (backdrop v)\nwait (0.25) seconds\nrepeat until <(x position) = [225]>\n    change x by (15)\nend\nhide\n\nwhen I start as a clone\ngo to x: (225) y: (0)\nswitch costume to (costume2 v)\nshow\npoint in direction (90)\nrepeat until <(x position) = [0]>\n    change x by (-15)\nend\nwait (0.25) seconds\nrepeat (18)\n    turn right (10) degrees\nend\nwait (0.25) seconds\nrepeat until <(x position) = [-225]>\n    change x by (-15)\nend\nhide\n\n@Boom intro\n\nwhen I receive [intro v]\nset [y speed v] to [0]\nhide\ngo to [back v] layer\nforever\n    go to (random position v)\n    Clone\n    wait (0.1) seconds\nend\n\nwhen I start as a clone\nset [ghost v] effect to (0)\nset [y speed v] to [12]\npoint in direction (pick random (1) to (360))\nshow\nrepeat (100)\n    change [ghost v] effect by (1)\n    change [y speed v] by (-1)\n    change y by (y speed)\n    move (3) steps\n    if <touching (_edge_ v)?> then\n        delete this clone\n    end\nend\ndelete this clone\n\nwhen I receive [close window v]\nstop [other scripts in sprite v]\ndelete this clone\n\ndefine Clone\nrepeat (10)\n    create clone of (_myself_ v)\nend\n\n@thumbnail\n\nwhen flag clicked\nset [ghost v] effect to (100)\ngo to x: (0) y: (0)\nforever\n    go to [front v] layer\nend\n\n@pen\n\nwhen flag clicked\nerase all\n\nadd [thing] to [particle x, y, speed, size v]\n\nwhen flag clicked\n\ndefine render\nerase all\nset [i v] to [1]\nrepeat ((length of [particle x, y, speed, size v]) / (3))\n    pen up\n    go to x: (item (i) of [particle x, y, speed, size v]) y: (item ((i) + (1)) of [particle x, y, speed, size v])\n    set pen size to ((item ((i) + (2)) of [particle x, y, speed, size v]) * (2))\n    set pen (transparency v) to (80)\n    pen down\n    pen up\n    change [i v] by (3)\nend\n\nwait (0.1) seconds\n\ndefine change\nset [i v] to [1]\nrepeat ((length of [particle x, y, speed, size v]) / (3))\n    if <(item (i) of [particle x, y, speed, size v]) > [-240]> then\n        replace item (i) of [particle x, y, speed, size v] with ((item (i) of [particle x, y, speed, size v]) - (item ((i) + (2)) of [particle x, y, speed, size v]))\n    else\n        delete (i) of [particle x, y, speed, size v]\n        delete ((i) + (1)) of [particle x, y, speed, size v]\n        delete ((i) + (2)) of [particle x, y, speed, size v]\n    end\n    change [i v] by (3)\nend\n\nadd (pick random (10) to (30)) to [particle x, y, speed, size v]\n\nwhen I receive [green flag v]\nset pen color to (#8d8ce5)\ndelete all of [particle x, y, speed, size v]\nforever\n    add [240] to [particle x, y, speed, size v]\n    add (pick random (-180) to (180)) to [particle x, y, speed, size v]\n    add (pick random (5) to (10)) to [particle x, y, speed, size v]\n    wait (0.05) seconds\nend\n\nwhen I receive [green flag v]\nhide\nforever\n    render\n    change\nend\n\n