griffpatch's platformer

Instructions: If you want an updated version with collectibles, enemies, and more levels play this: https://scratch.mit.edu/projects/612050043/\n\nFrom his simple platformer tutorial on youtube.\nPre-collectables.\n\nArrow keys to move.\nYou can go up as well as right\n\nThis project has 521 Blocks, 5 sprites, and 33 scripts

@Stage\n\nwhen I receive [change scene v]\nif <(scene #) = [1]> then\n    switch backdrop to (false2 v)\nelse\n    switch backdrop to (backdrop1 v)\nend\n\n@player\n\nwhen flag clicked\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]\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 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\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        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        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\nbegin scene # [1] go to x and y: [-150] [55]\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)\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 (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]\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 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\n@level\n\nwhen flag clicked\ngo to x: (0) y: (0)\ngo to [back v] layer\n\nwhen I receive [change scene v]\nswitch costume to (join [Scene] (scene #))\n\n@danger\n\nwhen flag clicked\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 #))\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 #) = [1]> then\n    show\n    Animate1\nend\nif <(scene #) = [3]> then\n    show\n    Animate3\nend\nif <(scene #) = [102]> then\n    show\n    Animate102\nend\nif <(scene #) = [103]> then\n    show\n    animate103\nend\n\ndefine Animate1\nswitch costume to (costume1 v)\npoint in direction (90)\ngo to x: (16) y: (-54)\nforever\n    glide (1) secs to x: (16) y: (83)\n    wait (1) seconds\n    glide (2) secs to x: (166) y: (51)\n    wait (1) seconds\n    glide (2) secs to x: (16) y: (-54)\n    wait (1) 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\ngo to x: (16) y: (-54)\nforever\n    glide (2) secs to x: (16) y: (83)\n    wait (1) seconds\n    glide (2) secs to x: (3) y: (51)\n    wait (1) seconds\nend\n\ndefine Animate3\nswitch costume to (costume1 v)\npoint in direction (0)\ngo to x: (99) y: (30)\nforever\n    glide (0.5) secs to x: (99) y: (-53)\n    wait (1) seconds\n    glide (1) secs to x: (99) y: (30)\n    wait (1) seconds\nend\n\ndefine Animate102\nswitch costume to (costume1 v)\npoint in direction (90)\ngo to x: (-146) y: (-31)\nwait (0.5) seconds\nforever\n    glide (1) secs to x: (-12) y: (-31)\n    wait (1) seconds\n    glide (1) secs to x: (-145) y: (-31)\n    wait (1) seconds\nend\n\ndefine animate103\nswitch costume to (costume2 v)\npoint in direction (90)\ngo to x: (-43) y: (-63)\nwait (0.5) seconds\nforever\n    glide (2.5) secs to x: (365) y: (-63)\n    wait (1) seconds\n    glide (2.5) secs to x: (-43) y: (-63)\n    wait (1) seconds\nend\n\n@Sprite1\n\nwhen flag clicked\nset [ghost v] effect to (100)\ngo to [front v] layer\nshow\n\n