Sword platformer

Instructions: Go through the levels using your sword to help you move, and see if you can get a record!

@Stage\n\n@Player\n\ndefine Clean Landing (x) (y)\nrepeat until <not <touching (ground v)?>>\n    change x by (x)\n    change y by (y)\nend\n\nwhen flag clicked\nforever\n    if <key (a v) pressed?> then\n        change [horizontal speed v] by (-5)\n    end\n    if <key (d v) pressed?> then\n        change [horizontal speed v] by (5)\n    end\n    set [horizontal speed v] to ((Horizontal speed) * (.6))\n    change x by (Horizontal speed)\n    if <touching (ground v)?> then\n        Clean Landing ((0) - ((Horizontal speed) / ([abs v] of (Horizontal speed) ))) [0]\n        set [horizontal speed v] to [0]\n    else\n        switch costume to (hitbox v)\n        point in direction (Sword direction)\n        if <touching (ground v)?> then\n            Clean Landing ((0) - ((Horizontal speed) / ([abs v] of (Horizontal speed) ))) [0]\n            set [horizontal speed v] to [0]\n        end\n        point in direction (90)\n        switch costume to (player v)\n    end\nend\n\nwhen flag clicked\nset [sword direction v] to [0]\nforever\n    switch costume to (hitbox v)\n    point towards (mouse-pointer v)\n    set [target direction v] to ((round (direction)) mod (360))\n    point in direction (Sword direction)\n    Position Sword\n    set [sword direction v] to ((round (direction)) mod (360))\n    point in direction (90)\n    switch costume to (player v)\nend\n\ndefine Position Sword\nif <not <((direction) mod (360)) = (Target direction)>> then\n    Set Turn Direction\n    set [push frames v] to [0]\n    repeat until <((direction) mod (360)) = (Target direction)>\n        turn right (Turn direction) degrees\n        if <touching (ground v)?> then\n            set [successful push? v] to [False]\n            Check Move [0] [5]\n            Check Move [0] [-5]\n            Check Move [5] [0]\n            Check Move [-5] [0]\n            if <(Successful Push?) = [False]> then\n                turn right (() - (Turn direction)) degrees\n                stop [this script v]\n            end\n            if <(Push Frames) > [5]> then\n                stop [this script v]\n            end\n        end\n    end\nend\n\ndefine Check Move (x) (y)\nif <(Successful Push?) = [False]> then\n    set [start x v] to (x position)\n    set [start y v] to (y position)\n    repeat ([abs v] of ((x) + (y)) )\n        change x by ((x) / ([abs v] of (x) ))\n        change y by ((y) / ([abs v] of (y) ))\n        if <not <touching (ground v)?>> then\n            switch costume to (player v)\n            set [previous direction v] to (direction)\n            point in direction (90)\n            if <touching (ground v)?> then\n                set x to (Start X)\n                set y to (Start Y)\n            else\n                set [successful push? v] to [True]\n                change [push frames v] by (1)\n            end\n            switch costume to (hitbox v)\n            point in direction (Previous Direction)\n            stop [this script v]\n        end\n    end\n    set x to (Start X)\n    set y to (Start Y)\nend\n\ndefine Set Turn Direction\nif <(Target direction) > (Sword direction)> then\n    if <(((360) - (Target direction)) + (Sword direction)) > ((Target direction) - (Sword direction))> then\n        set [turn direction v] to [1]\n    else\n        set [turn direction v] to [-1]\n    end\nelse\n    if <(((360) - (Sword direction)) + (Target direction)) > ((Sword direction) - (Target direction))> then\n        set [turn direction v] to [-1]\n    else\n        set [turn direction v] to [1]\n    end\nend\n\nwhen flag clicked\nset [vertical speed v] to [0]\ngo to x: (-212) y: (-100)\n\nwhen flag clicked\nforever\n    if <key (q v) pressed?> then\n        create clone of (fire ball v)\n        wait (3) seconds\n    end\nend\n\nchange y by (10)\n\nwhen flag clicked\nforever\n    if <touching (next level v)?> then\n        broadcast (Touching Next Level v)\n    end\nend\n\nwhen I receive [touching next level v]\ngo to x: (-212) y: (-100)\n\nwhen flag clicked\nforever\n    if <<touching (next level v)?> or <touching (obstacle v)?>> then\n        go to x: (-212) y: (-100)\n    end\nend\n\nwhen I receive [sword touching spikes v]\ngo to x: (-212) y: (-100)\n\nwhen flag clicked\nforever\n    if <(Hit) = [False]> then\n        if <touching (enemy v)?> then\n            go to x: (-212) y: (-100)\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <key (w v) pressed?> then\n        change y by (-1)\n        if <touching (ground v)?> then\n            set [vertical speed v] to [10]\n        end\n        change y by (1)\n    end\n    change [vertical speed v] by (-1)\n    change y by (Vertical speed)\n    if <touching (ground v)?> then\n        Clean Landing [0] ((0) - ((Vertical speed) / ([abs v] of (Vertical speed) )))\n        set [vertical speed v] to [0]\n    else\n        switch costume to (hitbox v)\n        point in direction (Sword direction)\n        if <touching (ground v)?> then\n            Clean Landing [0] ((0) - ((Vertical speed) / ([abs v] of (Vertical speed) )))\n            set [vertical speed v] to [0]\n        end\n        point in direction (90)\n        switch costume to (player v)\n    end\nend\n\n@Ground\n\nwhen flag clicked\ngo to x: (-6) y: (-10)\n\nwhen flag clicked\n\nwhen I receive [touching next level v]\nnext costume\n\nwhen flag clicked\nswitch costume to (costume1 v)\n\ngo to x: (-6) y: (-161)\n\nwhen flag clicked\nforever\n    if <(costume [number v]) = [5]> then\n        broadcast (Show Timer v)\n    end\nend\n\nwhen flag clicked\nforever\n    if <<(costume [number v]) = [1]> or <<(costume [number v]) = [2]> or <<(costume [number v]) = [3]> or <(costume [number v]) = [3]>>>> then\n        set [final time v] to (timer)\n    end\nend\n\nwhen flag clicked\nhide variable [final time v]\n\nwhen flag clicked\nforever\n    if <(costume [number v]) = [5]> then\n        show variable [final time v]\n    end\nend\n\n@Fire Ball\n\nwhen I start as a clone\nshow\ngo to (player v)\npoint in direction ([direction v] of [sword v])\nmove (7) steps\nrepeat until <touching (_edge_ v)?>\n    move (10) steps\n    if <touching (enemy v)?> then\n        wait (.1) seconds\n        delete this clone\n    end\nend\ndelete this clone\n\nwhen flag clicked\nhide\n\nwhen flag clicked\n\n@Sword\n\nwhen flag clicked\nforever\n    go to (player v)\nend\n\nwhen flag clicked\nswitch costume to (costume1 v)\n\nwhen flag clicked\nforever\n    point in direction (Sword direction)\nend\n\npoint towards (mouse-pointer v)\n\nforever\n    if <mouse down?> then\n        switch costume to (costume2 v)\n        wait (1) seconds\n    else\n        repeat (1)\n            switch costume to (costume1 v)\n        end\n    end\nend\n\nwhen flag clicked\n\nforever\n    if <touching (ground v)?> then\n        set [vertical speed v] to [7]\n    end\n    change y by (0)\n    change [vertical speed v] by (0)\n    change y by (Vertical speed)\n    if <touching (ground v)?> then\n        change y by ((0) - (Vertical speed))\n        set [vertical speed v] to [0]\n    end\nend\n\nwhen flag clicked\nif <touching (obstacle v)?> then\n    broadcast (Sword Touching Spikes v)\nend\n\n@Enemy\n\nwhen I start as a clone\nshow\npoint in direction (-90)\nforever\n    if <(Hit) = [False]> then\n        move (2.5) steps\n        switch costume to (costume2 v)\n        if <<touching (_edge_ v)?> or <touching (ground v)?>> then\n            turn right (180) degrees\n        end\n        switch costume to (costume3 v)\n        if <not <touching (ground v)?>> then\n            turn right (180) degrees\n        end\n        switch costume to (costume1 v)\n        if <<touching (sword v)?> or <<touching (fire ball v)?> or <touching (shield v)?>>> then\n            set [hit v] to [True]\n            wait (0) seconds\n            switch costume to (costume4 v)\n            wait (0.1) seconds\n            switch costume to (costume5 v)\n            wait (0.1) seconds\n            switch costume to (costume6 v)\n            wait (0.1) seconds\n            switch costume to (costume7 v)\n            set [hit v] to [False]\n            delete this clone\n        end\n    end\nend\n\npoint in direction ([y position v] of [player v])\n\nwhen flag clicked\nset rotation style [left-right v]\nhide\nCreate Enemy [92] [40]\n\nwhen flag clicked\nhide\n\nwhen flag clicked\n\nforever\n    if <touching (player v)?> then\n        forever\n            stop [all v]\n        end\n    end\nend\n\nmove (2.5) steps\n\nwhen I receive [touching next level v]\nwait (0) seconds\nif <([costume # v] of [ground v]) = [2]> then\n    Create Enemy [-31] [-135]\nend\n\ndefine Create Enemy (x) (y)\ngo to x: (x) y: (y)\ncreate clone of (_myself_ v)\n\ngo to x: (0) y: (0)\npoint in direction (90)\nswitch costume to (costume1 v)\nshow\n\nwhen I receive [touching next level v]\ndelete this clone\n\nwhen I receive [touching next level v]\nwait (0) seconds\nif <([costume # v] of [ground v]) = [3]> then\n    Create Enemy [113] [-131]\n    Create Enemy [-100] [-131]\nend\n\nwhen flag clicked\nset [hit v] to [False]\n\n@Shield\n\nwhen flag clicked\nforever\n    if <key (e v) pressed?> then\n        show\n        wait (3) seconds\n        hide\n        wait (10) seconds\n    end\nend\n\nwhen flag clicked\nhide\n\nwhen flag clicked\nforever\n    go to (player v)\n    set [ghost v] effect to (50)\nend\n\n@Next level\n\nwhen flag clicked\ngo to x: (239) y: (3)\nset [ghost v] effect to (0)\ngo to [back v] layer\n\nwhen flag clicked\nswitch costume to (costume1 v)\n\nwhen I receive [touching next level v]\nnext costume\n\n@Obstacle\n\nwhen flag clicked\ngo to x: (99) y: (-138)\n\nwhen I receive [touching next level v]\nnext costume\n\nwhen flag clicked\nswitch costume to (costume1 v)\n\n