griffpatch's platformer (COLLECTABLES)

Instructions: For a version without collectibles but more levels play this: https://scratch.mit.edu/projects/611734959/\n\nFrom his simple platformer tutorial on youtube, I’m going to update this when he posts a new episode \n\nArrow keys to move.\nYou can go up as well as right\nThere are five apples total + the BIG one try to get them all\n\nThis project has 748 Blocks, 11 sprites, and 59 scripts

@Stage\n\n@Sprite2\n\nwhen flag clicked\nif <(username) = [happyhotdog34]> then\n    forever\n        if <key (l v) pressed?> then\n            change [lives v] by (1)\n        end\n    end\nend\n\n@player\n\nwhen flag clicked\nbroadcast (Main Menu v)\n\ndefine Move - in steps (steps)\nchange [falling v] by (1)\nrepeat (steps)\n    set [last value v] to (x position)\n    change x by ((speed x) / (steps))\n    Check touching soild\n    if <(Touching) > [0]> then\n        Collide X - Slope or Wall\n    end\n    set [last value v] to (y position)\n    change y by ((speed y) / (steps))\n    Check touching soild\n    if <(Touching) > [0]> then\n        Collide Y - Ceiling or floor\n    end\nend\n\ndefine Check touching soild\nif <<touching (platform v)?> or <touching (level v)?>> then\n    set [touching v] to [1]\nelse\n    set [touching v] to [0]\nend\n\nwhen I receive [player v]\nMoved - by Moving Pladform\nswitch backdrop to <touching (level v)?>\nup and down\nleft and right \nMove - in steps (([abs v] of (speed x) ) + ([abs v] of (speed y) ))\nset costume \n\ndefine up and down\nif <<key (up arrow v) pressed?> or <key (space v) pressed?>> then\n    if <<(wall slide) > [0]> and <(jumping) = [0]>> then\n        start sound [Jump v]\n        set [jumping v] to [1]\n        set [falling v] to [3]\n        set [wall slide v] to [0]\n        turn right (180) degrees\n        set [speed x v] to (((direction) / (90)) * (7))\n        set [long jump v] to [7]\n    end\n    if <<(jumping) = [0]> and <(falling) < [3]>> then\n        start sound [Jump v]\n        set [jumping v] to [1]\n        set [falling v] to [3]\n    end\n    if <<(jumping) > [0]> and <(jumping) < (Jump duration)>> then\n        change [jumping v] by (1)\n        set [speed y v] to (Jump Force)\n    end\nelse\n    set [jumping v] to [0]\nend\nchange [speed y v] by (Gravity)\nif <(wall slide) > [0]> then\n    Check can wall sslide\n    if <(speed y) < [0]> then\n        set [speed y v] to ((speed y) * (0.6))\n    end\nend\n\ndefine left and right \nif <(long jump) > [0]> then\n    change [long jump v] by (-1)\n    stop [this script v]\nend\nset [key x v] to (<key (right arrow v) pressed?> - <key (left arrow v) pressed?>)\nif <(key x) = [0]> then\n    if <<(wall slide) < [1]> and <(falling) > [2]>> then\n        set [speed x v] to ((speed x) * (0.98))\n        stop [this script v]\n    end\n    if <([abs v] of (speed x) ) < [1]> then\n        set [frame v] to [0]\n        set [speed x v] to [0]\n    else\n        change [frame v] by (0.5)\n    end\nelse\n    change [speed x v] by ((key x) * (Acceleration))\n    point in direction ((key x) * (90))\n    change [frame v] by (1)\nend\nset [speed x v] to ((speed x) * (Resistance))\n\ndefine reset and begin level\nset [invulnerable v] to [0]\nset [speed y v] to [0]\nset [speed x v] to [0]\nset [falling v] to [99]\nset [long jump v] to [0]\nset [wall slide v] to [0]\nset [jumping v] to [0]\npoint in direction (90)\nbegin scene # (SPAWN SCENE) go to x and y: (SPAWN X) (SPAWN Y)\n\nwhen I receive [game loop v]\nset [ghost v] effect to (0)\nforever\n    broadcast (tick first v)\n    broadcast (tick - platforms v)\n    broadcast (player v)\n    broadcast (TICK LAST v)\nend\n\nwhen I receive [tick last v]\nif <(x position) > [235]> then\n    begin scene # ((scene #) + (1)) go to x and y: [-235] []\nend\nif <(x position) < [-235]> then\n    begin scene # ((scene #) + (-1)) go to x and y: [235] []\nend\nif <(y position) > [180]> then\n    begin scene # ((scene #) + (100)) go to x and y: [] [-160]\nend\nif <(y position) < [-180]> then\n    begin scene # ((scene #) + (-100)) go to x and y: [] [180]\nend\nif <touching (danger v)?> then\n    broadcast (lose life v)\nend\n\ndefine begin scene # (scene #) go to x and y: (x) (y)\nset [scene # v] to (scene #)\nif <(x) > []> then\n    set x to (x)\nend\nif <(y) > []> then\n    set y to (y)\nend\nbroadcast (About to Change Scene v)\nbroadcast (change scene v)\nstop [other scripts in sprite v]\nwait (0) seconds\nswitch costume to (hitbox v2 v)\nset rotation style [don't rotate v]\nif <(x) > []> then\n    fix collision in direction [0]\nelse\n    fix collision in direction [90]\nend\nset costume \nbroadcast (game loop v)\n\ndefine fix collision in direction (dir)\nset [temp v] to (direction)\nset [distance v] to [1]\npoint in direction (dir)\nrepeat (128)\n    Check touching soild\n    if <(Touching) < [1]> then\n        point in direction (temp)\n        stop [this script v]\n    end\n    move (Distance) steps\n    turn right (180) degrees\n    change [distance v] by (1)\nend\n\ndefine set costume \nset rotation style [left-right v]\nif <(wall slide) > [0]> then\n    switch costume to (hangon01 v)\n    stop [this script v]\nend\nif <(falling) > [1]> then\n    if <(speed y) > [0]> then\n        switch costume to (jump01 v)\n    else\n        switch costume to (run_j2 v)\n    end\n    stop [this script v]\nend\nif <(Frame) > [0]> then\n    switch costume to ((1) + ([floor v] of ((Frame) mod (16)) ))\nelse\n    switch costume to (hit angle 0 v)\n    repeat (5)\n        Check touching soild\n        if <(Touching) < [1]> then\n            switch costume to ((costume [number v]) + (5))\n            stop [this script v]\n        end\n        next costume\n    end\n    switch costume to (stand v)\nend\n\nwhen I receive [tick first v]\nswitch costume to (hitbox v2 v)\nset rotation style [don't rotate v]\nset [platform dx v] to []\nset [platform dy v] to []\n\ndefine Collide X - Slope or Wall\nCheck can wall sslide\nchange y by (1)\nCheck touching soild\nif <(Touching) > [0]> then\n    change y by (1)\n    Check touching soild\n    if <(Touching) > [0]> then\n        change y by (-2)\n        set x to (last value)\n        set [speed x v] to [0]\n        stop [this script v]\n    end\n    set [speed x v] to ((speed x) * (0.8))\nend\nset [speed x v] to ((speed x) * (0.95))\nSlip\n\ndefine Collide Y - Ceiling or floor\nset y to (last value)\nif <(speed y) > [0]> then\n    set [speed y v] to [0]\n    stop [this script v]\nend\nif <(falling) > [0]> then\n    set [falling v] to [0]\n    Slip\nend\nset [speed y v] to ((speed y) * (0.8))\n\ndefine Slip\nchange y by (-2)\nchange x by (1)\nCheck touching soild\nif <(Touching) < [1]> then\n    set [falling v] to [9]\n    change [speed x v] by (1)\n    stop [this script v]\nend\nchange x by (-2)\nCheck touching soild\nif <(Touching) < [1]> then\n    set [falling v] to [9]\n    change [speed x v] by (-1)\n    stop [this script v]\nend\nchange y by (2)\nchange x by (1)\n\ndefine Check can wall sslide\nif <(falling) < [2]> then\n    set [wall slide v] to [0]\n    stop [this script v]\nend\nswitch costume to (hitbox wallslide v)\nset rotation style [left-right v]\nCheck touching soild\nset [wall slide v] to (Touching)\nswitch costume to (hitbox v2 v)\nset rotation style [don't rotate v]\n\nwhen I receive [lose life v]\nset [invulnerable v] to [1]\nstop [other scripts in sprite v]\nstart sound [Oops v]\nrepeat (10)\n    change [ghost v] effect by (10)\nend\nwait (0.5) seconds\nchange [lives v] by (-1)\nif <(LIVES) > [0]> then\n    reset and begin level\nelse\n    broadcast (Game Over v)\nend\n\ndefine Moved - by Moving Pladform\nchange x by (PLATFORM DX)\nchange y by (PLATFORM DY)\nCheck touching soild\nif <(Touching) > [0]> then\n    Find Closest Space to (x position) (y position) max [16]\n    if <(Touching) > [0]> then\n        broadcast (lose life v)\n    end\nend\n\ndefine Find Closest Space to (x) (y) max (max)\nset [temp v] to (direction)\nset [distance v] to [1]\npoint in direction (0)\nrepeat (max)\n    repeat (16)\n        go to x: (x) y: (y)\n        move (Distance) steps\n        Check touching soild\n        if <(Touching) < [1]> then\n            point in direction (temp)\n            stop [this script v]\n        end\n        turn right (22.5) degrees\n    end\n    change [distance v] by (1)\nend\ngo to x: (x) y: (y)\npoint in direction (temp)\n\nwhen I receive [start game v]\nshow variable [scene # v]\nshow variable [apples v]\nshow variable [lives v]\nset [jump duration v] to [6]\nset [gravity v] to [-1.5]\nset [jump force v] to [12]\nset [acceleration v] to [1.5]\nset [resistance v] to [0.8]\nbroadcast (Reset game v) and wait\nbroadcast (setup v) and wait\nset [lives v] to [3]\nset [spawn scene v] to [1]\nset [spawn x v] to [-150]\nset [spawn y v] to [55]\nreset and begin level\n\nwhen I receive [player - bounce v]\nset [speed y v] to [10]\n\n@level\n\nwhen I receive [change scene v]\nerase all\nswitch costume to (join [Scene] (scene #))\nStamp Outline\nStamp Shadow\n\ndefine Stamp Outline\nset rotation style [don't rotate v]\nset [brightness v] effect to (-100)\nrepeat (8)\n    move (3) steps\n    stamp\n    move (-3) steps\n    turn right (45) degrees\nend\nclear graphic effects\n\ndefine Stamp Shadow\nset [brightness v] effect to (-100)\nset [ghost v] effect to (90)\nchange y by (-20)\nstamp\nchange y by (20)\nclear graphic effects\n\nwhen flag clicked\ngo to x: (0) y: (0)\ngo to [back v] layer\n\n@danger\n\nwhen flag clicked\ngo [backward v] (3) layers\ngo to x: (0) y: (0)\ngo to [back v] layer\n\nwhen I receive [change scene v]\nswitch costume to ( v)\nswitch costume to (join [Scene] (scene #))\n\nif <(scene #) = [3]> then\n    forever\n        set y to ((3) * ([sin v] of ((timer) * (180)) ))\n    end\nend\n\n@platform\n\nwhen I receive [change scene v]\ngo to [back v] layer\nhide\nif <(scene #) = [4]> then\n    Door at [-21] [71] Key [Key 1]\nend\n\nwhen I receive [tick - platforms v]\ntick (x position) (y position)\nset [last x v] to (x position)\nset [last y v] to (y position)\n\ndefine tick (new x) (new y)\nif <(new y) > (last y)> then\n    change y by (1)\nelse\n    set y to ((last y) + (1))\nend\nif <touching (player v)?> then\n    set [platform dx v] to ((new x) - (last x))\n    set [platform dy v] to ((new y) - (last y))\nend\ngo to x: (new x) y: (new y)\n\ndefine Door at (x) (y) Key (key name)\nshow\nswitch costume to (key name)\ngo to x: (x) y: (y)\nforever\n    wait until <touching (player v)?>\n    if <[collected v] contains (key name)?> then\n        start sound [Buzz Whir v]\n        repeat (24)\n            change y by (4)\n        end\n        wait (1) seconds\n        start sound [Buzz Whir v]\n        repeat (24)\n            change y by (-4)\n        end\n        start sound [Crunch v]\n    else\n        start sound [Low Squeak v]\n        wait until <not <touching (player v)?>>\n    end\nend\n\n@Collectables\n\nwhen I receive [change scene v]\nif <(scene #) = (my scene)> then\n    show\nelse\n    hide\nend\n\nwhen I start as a clone\nrepeat until <touching (player v)?>\n    change y by ((0.5) * ([sin v] of (Frame) ))\n    change [frame v] by (5)\nend\nset [my scene v] to []\nif <(costume [name v]) = [apple]> then\n    start sound [Chomp v]\n    change [apples v] by (1)\nelse\n    if <(costume [name v]) = [Flag]> then\n        start sound [Wand v]\n        set [spawn scene v] to (scene #)\n        set [spawn x v] to ([x position v] of [player v])\n        set [spawn y v] to ([y position v] of [player v])\n    else\n        start sound [Wand v]\n        add (costume [name v]) to [collected v]\n    end\nend\nrepeat (20)\n    change y by (2)\n    change [ghost v] effect by (5)\nend\nhide\n\nwhen I receive [setup v]\ndelete all of [collected v]\nset [apples v] to [0]\nset [frame v] to [0]\nhide\nPlace [apple] Scene [1] xy [115] [-45]\nPlace [apple] Scene [1] xy [-74] [40]\nPlace [apple] Scene [2] xy [24] [-73]\nPlace [Flag] Scene [2] xy [167] [-60]\nPlace [apple] Scene [103] xy [-138] [45]\nPlace [Key 1] Scene [103] xy [185] [-45]\nPlace [Flag] Scene [4] xy [130] [70]\nPlace [apple] Scene [104] xy [98] [-145]\nPlace [apple big] Scene [5] xy [108] [-15]\n\ndefine Place (costume name) Scene (scene) xy (x) (y)\nset [my scene v] to (scene)\nswitch costume to (costume name)\ngo to x: (x) y: (y)\ncreate clone of (_myself_ v)\nset [my scene v] to []\n\nwhen I receive [reset game v]\ndelete this clone\n\nPlace [apple] Scene [104] xy [218] [-150]\n\n@Splash Screen\n\nwhen flag clicked\ngo to x: (0) y: (0)\nswitch costume to (main menu  v)\ngo to [front v] layer\nshow\n\nwhen I receive [game over v]\ngo to x: (0) y: (40)\nswitch costume to (game over v)\ngo to [front v] layer\nshow\nbroadcast (Main Menu v)\n\nwhen I receive [start game v]\nhide\n\n@Main Menu\n\nwhen I receive [main menu v]\nhide variable [apples v]\nhide variable [lives v]\nhide variable [scene # v]\nwait (0.1) seconds\ngo to [front v] layer\nshow\nset size to (10) %\ngo to x: (0) y: (-94)\nforever\n    if <touching (mouse-pointer v)?> then\n        change size by ((0.2) * ((110) - (size)))\n    else\n        change size by ((0.2) * ((100) - (size)))\n    end\nend\n\nwhen flag clicked\nhide\n\nwhen this sprite clicked\nhide\nbroadcast (Start Game v)\n\n@Enemy\n\nwhen flag clicked\nset rotation style [left-right v]\nhide\n\nwhen I receive [change scene v]\nif <(scene #) = [1]> then\n    if <([x position v] of [player v]) < [0]> then\n        Spawn [Red] at [200] [-80] dir [-90]\n    else\n        Spawn [Red] at [40] [-80] dir [90]\n    end\n    Spawn [Red] at [-20] [20] dir [-90]\nend\nif <(scene #) = [103]> then\n    Spawn [Red] at [127] [-68] dir [-90]\nend\nif <(scene #) = [4]> then\n    Spawn [Red] at [66] [40] dir [-90]\nend\n\nwhen I start as a clone\nshow\nset [speed y v] to [0]\nset [frame v] to [0]\nforever\n    switch costume to (red1 v)\n    set rotation style [don't rotate v]\n    Move - Left or Right\n    Move down\n    change [frame v] by (0.33)\n    switch costume to ((1) + (([floor v] of (frame) ) mod (4)))\n    set rotation style [left-right v]\n    if <<(INVULNERABLE) = [0]> and <touching (player v)?>> then\n        Touching Player\n    end\nend\n\nwhen I receive [about to change scene v]\ndelete this clone\n\ndefine Move down\nchange [speed y v] by (-1)\nchange y by (Speed y)\nrepeat until <not <touching (level v)?>>\n    change y by (1)\n    set [speed y v] to [0]\nend\n\ndefine Move - Left or Right\nmove (2) steps\nrepeat (4)\n    if <not <<touching (level v)?> or <touching (_edge_ v)?>>> then\n        if <not <<touching (safe zones v)?> or <touching (platform v)?>>> then\n            stop [this script v]\n        end\n    end\n    change y by (1)\nend\nchange y by (-4)\nmove (-2) steps\nturn right (180) degrees\n\ndefine Touching Player\nif <([speed y v] of [player v]) < [-3]> then\n    broadcast (Player - Bounce v)\n    start sound [pop v]\n    switch costume to (red squish v)\n    wait (0.3) seconds\n    repeat (10)\n        change [ghost v] effect by (10)\n    end\n    delete this clone\nend\nbroadcast (lose life v)\n\ndefine Spawn (type) at (x) (y) dir (dir)\ngo to x: (x) y: (y)\npoint in direction (dir)\ncreate clone of (_myself_ v)\n\n@Sprite1\n\nwhen flag clicked\nset [ghost v] effect to (100)\ngo to [front v] layer\ngo [forward v] (21) layers\nshow\n\nhide\n\n@Safe zones\n\nwhen flag clicked\ngo [backward v] (3) layers\ngo to x: (0) y: (0)\ngo to [back v] layer\nset [ghost v] effect to (100)\n\nwhen I receive [change scene v]\nswitch costume to ( v)\nswitch costume to (join [Scene] (scene #))\n\n