Platformer with Enemy AI

Instructions: Arrow keys. Avoid the enemies and try to collect the lives powerups. Don't swim in water, and try to reach the other side. If you're having trouble on a level, click the "help" button. O to skip a level and P to go back. If you find any glitches, please tell me in the comments. Please be sure to like and favorite.\n◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆

@Stage\n\n@Sprite1\n\ndefine Restart\nset [x v] to [0]\nset [y v] to [0]\ngo to x: (-200) y: (0)\nif <(Lives) < [1]> then\n    stop [all v]\nend\n\ndefine Physics\nif <<key (right arrow v) pressed?> or <<key (d v) pressed?> or <<mouse down?> and <(mouse x) > (x position)>>>> then\n    change [x v] by (1)\nend\nif <<key (left arrow v) pressed?> or <<key (a v) pressed?> or <<mouse down?> and <(x position) > (mouse x)>>>> then\n    change [x v] by (-1)\nend\nchange x by (x)\nSlope Detection\nif <<touching color (#ffd900)?> or <touching color (#e47224)?>> then\n    change x by ((x) * (-1))\n    set [x v] to [0]\nend\nif <touching (sprite2 v)?> then\n    change x by ((x) * (-1))\n    if <<key (up arrow v) pressed?> or <<key (w v) pressed?> or <<mouse down?> and <(mouse y) > (y position)>>>> then\n        if <(x) > [0]> then\n            set [x v] to [-10]\n            set [y v] to [10]\n        else\n            set [x v] to [10]\n            set [y v] to [10]\n        end\n    else\n        set [x v] to [0]\n    end\nelse\n    set [x v] to ((x) * (.9))\nend\nchange y by (y)\nif <<touching (sprite2 v)?> or <<not <touching color (#ffde2a)?>> and <<touching color (#ffd900)?> or <touching color (#e47224)?>>>> then\n    change y by ((y) * (-1))\n    set [y v] to [0]\n    if <<key (up arrow v) pressed?> or <<key (w v) pressed?> or <<mouse down?> and <(mouse y) > (y position)>>>> then\n        if <(Jumping?) = [no]> then\n            set [y v] to [12]\n            set [jumping? v] to [yes]\n        end\n    end\nelse\n    change [y v] by (-1)\n    set [jumping? v] to [no]\nend\nif <touching (sprite3 v)?> then\n    change [lives v] by (-1)\n    Restart\n    broadcast (Reset Enemy v)\nend\nif <(x position) > [239]> then\n    if <(LEVEL) = [6]> then\n        set [level v] to [0]\n        set [lives v] to [3]\n    end\n    change [level v] by (1)\n    Restart\n    broadcast (Reset Enemy v)\n    broadcast (Delete Clones v)\nend\nif <[-179] > (y position)> then\n    change [lives v] by (-1)\n    Restart\n    broadcast (Reset Enemy v)\nend\nif <<touching color (#ffde2a)?> and <touching (sprite4 v)?>> then\n    set [y v] to [20]\n    set [jumping? v] to [yes]\n    broadcast (bounce v)\nend\n\ndefine Slope Detection\nset [slope v] to [0]\nrepeat until <<(Slope) = [8]> or <not <touching (sprite2 v)?>>>\n    change y by (1)\n    change [slope v] by (1)\nend\nif <touching (sprite2 v)?> then\n    change y by (-8)\nend\n\nwhen I receive [green flag v]\ngo to [back v] layer\nset [lives v] to [3]\nRestart\nSetup\nshow\nset [level v] to [1]\nforever\n    Physics\n    if <(Help Showing) = [yes]> then\n        wait until <(Help Showing) = [no]>\n    end\nend\n\nwhen I receive [green flag v]\nforever\n    play sound [Vexento - Tevo \(Original Mix\)2.MP3 v] until done\nend\n\nwhen [o v] key pressed\nif <(Intro going) = [no]> then\n    if <(LEVEL) = [6]> then\n        set [level v] to [0]\n        set [lives v] to [3]\n        Setup\n    end\n    change [level v] by (1)\n    Restart\n    broadcast (Reset Enemy v)\n    broadcast (Delete Clones v)\nend\n\nwhen [p v] key pressed\nif <(Intro going) = [no]> then\n    if <(LEVEL) = [1]> then\n        set [level v] to [6]\n        set [lives v] to [3]\n        Setup\n    end\n    change [level v] by (-1)\n    Restart\n    broadcast (Reset Enemy v)\n    broadcast (Delete Clones v)\nend\n\ndefine Setup\ndelete all of [collected? v]\nrepeat (10)\n    add [] to [collected? v]\nend\n\nwhen flag clicked\nhide\n\n@Sprite2\n\nwhen I receive [green flag v]\ngo to x: (0) y: (0)\nshow\ngo to [front v] layer\nforever\n    switch costume to (LEVEL)\n    if <(LEVEL) = [6]> then\n        broadcast (Delete Clones v)\n    end\nend\n\nwhen flag clicked\nhide\n\n@Sprite3\n\ndefine Restart\nhide\nstop [other scripts in sprite v]\nset [x v] to [0]\nset [y v] to [0]\nbroadcast (Spawn v)\ndelete this clone\n\ndefine Physics\nif <(x position) < ([x position v] of [sprite1 v])> then\n    change [x v] by (.4)\nend\nif <([x position v] of [sprite1 v]) < (x position)> then\n    change [x v] by (-.4)\nend\nchange x by (x)\nSlope Detection\nif <<touching color (#ffd900)?> or <touching color (#e47224)?>> then\n    change x by ((x) * (-1))\nend\nif <touching (sprite2 v)?> then\n    change x by ((x) * (-1))\n    if <(y position) < ([y position v] of [sprite1 v])> then\n        if <(x) > [0]> then\n            set [x v] to [-10]\n            set [y v] to [10]\n        else\n            set [x v] to [10]\n            set [y v] to [10]\n        end\n    else\n        set [x v] to [0]\n    end\nelse\n    set [x v] to ((x) * (.9))\nend\nchange y by (y)\nif <touching (sprite2 v)?> then\n    change y by ((y) * (-1))\n    set [y v] to [0]\n    if <((y position) - (25)) < ([y position v] of [sprite1 v])> then\n        if <(Jumping?) = [no]> then\n            set [y v] to [12]\n            set [jumping? v] to [yes]\n        end\n    end\nelse\n    change [y v] by (-1)\n    set [jumping? v] to [no]\nend\nif <[-179] > (y position)> then\n    delete this clone\nend\nif <touching (sprite4 v)?> then\n    set [y v] to [20]\n    set [jumping? v] to [yes]\n    broadcast (bounce v)\nend\n\ndefine Slope Detection\nset [slope v] to [0]\nrepeat until <<(Slope) = [8]> or <not <touching (sprite2 v)?>>>\n    change y by (1)\n    change [slope v] by (1)\nend\nif <touching (sprite2 v)?> then\n    change y by (-8)\nend\n\nwhen I receive [reset enemy v]\nRestart\n\nwhen I start as a clone\ngo to x: (pick random (-30) to (200)) y: (pick random (180) to (10))\nrepeat until <<(distance to [sprite1 v]) > [100]> and <not <<touching color (#9a7900)?> or <touching color (#0cff00)?>>>>\n    go to x: (pick random (-30) to (200)) y: (pick random (180) to (10))\nend\nshow\nforever\n    Physics\n    if <(Help Showing) = [yes]> then\n        wait until <(Help Showing) = [no]>\n    end\nend\n\nwhen I receive [spawn v]\nwait (.01) seconds\nif <(LEVEL) = [6]> then\n\nwhen I receive [delete clones v]\ndelete this clone\n\nwhen I receive [green flag v]\ngo to [back v] layer\nRestart\nhide\nset [level v] to [1]\n\nset [lives v] to [100]\n\nwhen flag clicked\nhide\n\n@Sprite4\n\nwhen I receive [bounce v]\nswitch costume to (costume2 v)\nwait (.05) seconds\nswitch costume to (costume3 v)\nwait (.07) seconds\nswitch costume to (costume2 v)\nwait (.05) seconds\nswitch costume to (costume1 v)\n\nwhen I receive [green flag v]\nswitch costume to (costume1 v)\ngo to [back v] layer\ngo [forward v] (2) layers\nforever\n    if <(LEVEL) = [1]> then\n        go to x: (218) y: (-89)\n        show\n    else\n        if <(LEVEL) = [3]> then\n            go to x: (-105) y: (-104)\n            show\n        else\n            if <(LEVEL) = [4]> then\n                show\n                go to x: (-33) y: (-109)\n            else\n                if <(LEVEL) = [5]> then\n                    go to x: (208) y: (-100)\n                    show\n                else\n                    hide\n                end\n            end\n        end\n    end\nend\n\nwhen flag clicked\nhide\n\n@Sprite5\n\nwhen I receive [green flag v]\ngo to x: (0) y: (0)\nshow\ngo to [front v] layer\ngo [backward v] (1) layers\nforever\n    switch costume to (LEVEL)\nend\n\nwhen flag clicked\nhide\n\n@Sprite6\n\nwhen I receive [delete clones v]\ndelete this clone\n\nwhen I receive [delete clones v]\nstop [other scripts in sprite v]\npoint in direction (90)\nset size to (100) %\nif <not (item (LEVEL) of [collected? v])> then\n    if <(LEVEL) = [1]> then\n        go to x: (-200) y: (80)\n        show\n        broadcast (Get moving v)\n    else\n        if <(LEVEL) = [2]> then\n            go to x: (-206) y: (96)\n            show\n            broadcast (Get moving v)\n        else\n            if <(LEVEL) = [3]> then\n                go to x: (-102) y: (17)\n                show\n                broadcast (Get moving v)\n            else\n                if <(LEVEL) = [4]> then\n                    go to x: (36) y: (90)\n                    show\n                    broadcast (Get moving v)\n                else\n                    hide\n                    delete this clone\n                end\n            end\n        end\n    end\nelse\n    stop [other scripts in sprite v]\n    hide\nend\n\nwhen I receive [get moving v]\nforever\n    if <touching (sprite1 v)?> then\n        repeat (10)\n            change size by (-8)\n            turn right (8) degrees\n        end\n        replace item (LEVEL) of [collected? v] with [collected]\n        change [lives v] by (1)\n        hide\n    end\nend\n\nwhen I receive [get moving v]\nforever\n    repeat (12)\n        if <(Help Showing) = [yes]> then\n            wait until <(Help Showing) = [no]>\n        end\n        change y by (.5)\n    end\n    repeat (12)\n        if <(Help Showing) = [yes]> then\n            wait until <(Help Showing) = [no]>\n        end\n        change y by (-.5)\n    end\nend\n\nwhen I receive [green flag v]\nrepeat (10)\n    hide\n    point in direction (90)\n    set size to (100) %\n    go to x: (-200) y: (80)\n    show\nend\nbroadcast (Get moving v)\n\nwhen flag clicked\nhide\n\n@Sprite7\n\nwhen I receive [green flag v]\nforever\n    show\n    set [ghost v] effect to (100)\n    go to x: (0) y: (0)\n    go to [front v] layer\n    go [backward v] (1) layers\nend\n\nwhen flag clicked\nhide\n\nwhen flag clicked\nhide\n\n@Red Counter\n\nwhen I start as a clone\nshow\nforever\n    set size to (100) %\n    go to x: (((digits) * (12)) - (174)) y: (156)\n    if <(length of (Lives)) < (digits)> then\n        hide\n    else\n        show\n        switch costume to (letter (digits) of (Lives))\n    end\nend\n\nwhen I receive [green flag v]\nhide\nset [digits v] to [1]\nrepeat (5)\n    create clone of (_myself_ v)\n    change [digits v] by (1)\nend\n\nwhen flag clicked\nhide\n\n@Sprite8\n\nwhen this sprite clicked\nif <<(Help Showing) = [no]> and <not <(LEVEL) = [6]>>> then\n    switch costume to ((LEVEL) + (1))\n    set [help showing v] to [yes]\n    go to x: (0) y: (0)\n    set size to (10) %\n    repeat (11)\n        change size by (9)\n        go to [front v] layer\n    end\nend\n\nwhen I receive [hide help v]\nrepeat (11)\n    change size by (-9)\n    go to [front v] layer\nend\nswitch costume to (costume1 v)\ngo to x: (-211) y: (125)\nset size to (100) %\nset [brightness v] effect to (0)\nset [help showing v] to [no]\n\nwhen I receive [green flag v]\nset [help showing v] to [no]\nswitch costume to (costume1 v)\nset size to (100) %\nset [brightness v] effect to (0)\ngo to x: (-211) y: (125)\nshow\nforever\n    if <(Help Showing) = [yes]> then\n        wait until <(Help Showing) = [no]>\n    end\n    if <touching (mouse-pointer v)?> then\n        set [brightness v] effect to (7)\n        repeat (5)\n            change size by (2)\n        end\n        wait until <not <touching (mouse-pointer v)?>>\n        set [brightness v] effect to (0)\n        repeat (5)\n            change size by (-2)\n        end\n    end\nend\n\nwhen flag clicked\nhide\n\n@Sprite9\n\nwhen this sprite clicked\nhide\nbroadcast (Hide Help v) and wait\n\nwhen I receive [hide help v]\nrepeat until <(Help Showing) = [no]>\n    hide\nend\n\nwhen I receive [green flag v]\nhide\ngo to x: (207) y: (143)\nforever\n    if <(Help Showing) = [yes]> then\n        wait (.4) seconds\n        if <(Help Showing) = [yes]> then\n            go to [front v] layer\n            show\n        else\n            hide\n        end\n    else\n        hide\n    end\nend\n\nwhen I receive [green flag v]\nhide\ngo to x: (207) y: (143)\nforever\n    if <touching (mouse-pointer v)?> then\n        set [brightness v] effect to (-10)\n    else\n        set [brightness v] effect to (0)\n    end\nend\n\nwhen flag clicked\nhide\n\n@Sprite10\n\nwhen this sprite clicked\nif <(timer) > (Timer)> then\n    repeat (25)\n        change [ghost v] effect by (4)\n    end\n    broadcast (Green Flag v)\nend\n\nwhen I receive [green flag v]\ngo to x: (-120) y: (109)\nforever\n    show\n    set size to (100) %\n    set [ghost v] effect to (100)\n    go to [front v] layer\nend\n\nwhen [timer v] > (Timer)\nset size to (100) %\nforever\n    if <touching (mouse-pointer v)?> then\n        set [brightness v] effect to (7)\n        repeat (5)\n            change size by (2)\n        end\n        wait until <not <touching (mouse-pointer v)?>>\n        set [brightness v] effect to (0)\n        repeat (5)\n            change size by (-2)\n        end\n    end\nend\n\nwhen flag clicked\nreset timer\nforever\n    set [timer v] to ((timer) + (.1))\nend\n\nwhen flag clicked\nhide\n\nwhen flag clicked\nhide\n\n@Sprite11\n\nwhen flag clicked\nset size to (100) %\nset [clone# v] to [0]\nrepeat (2)\n    change [clone# v] by (1)\n    create clone of (_myself_ v)\nend\nwait (.7) seconds\nrepeat (8)\n    change [clone# v] by (1)\n    create clone of (_myself_ v)\n    wait (.03) seconds\nend\n\nwhen I start as a clone\nshow\nif <(clone#) = [1]> then\n    switch costume to (y4 v)\n    go to x: (100) y: (-190)\n    set [my dir v] to [0]\n    set [ghost v] effect to (100)\n    Point to X: (My dir) Y: [0]\n    wait (.1) seconds\n    repeat (10)\n        change [ghost v] effect by (-10)\n    end\n    repeat (70)\n        Point to X: (My dir) Y: [0]\n        change [my dir v] by (2)\n    end\n    repeat (100)\n        Point to X: (My dir) Y: [0]\n        change [my dir v] by (-2)\n        change [ghost v] effect by (1)\n    end\nelse\n    if <(clone#) = [2]> then\n        switch costume to (y4 v)\n        go to x: (-100) y: (-190)\n        set [my dir v] to [0]\n        set [ghost v] effect to (100)\n        Point to X: (My dir) Y: [0]\n        wait (.1) seconds\n        set [ghost v] effect to (100)\n        repeat (10)\n            change [ghost v] effect by (-10)\n        end\n        repeat (70)\n            Point to X: (My dir) Y: [0]\n            change [my dir v] by (-2)\n        end\n        repeat (100)\n            Point to X: (My dir) Y: [0]\n            change [my dir v] by (2)\n            change [ghost v] effect by (1)\n        end\n    else\n        point in direction (90)\n        set [ghost v] effect to (100)\n        show\n        go to x: ((((clone#) - (2)) * (40)) - ((4) * (40))) y: (0)\n        set size to (80) %\n        switch costume to ((clone#) - (2))\n        repeat (5)\n            change [ghost v] effect by (-20)\n        end\n        wait (2) seconds\n        repeat (5)\n            change [ghost v] effect by (20)\n        end\n    end\nend\ndelete this clone\n\ndefine Point to X: (x) Y: (y)\nset [dx v] to ((x) - (x position))\nset [dy v] to ((y) - (y position))\nif <(dy) = [0]> then\n    if <(dx) > [0]> then\n        set [dir v] to [90]\n    else\n        set [dir v] to [-90]\n    end\nelse\n    if <(dy) > [0]> then\n        set [dir v] to ([atan v] of ((dx) / (dy)) )\n    else\n        set [dir v] to ((180) + ([atan v] of ((dx) / (dy)) ))\n    end\nend\nif <not <(direction) = (dir)>> then\n    point in direction (dir)\nend\n\nwhen flag clicked\nset [intro going v] to [yes]\nshow\nswitch costume to (y5 v)\nset [ghost v] effect to (99)\nrepeat (3)\n    change [ghost v] effect by (-33)\n    go to [back v] layer\nend\ngo to x: (0) y: (0)\nrepeat (100)\n    go to [back v] layer\nend\nwait (3) seconds\nrepeat (20)\n    change [ghost v] effect by (5)\nend\nhide\nset [intro going v] to [no]\nbroadcast (Green Flag v)\n\n