Scrolling Platformer Engine
@Stage\n\n@Hitbox\n\nwhen flag clicked\nset [ghost v] effect to (100)\nset [x vel v] to [0]\nset [walljumping v] to [False]\nset [y vel v] to [0]\nset [scroll x v] to [0]\nset [scroll y v] to [100]\nset [in air v] to [3]\nforever\n    set [player x v] to ((Scroll X) + (y position))\n    set [player y v] to ((Scroll Y) + (x position))\n    if <touching (moving platform v)?> then\n        if <(Player X) > (TMPX)> then\n            change [x vel v] by (MPXVEL)\n        end\n        if <(PLayer Y) > (TMPY)> then\n            change [y vel v] by (MPYVEL)\n        end\n    else\n        set [mpxvel v] to [0]\n        set [mpyvel v] to [0]\n    end\n    point in direction (90)\n    change [y vel v] by (-1)\n    change y by (Y Vel)\n    Detect <(Y Vel) > [0]>\n    change [x vel v] by ((<key (right arrow v) pressed?> - <key (left arrow v) pressed?>) * (2))\n    set [x vel v] to ((X Vel) * (0.85))\n    change x by (X Vel)\n    Wall\n    Scroll\n    if <<key (up arrow v) pressed?> and <(In air) < [2]>> then\n        set [y vel v] to [12]\n    end\n    broadcast (Move Platforms v)\nend\n\ndefine Scroll\nchange x by ((0) - (round ((x position) / (10))))\nchange y by ((0) - (round ((y position) / (10))))\nchange [scroll x v] by (round ((x position) / (10)))\nchange [scroll y v] by (round ((y position) / (10)))\n\ndefine Detect <up or down>\npoint in direction (90)\nchange [in air v] by (1)\nrepeat until <not <touching (platform v)?>>\n    if <up or down> then\n        change y by (-1)\n    else\n        change y by (1)\n        set [in air v] to [0]\n    end\n    set [y vel v] to [0]\nend\nrepeat until <not <touching (moving platform v)?>>\n    if <up or down> then\n        change y by (-1)\n    else\n        change y by (1)\n        set [in air v] to [0]\n    end\n    set [y vel v] to [0]\nend\n\ndefine Wall\npoint in direction (90)\nset [touching wall? v] to [0]\nset [walljumping v] to [False]\nrepeat until <<<not <touching (platform v)?>> and <not <touching (moving platform v)?>>> or <(Touching Wall?) = [11]>>\n    change y by (1)\n    change [touching wall? v] by (1)\nend\nif <(Touching Wall?) = [11]> then\n    change x by ((0) - (X Vel))\n    change y by (-11)\n    if <key (up arrow v) pressed?> then\n        set [walljumping v] to [True]\n        set [y vel v] to [10]\n        if <(X Vel) > [0]> then\n            set [x vel v] to [-15]\n        else\n            set [x vel v] to [15]\n        end\n    else\n        set [walljumping v] to [False]\n        set [x vel v] to [0]\n    end\nend\n\nwhen flag clicked\nforever\n    Touching PLatform?\nend\n\ndefine Touching PLatform?\nchange y by (-10)\nif <touching (platform v)?> then\n    set [touching platform? v] to [True]\nelse\n    set [touching platform? v] to [False]\nend\nchange y by (10)\n\nwhen flag clicked\nforever\n    if <touching (lava v)?> then\n        broadcast (Kill v) and wait\n    end\nend\n\n@Player\n\nwhen flag clicked\nforever\n    go to (hitbox v)\n    if <(Walljumping) = [False]> then\n        point in direction ((X Vel) + (90))\n    else\n        point in direction (90)\n    end\nend\n\nwhen flag clicked\nforever\n    if <[-180] > (Scroll Y)> then\n        broadcast (Kill v) and wait\n    end\nend\n\n@Platform\n\ndefine Position (x) (y)\ngo to x: (x) y: (y)\nif <<(x) = (x position)> and <(y) = (y position)>> then\n    show\nelse\n    hide\nend\n\nwhen flag clicked\nhide\nset [clone number v] to [1]\nrepeat (4)\n    create clone of (_myself_ v)\n    change [clone number v] by (1)\nend\n\nwhen I start as a clone\nshow\nswitch costume to (Clone Number)\nif <(Clone Number) = [1]> then\n    set [x v] to [0]\n    set [y v] to [0]\nend\nif <(Clone Number) = [2]> then\n    set [x v] to [250]\n    set [y v] to [150]\nend\nif <(Clone Number) = [3]> then\n    set [x v] to [700]\n    set [y v] to [150]\nend\nif <(Clone Number) = [4]> then\n    set [x v] to [1000]\n    set [y v] to [50]\nend\nforever\n    Position ((x) - (Scroll X)) ((y) - (Scroll Y))\nend\n\n@Weapon\n\nwhen flag clicked\nset rotation style [all around v]\nforever\n    go to x: ([x position v] of [hitbox v]) y: ([y position v] of [hitbox v])\n    point towards (mouse-pointer v)\n    move (60) steps\n    if <(direction) < [0]> then\n        switch costume to (weapon2 v)\n    else\n        switch costume to (weapon v)\n    end\nend\n\nwhen flag clicked\nforever\n    if <mouse down?> then\n        create clone of (bullet v)\n        wait (0.1) seconds\n    end\nend\n\n@Bullet\n\nwhen flag clicked\nhide\n\nwhen I start as a clone\ngo to [back v] layer\nshow\ngo to (weapon v)\npoint in direction ([direction v] of [weapon v])\nset [x v] to (((Scroll X) + ([x position v] of [weapon v])) + ((([sin v] of (direction) ) * (20)) * (2)))\nset [y v] to (((Scroll Y) + ([y position v] of [weapon v])) + ((([cos v] of (direction) ) * (20)) * (2)))\ngo to x: ((x) - (Scroll X)) y: ((y) - (Scroll Y))\nforever\n    go to x: ((x) - (Scroll X)) y: ((y) - (Scroll Y))\n    change [x v] by (([sin v] of (direction) ) * (20))\n    change [y v] by (([cos v] of (direction) ) * (20))\n    if <<<touching (_edge_ v)?> or <touching (platform v)?>> or <touching (moving platform v)?>> then\n        delete this clone\n    end\n    if <touching (enemies v)?> then\n        wait (0.03) seconds\n        delete this clone\n    end\nend\n\n@Moving PLatform\n\ndefine Position (x) (y)\ngo to x: (x) y: (y)\nif <<(x) = (x position)> and <(y) = (y position)>> then\n    show\nelse\n    hide\nend\n\nwhen flag clicked\nhide\nset [clone number v] to [1]\nrepeat (1)\n    create clone of (_myself_ v)\n    change [clone number v] by (1)\nend\n\nwhen I start as a clone\nshow\nswitch costume to (Clone Number)\nif <(Clone Number) = [1]> then\n    set [x v] to [810]\n    set [y v] to [550]\n    forever\n        repeat until <[375] > (y)>\n            if <touching (player v)?> then\n                set [oldx v] to (x)\n                set [oldy v] to (y)\n            end\n            set [y v] to ((y) + (-3))\n            if <touching (player v)?> then\n                set [mpxvel v] to ((OLDX) - (x))\n                set [mpyvel v] to ((OLDY) - (y))\n                set [tmpx v] to (x)\n                set [tmpy v] to (y)\n            end\n            if <<<<(PLayer Y) < (y)> and <(Player X) < [750]>> and <(Player X) < [815]>> and <touching (player v)?>> then\n                if <(Touching Platform?) = [True]> then\n                    broadcast (Kill v)\n                    set [scroll x v] to [0]\n                    set [scroll y v] to [0]\n                end\n            end\n        end\n        repeat until <(y) > [700]>\n            if <touching (player v)?> then\n                set [oldx v] to (x)\n                set [oldy v] to (y)\n            end\n            set [y v] to ((y) + (3))\n            if <touching (player v)?> then\n                set [mpxvel v] to ((OLDX) - (x))\n                set [mpyvel v] to ((OLDY) - (y))\n                set [tmpx v] to (x)\n                set [tmpy v] to (y)\n            end\n            if <<<<(PLayer Y) < (y)> and <(Player X) < [750]>> and <(Player X) < [815]>> and <touching (player v)?>> then\n                if <(Touching Platform?) = [True]> then\n                    broadcast (Kill v)\n                    set [scroll y v] to [0]\n                    set [scroll x v] to [0]\n                end\n            end\n        end\n    end\nend\n\nwhen I receive [move platforms v]\nPosition ((x) - (Scroll X)) ((y) - (Scroll Y))\n\n@Kill\n\nwhen I receive [kill v]\nclear graphic effects\nshow\nwait (0.5) seconds\nset [scroll x v] to [0]\nset [scroll y v] to [0]\nrepeat (10)\n    change [ghost v] effect by (10)\nend\nhide\n\nwhen flag clicked\ngo to x: (0) y: (0)\nhide\n\n@Enemies\n\ndefine Position (x) (y)\ngo to x: (x) y: (y)\nif <<(x) = (x position)> and <(y) = (y position)>> then\n    show\nelse\n    hide\nend\n\nwhen flag clicked\nset [real? v] to [False]\nset [timer v] to [0]\nclear graphic effects\nhide\nset [clone number v] to [1]\nrepeat (1)\n    create clone of (_myself_ v)\n    change [clone number v] by (1)\nend\nset [real? v] to [True]\nforever\n    change [timer v] by (1)\nend\n\nwhen I start as a clone\nswitch costume to (enemy v)\nshow\nswitch costume to (Clone Number)\nif <(Clone Number) = [1]> then\n    set [x v] to [1400]\n    set [y v] to [-64]\n    forever\n        Position ((x) - (Scroll X)) ((y) - (Scroll Y))\n        set [sync v] to ((((Timer) / (100)) + (1400)) mod (1))\n        set [x v] to ((([sin v] of (([sin v] of ((Sync) * (360)) ) * (100)) ) * (100)) + (1400))\n        if <touching (player v)?> then\n            broadcast (Kill v)\n        end\n        if <touching (bullet v)?> then\n            repeat (10)\n                Position ((x) - (Scroll X)) ((y) - (Scroll Y))\n                change [ghost v] effect by (10)\n            end\n            delete this clone\n        end\n    end\nend\n\nwhen I receive [kill v]\nif <(Real?) = [True]> then\n    set [real? v] to [False]\n    hide\n    set [clone number v] to [1]\n    repeat (1)\n        create clone of (_myself_ v)\n        change [clone number v] by (1)\n    end\n    set [real? v] to [True]\nend\n\nwhen I receive [kill v]\ndelete this clone\n\n@Lava\n\ndefine Position (x) (y)\ngo to x: (x) y: (y)\nif <<(x) = (x position)> and <(y) = (y position)>> then\n    show\nelse\n    hide\nend\n\nwhen flag clicked\nhide\nset [clone number v] to [1]\nrepeat (4)\n    create clone of (_myself_ v)\n    change [clone number v] by (1)\nend\n\nwhen I start as a clone\nshow\nswitch costume to (Clone Number)\nif <(Clone Number) = [1]> then\n    set [x v] to [0]\n    set [y v] to [0]\nend\nforever\n    Position ((x) - (Scroll X)) ((y) - (Scroll Y))\nend\n\n
Use with credit \n\nThis engine includes\n- Moving Platforms\n- Weapon \n- Bullets\n- Slope and wall detection\n- Enemies