Astro 2 / A Platformer / #games

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

@Stage\n\nwhen flag clicked\nforever\n    if <(LEVEL #) = [1]> then\n        set [gravity v] to [-3]\n    end\n    if <(LEVEL #) = [2]> then\n        set [gravity v] to [-0.7]\n    end\n    if <(LEVEL #) = [3]> then\n        set [gravity v] to [-1.35]\n    end\n    if <(LEVEL #) = [4]> then\n        set [gravity v] to [-1.5]\n    end\n    if <(LEVEL #) = [5]> then\n        set [gravity v] to [-0.7]\n    end\n    if <(LEVEL #) = [6]> then\n        set [gravity v] to [-1]\n    end\n    if <(LEVEL #) = [7]> then\n        set [gravity v] to [-2.5]\n    end\n    if <(LEVEL #) = [8]> then\n        set [gravity v] to [-1.7]\n    end\n    if <(LEVEL #) = [9]> then\n        set [gravity v] to [-1.4]\n    end\n    if <(LEVEL #) = [10]> then\n        set [gravity v] to [-1.7]\n    end\n    if <(LEVEL #) = [0]> then\n        set [gravity v] to [-1.5]\n    end\n    if <(LEVEL #) = [11]> then\n        set [gravity v] to [-1.5]\n    end\nend\n\nwhen flag clicked\nforever\n    play sound [Deep Space v] until done\nend\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\nif <(y position) < [-179]> 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]\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\nset [level # v] to [1]\n\nwhen I receive [change level v]\n\n@Level\n\nwhen flag clicked\ngo to x: (0) y: (0)\ngo to [back v] layer\n\nwhen I receive [change level v]\nswitch costume to (join [Level ] (LEVEL #))\n\n@Danger\n\nwhen flag clicked\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 #) = []> then\n    forever\n        set y to ((3) * ([sin v] of ((timer) * (180)) ))\n    end\nend\n\n@Platform\n\nwhen I receive [change level v]\nhide\nif <(LEVEL #) = [2]> then\n    show\n    animate 2\nend\nif <(LEVEL #) = [7]> then\n    show\n    animate 7\nend\nif <(LEVEL #) = [10]> then\n    show\n    animate 10\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: (-128) y: (-64)\nforever\n    glide (2) secs to x: (-128) y: (40)\n    glide (2) secs to x: (161) y: (-64)\n    wait (0.7) seconds\n    glide (2) secs to x: (-128) y: (40)\n    glide (2) secs to x: (-128) y: (-64)\n    wait (0.7) seconds\nend\n\ndefine animate 7\nswitch costume to (level 7 v)\ngo to x: (-38) y: (-38)\nforever\n    glide (0.5) secs to x: (125) y: (-38)\n    wait (0.2) seconds\n    glide (0.5) secs to x: (-38) y: (-38)\n    wait (0.2) seconds\nend\n\ndefine animate 10\nswitch costume to (level 10 v)\ngo to [back v] layer\nforever\n    go to x: (-157) y: (-189)\n    glide (2) secs to x: (-110) y: (-125)\n    glide (2) secs to x: (-62) y: (-87)\n    glide (4) secs to x: (77) y: (-28)\n    glide (5) secs to x: (291) y: (20)\nend\n\nwait (0.7) seconds\nglide (2) secs to x: (-128) y: (40)\nglide (2) secs to x: (-128) y: (-64)\nwait (0.7) seconds\n\n@Background\n\nwhen I receive [change level v]\ngo to x: (0) y: (0)\ngo to [back v] layer\nswitch costume to (blank v)\nswitch costume to (join [Level ] (LEVEL #))\n\n@Thumbnail\n\nwhen flag clicked\nhide\n\ngo to [front v] layer\nshow\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 #) = [11]> then\n        show\n        go to x: (0) y: (0)\n    else\n        hide\n    end\nend\n\n