Tile Scrolling Platformer Engine


@Stage\n\nwhen flag clicked\nforever\n    play sound [Azricle - Lost v] until done\nend\n\n@Mario\n\nwhen flag clicked\nLevel [2]\n\ndefine move camera\nif <(_Camera X) < [240]> then\n    set [_camera x v] to [240]\nend\nif <(_Camera Y) < [180]> then\n    set [_camera y v] to [180]\nend\nif <(_Camera X) > (((56) * (Gird Width)) - (240))> then\n    set [_camera x v] to (((56) * (Gird Width)) - (240))\nend\nif <(_Camera Y) > (((56) * (Gird Height)) - (180))> then\n    set [_camera y v] to (((56) * (Gird Height)) - (180))\nend\n\ndefine Physics\nif <key (up arrow v) pressed?> then\n    if <(jumpable) < [4]> then\n        set [speed y v] to [12]\n    end\nend\nchange [speed y v] by (-1.1)\nchange y by (round (speed y))\nif <key (left arrow v) pressed?> then\n    change [speed x v] by (-1.7)\nend\nif <key (right arrow v) pressed?> then\n    change [speed x v] by (1.7)\nend\nchange x by (round ((speed x) + (Derta Sx)))\nset [speed x v] to ((speed x) * (0.8))\nchange [_camera x v] by (((player x) - (_Camera X)) / (5))\nchange [_camera y v] by (((player y) - (_Camera Y)) / (5))\nif <(player y) < [-20]> then\n    set [die v] to [1]\nend\ncollision\n\ndefine go to (x) (y)\ngo to x: ((x) - (_Camera X)) y: ((y) - (_Camera Y))\n\ndefine add (x) (y) to collision\nset [col: x v] to ((([floor v] of ((x) / (56)) ) * (56)) + (28))\nset [col: y v] to ((([floor v] of ((y) / (56)) ) * (56)) + (28))\nadd (item (((((col: x) - (28)) / (56)) * (Gird Height)) + (((col: y) + (28)) / (56))) of [_tile gird v]) to [collision v]\n\ndefine tick\nPhysics\nmove camera\ngo to (player x) (player y)\n\ndefine collision\nset [collision_result v] to [0]\nif <(jumpable) > [0]> then\n    set [derta sx v] to [0]\nend\ndelete all of [collision v]\nadd ((player x) + (player size)) ((player y) + (player size)) to collision\nadd ((player x) + (player size)) ((player y) - (player size)) to collision\nadd ((player x) - (player size)) ((player y) - (player size)) to collision\nadd ((player x) - (player size)) ((player y) + (player size)) to collision\nif <<<[collision v] contains [3]?> or <[collision v] contains [4]?>> or <[collision v] contains [5]?>> then\n    set [collision_result v] to [1]\nelse\n    if <<<[collision v] contains [6]?> or <[collision v] contains [7]?>> or <[collision v] contains [8]?>> then\n        set [collision_result v] to [1]\n    else\n        if <<<[collision v] contains [9]?> or <[collision v] contains [10]?>> or <[collision v] contains [11]?>> then\n            set [collision_result v] to [1]\n        end\n    end\nend\nif <<touching color (#757474)?> and <[collision v] contains [12]?>> then\n    set [die v] to [1]\nend\n\n__init\n\nset [i v] to [0]\nrepeat (4)\n    change [i v] by (1)\nend\n\ndefine __init\nset [die v] to [0]\nset [player x v] to [100]\nset [player y v] to [100]\nset [player size v] to [14]\nset [speed x v] to [0]\nset [speed y v] to [0]\nset [jumpable v] to [5]\ngo to (player x) (player y)\ngo to [front v] layer\nshow\n\ndefine change y by (sy)\nchange [player y v] by (sy)\nchange [jumpable v] by (1)\ncollision\nif <(collision_result) = [1]> then\n    repeat until <not <(collision_result) = [1]>>\n        if <(sy) > [0]> then\n            change [player y v] by (-1)\n        else\n            change [player y v] by (1)\n            set [jumpable v] to [0]\n        end\n        set [speed y v] to [0]\n        collision\n    end\nend\n\ndefine change x by (sx)\nchange [player x v] by (sx)\ncollision\nif <(collision_result) = [1]> then\n    repeat (8)\n        change [player y v] by (1)\n        collision\n        if <not <(collision_result) = [1]>> then\n            stop [this script v]\n        end\n    end\n    change [player y v] by (-8)\n    repeat until <not <(collision_result) = [1]>>\n        if <(sx) > [0]> then\n            change [player x v] by (-1)\n        else\n            change [player x v] by (1)\n        end\n        collision\n    end\n    if <<key (right arrow v) pressed?> or <key (left arrow v) pressed?>> then\n        set [speed y v] to [-2]\n    end\n    if <key (up arrow v) pressed?> then\n        set [jumpable v] to [2]\n        if <(sx) > [0]> then\n            set [speed x v] to [-15]\n        else\n            set [speed x v] to [15]\n        end\n    end\nend\n\ndefine susbtitution jetsu (sx)\nchange [jetsu 1 time v] by (1)\nif <<key (1 v) pressed?> and <([abs v] of (sx) ) > [1]>> then\n    if <(jetsu 1 time) > [10]> then\n        set [jetsu 1 time v] to [0]\n        if <(sx) > [0]> then\n            change [player x v] by (96)\n        else\n            change [player x v] by (-96)\n        end\n        collision\n        repeat until <not <(collision_result) = [1]>>\n            if <(sx) > [0]> then\n                change [player x v] by (-1)\n            else\n                change [player x v] by (1)\n            end\n            collision\n        end\n    end\nend\n\nif <(collision_result) = [0]> then\n\nset [derta sx v] to (item (i) of [mv:△x v])\n\ndefine Level (#)\nset [__level v] to (#)\nbroadcast (Generate level v) and wait\nbroadcast (clone level tiles v) and wait\nset [_camera x v] to (player x)\nset [_camera y v] to (player y)\n__init\nforever\n    broadcast (position tiles v)\n    broadcast (tick v)\n    tick\n    if <(die) = [1]> then\n        __init\n    end\nend\n\n@blank\n\n@Tiles\n\ndefine setup\nshow\nset [clone? v] to [1]\nset [tile index v] to [1]\nset [tile x v] to [28]\nrepeat (Clone Count X)\n    set [tile y v] to [28]\n    repeat (Clone Count Y)\n        create clone of (_myself_ v)\n        change [tile y v] by (56)\n        change [tile index v] by (1)\n    end\n    change [tile x v] by (56)\n    change [tile index v] by ((Gird Height) - (Clone Count Y))\nend\nset [clone? v] to [0]\nhide\n\nwhen I receive [position tiles v]\nif <(clone?) = [1]> then\n    if <([abs v] of ((tile x) - (_Camera X)) ) > ((Clone Count X) * (28))> then\n        if <(tile x) > (_Camera X)> then\n            loop tile x (() - (Clone Count X))\n        else\n            loop tile x (Clone Count X)\n        end\n    end\n    if <([abs v] of ((tile y) - (_Camera Y)) ) > ((Clone Count Y) * (28))> then\n        if <(tile y) > (_Camera Y)> then\n            loop tile y (() - (Clone Count Y))\n        else\n            loop tile y (Clone Count Y)\n        end\n    end\n    switch costume to (big v)\n    go to x: ((tile x) - (_Camera X)) y: ((tile y) - (_Camera Y))\n    set [tile v] to (item (tile index) of [_tile gird v])\n    if <(tile) < [2]> then\n        set [tile v] to [2]\n    end\n    switch costume to (tile)\nend\n\ndefine loop tile x (tile skip)\nchange [tile x v] by ((56) * (tile skip))\nchange [tile index v] by ((tile skip) * (Gird Height))\n\ndefine loop tile y (tile skip)\nchange [tile y v] by ((56) * (tile skip))\nchange [tile index v] by (tile skip)\n\nwhen I receive [clone level tiles v]\nset size to (400) %\nset [clone count y v] to [8]\nset [clone count x v] to [10]\nsetup\n\nwhen flag clicked\nforever\n    set [editing x v] to ((([floor v] of (((mouse x) + (_Camera X)) / (56)) ) * (56)) + (28))\n    set [editing y v] to ((([floor v] of (((mouse y) + (_Camera Y)) / (56)) ) * (56)) + (28))\n    go to x: ((Editing X) - (_Camera X)) y: ((Editing Y) - (_Camera Y))\n    set [editing list # v] to (((((Editing X) - (28)) / (56)) * (Gird Height)) + (((Editing Y) + (28)) / (56)))\nend\n\nshow\n\nif <mouse down?> then\n    replace item (Editing list #) of [_tile gird v] with (costume [number v])\nend\n\n    replace item (Editing list #) of [_tile gird v] with [2]\nend\nif <key (space v) pressed?> then\n    next costume\n    if <(costume [number v]) < [2]> then\n        next costume\n    end\n    wait until <not <key (space v) pressed?>>\nend\n\n@Generate\n\ndefine Generate level\n\ndelete all of [_tile gird v]\nset [gird width v] to [30]\nset [gird height v] to [20]\nrepeat ((Gird Width) * (Gird Height))\n    add [2] to [_tile gird v]\nend\n\nadd [7] to [_tile gird v]\nrepeat ((Gird Height) - (2))\n    add [4] to [_tile gird v]\nend\nadd [8] to [_tile gird v]\nrepeat ((Gird Width) - (2))\n    add boxed column\nend\nadd [9] to [_tile gird v]\nrepeat ((Gird Height) - (2))\n    add [4] to [_tile gird v]\nend\nadd [10] to [_tile gird v]\n\ndefine add wall column\nrepeat (Gird Height)\n    add [11] to [_tile gird v]\nend\n\ndefine add boxed column\nadd [3] to [_tile gird v]\nrepeat ((Gird Height) - (2))\n    if <(pick random (1) to (10)) = [1]> then\n        add [3] to [_tile gird v]\n    else\n        add [2] to [_tile gird v]\n    end\nend\nadd [3] to [_tile gird v]\n\nwhen I receive [generate level v]\nGenerate level\n\nadd wall column\nadd wall column\n\ndefine add tile gird to level #\ndelete all of [level 2 v]\nfor each [i v] in (length of [_tile gird v])\n    add (item (i) of [_tile gird v]) to [level 2 v]\nend\n\nrepeat (10)\n\ndefine import from level (#)\ndelete all of [_tile gird v]\nif <(#) = [1]> then\n    set [gird width v] to [100]\n    set [gird height v] to [50]\n    for each [i v] in (length of [level 1 v])\n        add (item (i) of [level 1 v]) to [_tile gird v]\n    end\nelse\n    if <(#) = [2]> then\n        set [gird width v] to [500]\n        set [gird height v] to [200]\n        for each [i v] in (length of [level 2 v])\n            add (item (i) of [level 2 v]) to [_tile gird v]\n        end\n    end\nend\n\nimport from level [2]\n\n@bg\n\nwhen flag clicked\nset [clone id v] to [0]\ncreate clone of (_myself_ v)\nchange [clone id v] by (1)\n\nforever\n\nwhen I receive [tick v]\ngo to [back v] layer\nset [ghost v] effect to (50)\nswitch costume to (big v)\nset x to ((((_Camera X) / (-3)) mod (480)) - ((480) * (clone id)))\nswitch costume to (costume1 v)\n\ndefine go to (x) (y)\ngo to x: ((x) - (_Camera X)) y: ((y) - (_Camera Y))\n\n@packgame tiles\n\n@Thb\n\nwhen flag clicked\ngo to [front v] layer\nset [ghost v] effect to (100)\ngo to x: (0) y: (0)\n\ngo to x: (0) y: (0)\n\n