The Ninja Platformer (Part 1)

Instructions: Click the flag twice. You must fight your way through the ninja world to save your master. As you go along, you will earn achievements and fight evil ninjas. (Full story in the game)\nPart 2 is out, play it now! https://scratch.mit.edu/projects/980021443\n\n- Use the arrow keys or ASWD to move    \n- T to open the achievement list\n- Space to throw a ninja star\n- Q + R to reset the level\n\n❤️ + ⭐& follow for more fun games by @apple-sock8

@Stage\n\nwhen flag clicked\nforever\n    play sound [Vexento - Tevo \(Original Mix\) v] until done\nend\n\n@P1\n\ndefine jumping (jump height) (fall speed)\nchange y by (y vel)\nif <<<touching (ground v)?> or <touching (target v)?>> or <touching (hidden ground v)?>> then\n    repeat ([ceiling v] of ([abs v] of (y vel) ) )\n        if <<<touching (ground v)?> or <touching (target v)?>> or <touching (hidden ground v)?>> then\n            change y by (((y vel) / ([abs v] of (y vel) )) * (-1))\n        end\n    end\n    if <<not <(y vel) > [0]>> and <<key (up arrow v) pressed?> or <key (w v) pressed?>>> then\n        set [y vel v] to (jump height)\n        change [jumps v] by (1)\n    else\n        set [y vel v] to [0]\n    end\nelse\n    change [y vel v] by (fall speed)\nend\n\nwhen flag clicked\nset [moving? v] to [no]\nforever\n    if <(Moving?) = [yes]> then\n        moving [10] [0.6]\n        next level\n        if <(bounce pad) = [yes]> then\n            jumping [18] [-1]\n        else\n            jumping [14] [-1]\n        end\n    end\nend\n\ndefine moving (movement) (drag)\nchange x by (x vel)\nif <<<touching (ground v)?> or <touching (target v)?>> or <touching (hidden ground v)?>> then\n    repeat ([ceiling v] of ([abs v] of (x vel) ) )\n        if <<<touching (ground v)?> or <touching (target v)?>> or <touching (hidden ground v)?>> then\n            change x by (((x vel) / ([abs v] of (x vel) )) * (-1))\n        end\n    end\n    set [x vel v] to [0]\nend\nif <<key (right arrow v) pressed?> or <key (d v) pressed?>> then\n    set [x vel v] to (movement)\n    point in direction (90)\nelse\n    if <<key (left arrow v) pressed?> or <key (a v) pressed?>> then\n        point in direction (-90)\n        set [x vel v] to ((movement) * (-1))\n    end\nend\nset [x vel v] to ((x vel) * (drag))\n\nwhen flag clicked\nset [spawn x v] to [-212]\nset [spawn y v] to [-65]\ngo to x: (spawn x) y: (spawn y)\nset [y vel v] to [0]\nset [x vel v] to [0]\n\ndefine next level\nif <(x position) > [230]> then\n    broadcast (next level v)\n    go to x: (spawn x) y: (spawn y)\nend\n\nwhen I receive [die v]\ngo to x: (spawn x) y: (spawn y)\n\nwhen flag clicked\nset rotation style [left-right v]\nforever\n    go to [front v] layer\nend\n\nwhen flag clicked\nset [costume v] to [yes]\nswitch costume to (costume1 v)\nforever\n    if <(costume) = [yes]> then\n        wait (.1) seconds\n        switch costume to (costume1 v)\n        wait (.1) seconds\n        switch costume to (costume2 v)\n        wait (.1) seconds\n        switch costume to (costume3 v)\n    end\n    if <(costume) = [no]> then\n        switch costume to (costume4 v)\n    end\nend\n\nwhen flag clicked\npoint in direction (90)\nset [achievements see v] to [Hide]\nshow list [achievments v]\ndelete all of [achievments v]\nadd [1: Beat 1 level] to [achievments v]\nadd [2: Beat 5 levels] to [achievments v]\nadd [3: Beat every level] to [achievments v]\nadd [4: Throw a ninja star] to [achievments v]\nadd [5: Jump 25 times] to [achievments v]\nadd [6: Take out 1 ninja] to [achievments v]\nadd [7: Take out 5 ninjas] to [achievments v]\nadd [8: Collect 1 purple coin] to [achievments v]\nadd [9: Collect 3 purple coins] to [achievments v]\nadd [10: Earn all other achievments] to [achievments v]\nforever\n    if <<key (t v) pressed?> and <(Achievements see) = [Hide]>> then\n        wait until <not <key (t v) pressed?>>\n        hide list [achievments v]\n        set [achievements see v] to [Open]\n    end\n    if <<key (t v) pressed?> and <(Achievements see) = [Open]>> then\n        wait until <not <key (t v) pressed?>>\n        show list [achievments v]\n        set [achievements see v] to [Hide]\n    end\nend\n\nwhen flag clicked\nforever\n    if <(Lives) = [0]> then\n        broadcast (game over v)\n        hide\n        stop [all v]\n    end\nend\n\nwhen flag clicked\nforever\n    set [player direction v] to (direction)\nend\n\nwhen flag clicked\nhide\nforever\n    if <(bounce pad) = [yes]> then\n        if <key (up arrow v) pressed?> then\n            start sound [Jump v]\n        end\n    end\n    if <(Moving?) = [yes]> then\n        show\n    end\nend\n\nwhen flag clicked\nforever\n    if <<key (r v) pressed?> and <key (q v) pressed?>> then\n        wait until <not <<key (r v) pressed?> and <key (q v) pressed?>>>\n        go to x: (spawn x) y: (spawn y)\n        point in direction (90)\n    end\nend\n\nwhen flag clicked\nforever\n    set [achievements v] to (join (Achievement amount) [/10])\nend\n\nwhen flag clicked\nset [jumps v] to [0]\nforever\n    if <(jumps) = [25]> then\n        wait (.1) seconds\n        change [achievement amount v] by (1)\n        wait (1) seconds\n        stop [this script v]\n    end\nend\n\nwhen flag clicked\nforever\n    if <(level) = [14]> then\n        set [costume v] to [no]\n    end\nend\n\nwhen flag clicked\nset [time v] to [0]\nforever\n    wait until <(Moving?) = [yes]>\n    if <(costume) = [yes]> then\n        wait (1) seconds\n        change [time v] by (1)\n    end\nend\n\n@hitbox\n\nwhen flag clicked\nset [bounce pad v] to [no]\nforever\n    set [ghost v] effect to (1000)\n    go to (p1 v)\nend\n\ndefine Safe Check\nif <<touching color (#d20000)?> and <touching (ground v)?>> then\n    broadcast (die v)\nend\nif <touching color (#27fd2a)?> then\n    broadcast (die v)\nend\nif <<touching color (#fbff00)?> and <touching (ground v)?>> then\n    set [bounce pad v] to [yes]\nelse\n    set [bounce pad v] to [no]\nend\nif <touching (#1 star v)?> then\n    broadcast (die v)\nend\nif <touching (black ninja 1 v)?> then\n    broadcast (die v)\nend\nif <(y position) < [-190]> then\n    broadcast (die v)\nend\nif <touching (#1 star2 v)?> then\n    broadcast (die v)\nend\nif <touching (black ninja 2 v)?> then\n    broadcast (die v)\nend\n\nwhen flag clicked\nforever\n    Safe Check\nend\n\n@Ground\n\nwhen flag clicked\nswitch costume to (costume1 v)\nset [level v] to [1]\nforever\n    go to x: (0) y: (-80)\nend\n\nwhen I receive [next level v]\nchange [level v] by (1)\nnext costume\n\nwhen flag clicked\nforever\n    if <(level) = [14]> then\n        show variable [time v]\n    else\n        hide variable [time v]\n    end\nend\n\n@Hearts\n\nwhen flag clicked\nswitch costume to (5 v)\nset [lives v] to [5]\nforever\n    go to x: (-175) y: (-165)\n    switch costume to (Lives)\nend\n\nwhen I receive [die v]\nchange [lives v] by (-1)\n\n@Acheivments\n\nwhen flag clicked\nset [achievement amount v] to [0]\nhide\ngo to x: (0) y: (180)\nforever\n    go to [front v] layer\n    if <(level) = [3]> then\n        wait (.2) seconds\n        if <(level) = [3]> then\n            switch costume to (costume1 v)\n            show\n            change [achievement amount v] by (1)\n            start sound [Collect v]\n            glide (1) secs to x: (0) y: (140)\n            wait (2) seconds\n            glide (1) secs to x: (0) y: (180)\n            hide\n            stop [this script v]\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(purple coins) = [1]> then\n        wait (.3) seconds\n        if <(purple coins) = [1]> then\n            switch costume to (costume2 v)\n            show\n            change [achievement amount v] by (1)\n            start sound [Collect v]\n            glide (1) secs to x: (0) y: (140)\n            wait (2) seconds\n            glide (1) secs to x: (0) y: (180)\n            hide\n            stop [this script v]\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(ninjas knocked) = [1]> then\n        wait (.3) seconds\n        if <(ninjas knocked) = [1]> then\n            switch costume to (costume3 v)\n            show\n            change [achievement amount v] by (1)\n            start sound [Collect v]\n            glide (1) secs to x: (0) y: (140)\n            wait (2) seconds\n            glide (1) secs to x: (0) y: (180)\n            hide\n            stop [this script v]\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <key (space v) pressed?> then\n        wait until <not <key (space v) pressed?>>\n        change [achievement amount v] by (1)\n        start sound [Collect v]\n        broadcast (star achievement v)\n        stop [this script v]\n    end\nend\n\nwhen I receive [star achievement v]\nswitch costume to (costume4 v)\nshow\nglide (1) secs to x: (0) y: (140)\nwait (2) seconds\nglide (1) secs to x: (0) y: (180)\nhide\nstop [this script v]\n\nwhen flag clicked\nforever\n    if <(jumps) = [25]> then\n        wait (.3) seconds\n        if <<(jumps) = [25]> or <(jumps) > [25]>> then\n            switch costume to (costume5 v)\n            show\n            start sound [Collect v]\n            glide (1) secs to x: (0) y: (140)\n            wait (2) seconds\n            glide (1) secs to x: (0) y: (180)\n            hide\n            stop [this script v]\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(level) = [7]> then\n        wait (.2) seconds\n        if <(level) = [7]> then\n            switch costume to (costume6 v)\n            show\n            change [achievement amount v] by (1)\n            start sound [Collect v]\n            glide (1) secs to x: (0) y: (140)\n            wait (2) seconds\n            glide (1) secs to x: (0) y: (180)\n            hide\n            stop [this script v]\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(ninjas knocked) = [5]> then\n        wait (.3) seconds\n        if <(ninjas knocked) = [5]> then\n            switch costume to (costume7 v)\n            show\n            change [achievement amount v] by (1)\n            start sound [Collect v]\n            glide (1) secs to x: (0) y: (140)\n            wait (2) seconds\n            glide (1) secs to x: (0) y: (180)\n            hide\n            stop [this script v]\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(purple coins) = [3]> then\n        wait (.3) seconds\n        if <(purple coins) = [3]> then\n            switch costume to (costume8 v)\n            show\n            change [achievement amount v] by (1)\n            start sound [Collect v]\n            glide (1) secs to x: (0) y: (140)\n            wait (2) seconds\n            glide (1) secs to x: (0) y: (180)\n            hide\n            stop [this script v]\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(level) = [14]> then\n        wait (.3) seconds\n        if <(level) = [14]> then\n            switch costume to (costume10 v)\n            show\n            change [achievement amount v] by (1)\n            start sound [Collect v]\n            glide (1) secs to x: (0) y: (140)\n            wait (2) seconds\n            glide (1) secs to x: (0) y: (180)\n            hide\n            if <(Achievement amount) = [9]> then\n                switch costume to (costume9 v)\n                show\n                change [achievement amount v] by (1)\n                start sound [Collect v]\n                glide (1) secs to x: (0) y: (140)\n                wait (2) seconds\n                glide (1) secs to x: (0) y: (180)\n                hide\n                stop [this script v]\n            else\n                stop [this script v]\n            end\n        end\n    end\nend\n\n@Target\n\nwhen flag clicked\nswitch costume to (costume1 v)\nhide\nforever\n    if <(level) = [4]> then\n        show\n        go to x: (207) y: (-72)\n    else\n        hide\n    end\nend\n\nwhen I receive [target smashed v]\nswitch costume to (costume2 v)\n\n@Player star\n\nwhen flag clicked\nhide\nforever\n    go to (p1 v)\nend\n\ndefine Rotate\nwait (.05) seconds\nnext costume\n\nwhen flag clicked\nforever\n    if <key (space v) pressed?> then\n        wait until <not <key (space v) pressed?>>\n        create clone of (_myself_ v)\n        wait (1) seconds\n    end\nend\n\nwhen I start as a clone\nshow\npoint in direction (Player Direction)\nrepeat until <touching (_edge_ v)?>\n    move (7) steps\nend\n\nwhen I start as a clone\nforever\n    Rotate\nend\n\nwhen I start as a clone\nforever\n    if <<<touching (_edge_ v)?> or <touching (ground v)?>> or <touching (hidden ground v)?>> then\n        delete this clone\n    end\n    if <touching (target v)?> then\n        broadcast (target smashed v)\n    end\nend\n\n@Hidden Ground\n\nwhen flag clicked\nhide\nforever\n    if <not <(level) = [4]>> then\n        hide\n    end\nend\n\nwhen I receive [target smashed v]\nif <(level) = [4]> then\n    show\n    go to x: (9) y: (15)\nelse\n    hide\nend\n\n@Instructions\n\nwhen flag clicked\nhide\nforever\n    if <(level) = [3]> then\n        go to x: (0) y: (150)\n        show\n        switch costume to (costume1 v)\n    else\n        if <(level) = [6]> then\n            go to x: (0) y: (165)\n            show\n            switch costume to (costume2 v)\n        else\n            if <(level) = [9]> then\n                go to x: (0) y: (165)\n                show\n                switch costume to (costume3 v)\n            else\n                if <(level) = [10]> then\n                    go to x: (0) y: (165)\n                    show\n                    switch costume to (costume4 v)\n                else\n                    if <(level) = [2]> then\n                        go to x: (0) y: (165)\n                        show\n                        switch costume to (costume5 v)\n                    else\n                        if <(level) = [11]> then\n                            go to x: (0) y: (165)\n                            show\n                            switch costume to (costume6 v)\n                        else\n                            hide\n                        end\n                    end\n                end\n            end\n        end\n    end\nend\n\n@purple coins\n\nwhen flag clicked\nhide\n\nwhen flag clicked\nset [purple coins v] to [0]\nforever\n    if <(level) = [4]> then\n        if <touching (p1 v)?> then\n            change [purple coins v] by (1)\n            start sound [Coin v]\n            hide\n            stop [this script v]\n        end\n    end\nend\n\nwhen I receive [next level v]\nwait (.2) seconds\nif <(level) = [4]> then\n    go to x: (-195) y: (135)\n    show\nelse\n    if <(level) = [9]> then\n        go to x: (-195) y: (135)\n        show\n    else\n        if <(level) = [10]> then\n            go to x: (125) y: (-135)\n            show\n        else\n            hide\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(level) = [9]> then\n        if <touching (p1 v)?> then\n            change [purple coins v] by (1)\n            start sound [Coin v]\n            hide\n            stop [this script v]\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(level) = [10]> then\n        if <touching (p1 v)?> then\n            change [purple coins v] by (1)\n            start sound [Coin v]\n            hide\n            stop [this script v]\n        end\n    end\nend\n\n@Black ninja 1\n\nwhen flag clicked\nhide\nset rotation style [left-right v]\n\nwhen I receive [next level v]\nwait (.1) seconds\nif <(level) = [5]> then\n    set [#1 okay? v] to [yes]\n    show\n    point in direction (-90)\n    go to x: (170) y: (-75)\n    forever\n        if <(#1 okay?) = [yes]> then\n            wait (3) seconds\n            if <(#1 okay?) = [yes]> then\n                Throw\n            end\n        end\n    end\nend\n\ndefine Throw\nbroadcast (#1 throw v)\n\nwhen flag clicked\nset [ninjas knocked v] to [0]\nforever\n    if <touching (player star v)?> then\n        set [#1 okay? v] to [no]\n        hide\n        change [ninjas knocked v] by (1)\n        broadcast (#1 knocked v)\n    end\nend\n\nwhen I receive [next level v]\nwait (.1) seconds\nif <(level) = [8]> then\n    set [#1 okay? v] to [yes]\n    show\n    point in direction (-90)\n    go to x: (170) y: (-75)\n    forever\n        if <(#1 okay?) = [yes]> then\n            wait (3) seconds\n            if <(#1 okay?) = [yes]> then\n                Throw\n            end\n        end\n    end\nend\n\nwhen I receive [next level v]\nwait (.1) seconds\nif <(level) = [12]> then\n    set [#1 okay? v] to [yes]\n    show\n    point in direction (-90)\n    go to x: (170) y: (-75)\n    forever\n        if <(#1 okay?) = [yes]> then\n            wait (3) seconds\n            if <(#1 okay?) = [yes]> then\n                Throw\n            end\n        end\n    end\nend\n\nwhen I receive [next level v]\nwait (.1) seconds\nif <(level) = [13]> then\n    set [#1 okay? v] to [yes]\n    show\n    point in direction (-90)\n    go to x: (170) y: (-75)\n    forever\n        if <(#1 okay?) = [yes]> then\n            wait (3) seconds\n            if <(#1 okay?) = [yes]> then\n                Throw\n            end\n        end\n    end\nend\n\n@#1 star\n\nwhen flag clicked\nhide\nforever\n    go to (black ninja 1 v)\nend\n\ndefine Rotate\nwait (.05) seconds\nnext costume\n\nwhen I start as a clone\nshow\npoint in direction (-90)\nrepeat until <touching (_edge_ v)?>\n    move (7) steps\nend\n\nwhen I start as a clone\nforever\n    Rotate\nend\n\nwhen I start as a clone\nforever\n    if <<<<touching (_edge_ v)?> or <touching (ground v)?>> or <touching (hidden ground v)?>> or <touching (p1 v)?>> then\n        wait (.05) seconds\n        delete this clone\n    end\n    if <touching (target v)?> then\n        wait (.1) seconds\n        delete this clone\n    end\nend\n\nwhen I receive [#1 throw v]\ncreate clone of (_myself_ v)\n\n@heart #1\n\nwhen flag clicked\nhide\nforever\n    go to (black ninja 1 v)\n    if <touching (hitbox v)?> then\n        wait (.1) seconds\n        change [lives v] by (1)\n        start sound [Connect v]\n        hide\n    end\n    if <(Lives) > [5]> then\n        set [lives v] to [5]\n    end\nend\n\nwhen I receive [#1 knocked v]\nif <(level) = [8]> then\n    show\nelse\n    if <(level) = [12]> then\n        show\n    else\n        hide\n    end\nend\n\n@clouds\n\nwhen flag clicked\nforever\n    go to x: (36) y: (28)\n    go to [back v] layer\n    set [ghost v] effect to (30)\nend\n\n@Acid\n\nwhen flag clicked\ngo to x: (50) y: (-171)\nhide\nforever\n    set [ghost v] effect to (10)\n    go to [back v] layer\n    glide (1.5) secs to x: (50) y: (-200)\n    glide (2) secs to x: (50) y: (-170)\nend\n\nwhen flag clicked\nforever\n    if <(level) = [6]> then\n        show\n    else\n        if <(level) = [11]> then\n            show\n        else\n            hide\n        end\n    end\nend\n\n@Slides\n\nwhen flag clicked\nshow\nswitch costume to (costume1 v)\nforever\n    if <(Moving?) = [yes]> then\n        show variable [achievements v]\n    end\n    if <(Moving?) = [no]> then\n        hide variable [achievements v]\n    end\nend\n\nwhen flag clicked\nswitch costume to (costume1 v)\nwait (.1) seconds\nforever\n    if <(Moving?) = [no]> then\n        if <mouse down?> then\n            wait until <not <mouse down?>>\n            next costume\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <(costume [number v]) = [4]> then\n        if <mouse down?> then\n            broadcast (start v)\n            hide\n            set [moving? v] to [yes]\n        end\n    end\nend\n\n@Black ninja 2\n\nwhen flag clicked\nhide\nset rotation style [left-right v]\n\ndefine Throw\nbroadcast (#2 throw v)\n\nwhen flag clicked\nforever\n    if <touching (player star v)?> then\n        set [#2 okay? v] to [no]\n        hide\n        change [ninjas knocked v] by (1)\n        broadcast (#2 knocked v)\n    end\nend\n\nwhen I receive [next level v]\nwait (.1) seconds\nif <(level) = [12]> then\n    set [#2 okay? v] to [yes]\n    show\n    point in direction (-90)\n    go to x: (170) y: (0)\n    forever\n        if <(#2 okay?) = [yes]> then\n            wait (3) seconds\n            if <(#2 okay?) = [yes]> then\n                Throw\n            end\n        end\n    end\nend\n\n@#1 star2\n\nwhen flag clicked\nhide\nforever\n    go to (black ninja 2 v)\nend\n\ndefine Rotate\nwait (.05) seconds\nnext costume\n\nwhen I start as a clone\nshow\npoint in direction (-90)\nrepeat until <touching (_edge_ v)?>\n    move (7) steps\nend\n\nwhen I start as a clone\nforever\n    Rotate\nend\n\nwhen I start as a clone\nforever\n    if <<<<touching (_edge_ v)?> or <touching (ground v)?>> or <touching (hidden ground v)?>> or <touching (p1 v)?>> then\n        wait (.05) seconds\n        delete this clone\n    end\n    if <touching (target v)?> then\n        wait (.1) seconds\n        delete this clone\n    end\nend\n\nwhen I receive [#2 throw v]\ncreate clone of (_myself_ v)\n\n@thumbnail\n\nwhen flag clicked\nforever\n    go to x: (0) y: (0)\n    hide\nend\n\n@game over\n\nwhen flag clicked\nhide\nforever\n    go to x: (0) y: (0)\nend\n\nwhen I receive [game over v]\nshow\ngo to [front v] layer\n\n