Factory / A Platformer / #games

Instructions:                                      GROTTO\n     --> https://scratch.mit.edu/projects/596294350/ <--\n\n                      Press the arrow keys to move.

@Stage\n\nwhen I receive [change level v]\nstop all sounds\n\nwhen I receive [lose life v]\nclear sound effects\n\n@Player\n\nwhen flag clicked\nset [gravity v] to [-1.5]\nset [jump force v] to [15]\nset [acceleration v] to [2]\nset [resistance v] to [0.8]\nset [jump duration v] to [4]\nreset and begin level\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 solid\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 solid\n    if <(touching) > [0]> then\n        collide y - ceiling or floor?\n    end\nend\n\ndefine check touching solid\nif <<touching (level v)?> or <touching (platform v)?>> then\n    set [touching v] to [1]\nelse\n    set [touching v] to [0]\nend\n\nwhen I receive [tick - player v]\nmoved by moving platform\nswitch backdrop to <touching (level v)?>\ncontrols - up and down\ncontrols - left and right\nmove - in steps (([abs v] of (speed \(x\)) ) + ([abs v] of (speed \(y\)) ))\nset costume\n\ndefine controls - up and down\nif <key (up arrow v) pressed?> then\n    if <<(wall slide) > [0]> and <(jumping) = [0]>> then\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 [12]\n    end\n    if <<(falling) < [3]> and <(jumping) = [0]>> then\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 slide\n    if <(speed \(y\)) < [0]> then\n        set [speed \(y\) v] to ((speed \(y\)) * (0.6))\n    end\nend\n\ndefine controls - 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 <<(falling) > [2]> and <(wall slide) < [1]>> then\n        set [speed \(x\) v] to ((speed \(x\)) * (0.91))\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 [speed \(x\) v] to [0]\nset [speed \(y\) v] to [0]\nset [falling v] to [99]\nset [wall slide v] to [0]\nset [jumping v] to [0]\nset [long jump v] to [0]\npoint in direction (90)\ngo to x: (-220) y: (50)\nbroadcast (change level v)\nbroadcast (game loop v)\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 (tick - player v)\n    broadcast (tick - last v)\nend\n\nwhen I receive [tick - last v]\nif <(x position) > [235]> then\n    begin level # ((LEVEL #) + (1)) go to x: [-235]\nend\nif <(x position) < [-235]> then\n    begin level # ((LEVEL #) - (1)) go to x: [235]\nend\nif <touching (danger v)?> then\n    broadcast (lose life v)\nend\n\ndefine begin level # (level #) go to x: (x)\nset [level # v] to (level #)\nset x to (x)\nbroadcast (change level v)\nstop [other scripts in sprite v]\nwait (0) seconds\nswitch costume to (hitbox v)\nset rotation style [don't rotate v]\nfix collision in direction [0]\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 (1000)\n    check touching solid\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\nwhen I receive [tick - first v]\nswitch costume to (hitbox v)\nset rotation style [don't rotate v]\nset [platform dx v] to []\nset [platform dy v] to []\n\ndefine set costume\nset rotation style [left-right v]\nswitch costume to (player v)\n\ndefine collide x - slope or wall?\ncheck can wall slide\nchange y by (1)\ncheck touching solid\nif <(touching) > [0]> then\n    change y by (1)\n    check touching solid\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 solid\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 solid\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 slide\nif <(falling) < [2]> then\n    set [wall slide v] to [0]\n    stop [this script v]\nend\nset rotation style [left-right v]\ncheck touching solid\nset [wall slide v] to (touching)\nset rotation style [don't rotate v]\n\nwhen I receive [lose life v]\nstart sound [Low Whoosh v]\nstop [other scripts in sprite v]\nrepeat (10)\n    change [ghost v] effect by (10)\nend\nwait (0.5) seconds\nreset and begin level\n\ndefine moved by moving platform\nchange x by (PLATFORM DX)\nchange y by (PLATFORM DY)\ncheck touching solid\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 solid\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 flag clicked\nshow\nset [level # v] to [1]\n\nwhen I receive [win game v]\nhide\n\n@Level\n\nwhen I receive [win game v]\nhide\n\nwhen flag clicked\nshow\ngo to x: (0) y: (0)\ngo to [front v] layer\nforever\n    go to [front v] layer\nend\n\nwhen I receive [change level v]\nswitch costume to (join [Level ] (LEVEL #))\n\n@Danger\n\nwhen I receive [win game v]\nhide\n\nwhen flag clicked\nshow\ngo to x: (0) y: (0)\ngo to [back v] layer\n\nwhen I receive [change level v]\nswitch costume to (blank v)\nswitch costume to (join [Level ] (LEVEL #))\nif <<(LEVEL #) = [2]> or <(LEVEL #) = [7]>> then\n    forever\n        set y to ((3) * ([sin v] of ((timer) * (180)) ))\n    end\nelse\n    go to x: (0) y: (0)\nend\n\n@Platform\n\nwhen I receive [win game v]\nhide\n\nwhen I receive [change level v]\ngo to [back v] layer\ngo [forward v] (2) layers\nhide\nif <(LEVEL #) = [1]> then\n    show\n    animate 1\nend\nif <(LEVEL #) = [2]> then\n    show\n    animate 2\nend\nif <(LEVEL #) = [5]> then\n    show\n    animate 5\nend\nif <(LEVEL #) = [6]> then\n    show\n    animate 6\nend\n\ndefine animate 1\nset volume to (50) %\nswitch costume to (level 1 v)\ngo to x: (35) y: (21)\nforever\n    glide (1) secs to x: (35) y: (110)\n    wait (0.7) seconds\n    glide (0.3) secs to x: (35) y: (21)\n    start sound [Close Vault Or Jail Door-SoundBible v]\n    wait (0.7) seconds\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 animate 2\nswitch costume to (level 2 v)\ngo to x: (-100) y: (-75)\nforever\n    start sound [Level 2 Motion v]\n    glide (2) secs to x: (100) y: (-75)\n    wait (0.7) seconds\n    start sound [Level 2 Motion v]\n    glide (2) secs to x: (-100) y: (-75)\n    wait (0.7) seconds\nend\n\ndefine animate 5\nset volume to (50) %\nswitch costume to (level 5 v)\ngo to x: (21) y: (-52)\nforever\n    glide (1) secs to x: (21) y: (24)\n    wait (0.7) seconds\n    glide (0.3) secs to x: (21) y: (-51)\n    start sound [Close Vault Or Jail Door-SoundBible v]\n    wait (0.7) seconds\nend\n\ndefine animate 6\nswitch costume to (level 6 v)\ngo to x: (-128) y: (-80)\nforever\n    start sound [Level 2 Motion v]\n    glide (2) secs to x: (201) y: (-80)\n    wait (0.7) seconds\n    start sound [Level 2 Motion v]\n    glide (2) secs to x: (-128) y: (-80)\n    wait (0.7) seconds\nend\n\n@Clouds\n\nwhen I receive [win game v]\nhide\n\nwhen flag clicked\nshow\nset [ghost v] effect to (100)\nforever\n    switch costume to (pick random (1) to (2))\n    wait (1.5) seconds\n    create clone of (_myself_ v)\nend\n\nwhen I start as a clone\nset [cloud x v] to (pick random (1) to (2))\nset [cloud y v] to (pick random (0) to (180))\nif <(cloud x) = [1]> then\n    go to x: (-240) y: (cloud y)\n    repeat (pick random (7) to (10))\n        change [ghost v] effect by (-8)\n    end\n    glide (5) secs to x: (240) y: (cloud y)\n    repeat (5)\n        change [ghost v] effect by (8)\n    end\n    delete this clone\nelse\n    go to x: (240) y: (cloud y)\n    repeat (pick random (7) to (10))\n        change [ghost v] effect by (-8)\n    end\n    glide (5) secs to x: (-240) y: (cloud y)\n    repeat (5)\n        change [ghost v] effect by (8)\n    end\n    delete this clone\nend\n\nwhen I start as a clone\nforever\n    go to [back v] layer\nend\n\n@Backdrops\n\nwhen I receive [win game v]\nhide\n\nwhen flag clicked\nshow\ngo to x: (0) y: (0)\nswitch costume to (level 1 v)\n\nwhen I receive [change level v]\ngo [forward v] (1) layers\ngo to [back v] layer\nswitch costume to (blank v)\nswitch costume to (join [Level ] (LEVEL #))\n\n@Win\n\nwhen flag clicked\nswitch costume to (walk into v)\ngo to x: (0) y: (0)\nforever\n    if <touching (player v)?> then\n        switch costume to (win screen v)\n        broadcast (win game v)\n    end\nend\n\nwhen flag clicked\nforever\n    if <(LEVEL #) = [9]> then\n        show\n        go to x: (0) y: (0)\n    else\n        hide\n    end\nend\n\n@Thumbnail\n\nwhen I receive [win game v]\nhide\n\nwhen flag clicked\nhide\n\n