Scrolling Platformer Engine

Instructions: use with credit

@Stage\n\n@Player\n\ndefine get dir (first dir)\nswitch costume to (hitbox v)\nmove [-1] steps with dir: ((first dir) - (90))\nif <touching (hitboxes v)?> then\n    switch costume to (dir v)\n    set dir to [90]\n    try to find dir from [air] and with speed [-15] if i> [24] then stop progress\n    try to find dir from [hitbox] and with speed [15] if i> [24] then stop progress\n    set [start dir v] to (dir)\n    change dir by [-15]\n    try to find dir from [hitbox] and with speed [-15] if i> [24] then stop progress\n    set [dir v] to ((((dir) + (start dir)) / (2)) + (90))\n    if <([abs v] of ((dir) - (90)) ) > [44]> then\n        set dir to [90]\n    end\n    set dir to (dir)\nend\nmove [1] steps with dir: ((first dir) - (90))\nswitch costume to (hitbox v)\n\ndefine change dir by (dir)\nchange [dir v] by (round (dir))\npoint in direction (dir)\n\ndefine try to find dir from (hitbox/air) and with speed (speed) if i> (number) then stop progress\nset [i v] to [0]\nif <(hitbox/air) = [hitbox]> then\n    repeat until <touching (hitboxes v)?>\n        change [i v] by (1)\n        change dir by (speed)\n        if <(i) > (number)> then\n            stop [this script v]\n        end\n    end\nelse\n    if <(hitbox/air) = [air]> then\n        repeat until <not <touching (hitboxes v)?>>\n            change [i v] by (1)\n            change dir by (speed)\n            if <(i) > (number)> then\n                stop [this script v]\n            end\n        end\n    end\nend\n\ndefine set dir to (dir)\nset [dir v] to (round (dir))\npoint in direction (dir)\n\nwhen flag clicked\nbroadcast (Setup v) and wait\nforever\n    Tick\n    broadcast (Tick v) and wait\nend\n\ndefine Tick\nControls\nget dir (dir)\nchange [yvel v] by (((0) - <(yvel) > [-15]>) * (2))\nif <<(yvel) < [0]> and <(collision?) = [0]>> then\n    change dir by (((90) - (dir)) / (3))\nend\nmove (yvel) steps with dir: ((dir) - (90))\nCollision Y (yvel)\nif <<(item (5) of [controls v]) > [0]> and <(collision?) = [1]>> then\n    set [yvel v] to [20]\nend\nset [xvel v] to ((((([abs v] of (dir) ) - (90)) / (25)) * (collision?)) + (((2) * (item (6) of [controls v])) + ((xvel) * (0.8))))\nmove (round (xvel)) steps with dir: (dir)\nCollision X (round (xvel)) (dir)\nif <<(y) < [-480]> or <touching (danger v)?>> then\n    set [xvel v] to [0]\n    set [yvel v] to [0]\n    set [x v] to (cx)\n    set [y v] to (cy)\nend\nCamera Move\nswitch costume to ((item (6) of [controls v]) + (2))\n\ndefine move (step count) steps with dir: (dir)\nchange [x v] by (([sin v] of (dir) ) * (step count))\nchange [y v] by (([cos v] of (dir) ) * (step count))\npos\n\ndefine pos\nswitch costume to (position hack v)\ngo to x: ((x) - (CamX)) y: ((y) - (CamY))\nswitch costume to (hitbox v)\n\ndefine Controls\ndelete all of [controls v]\nadd (<<<key (w v) pressed?> or <key (up arrow v) pressed?>> or <<mouse down?> and <(mouse y) > (y position)>>> - (0)) to [controls v]\nadd (<<<key (s v) pressed?> or <key (down arrow v) pressed?>> or <<mouse down?> and <(mouse y) < (y position)>>> - (0)) to [controls v]\nadd (<<<key (d v) pressed?> or <key (right arrow v) pressed?>> or <<mouse down?> and <(mouse x) > (x position)>>> - (0)) to [controls v]\nadd (<<<key (a v) pressed?> or <key (left arrow v) pressed?>> or <<mouse down?> and <(mouse x) < (x position)>>> - (0)) to [controls v]\nadd ((item (1) of [controls v]) - (item (2) of [controls v])) to [controls v]\nadd ((item (3) of [controls v]) - (item (4) of [controls v])) to [controls v]\n\ndefine Collision X (sx) (dir)\nif <([abs v] of ((1) / (sx)) ) = [Infinity]> then\n\ndefine Collision Y (sy)\nset [collision? v] to [0]\nif <([abs v] of ((1) / (sy)) ) = [Infinity]> then\n\ndefine Camera Move\nchange [camx v] by (round (((x) - (CamX)) / (3)))\nchange [camy v] by (round (((y) - (CamY)) / (7)))\nif <(CamY) < [-300]> then\n    set [camy v] to [-300]\nend\npos\n\nwhen I receive [setup v]\nset dir to [90]\nset [cx v] to [0]\nset [cy v] to [200]\nset [x v] to [0]\nset [y v] to [200]\nset [xvel v] to [0]\nset [yvel v] to [0]\nset [camx v] to [0]\nset [camy v] to [100]\npos\n\n@Hitboxes\n\nwhen I receive [tick v]\nPosition at x: ((x) - (CamX)) y: ((y) - (CamY)) costume: (costume)\n\nwhen I receive [setup v]\ncreate a clone at x: [0] y: [0] with costume: [2]\ncreate a clone at x: [330] y: [0] with costume: [3]\ncreate a clone at x: [760] y: [0] with costume: [4]\ncreate a clone at x: [1300] y: [0] with costume: [5]\n\ndefine Position at x: (x) y: (y) costume: (costume)\nif <(Clone?) > [0]> then\n    set [ghost v] effect to (100)\n    switch costume to (position hack v)\n    go to x: (x) y: (y)\n    if <<(x) = (x position)> and <(y) = (y position)>> then\n        show\n    else\n        hide\n    end\n    switch costume to (costume)\nend\n\ndefine create a clone at x: (x) y: (y) with costume: (costume)\nset [x v] to (x)\nset [y v] to (y)\nset [costume v] to (costume)\nset [clone? v] to [1]\ncreate clone of (_myself_ v)\nset [clone? v] to [0]\n\n@Vectors\n\nwhen I receive [tick v]\nPosition at x: ((x) - (CamX)) y: ((y) - (CamY)) costume: (costume)\n\nwhen I receive [setup v]\ncreate a clone at x: [0] y: [0] with costume: [2]\ncreate a clone at x: [330] y: [0] with costume: [3]\ncreate a clone at x: [760] y: [0] with costume: [4]\ncreate a clone at x: [1300] y: [0] with costume: [5]\n\ndefine Position at x: (x) y: (y) costume: (costume)\nif <(Clone?) > [0]> then\n    switch costume to (position hack v)\n    go to x: (x) y: (y)\n    if <<(x) = (x position)> and <(y) = (y position)>> then\n        show\n    else\n        hide\n    end\n    switch costume to (costume)\nend\n\ndefine create a clone at x: (x) y: (y) with costume: (costume)\nset [x v] to (x)\nset [y v] to (y)\nset [costume v] to (costume)\nset [clone? v] to [1]\ncreate clone of (_myself_ v)\nset [clone? v] to [0]\n\n@Checkpoints\n\nwhen I receive [tick v]\nPosition at x: ((x) - (CamX)) y: ((y) - (CamY)) costume: (costume)\n\nwhen I receive [setup v]\ncreate a clone at x: [900] y: [25]\n\ndefine Position at x: (x) y: (y) costume: (costume)\nif <(Clone?) > [0]> then\n    if <<touching (player v)?> and <(costume) = [3]>> then\n        point in direction (165)\n        set [costume v] to [2]\n        set [cx v] to (x)\n        set [cy v] to ((y) + (50))\n    end\n    switch costume to (position hack v)\n    go to x: (x) y: (y)\n    turn right (((90) - (direction)) / (10)) degrees\n    if <<(x) = (x position)> and <(y) = (y position)>> then\n        show\n    else\n        hide\n    end\n    switch costume to (costume)\nend\n\ndefine create a clone at x: (x) y: (y)\npoint in direction (90)\ngo to [front v] layer\nset [x v] to (x)\nset [y v] to (y)\nset [costume v] to [3]\nset [clone? v] to [1]\ncreate clone of (_myself_ v)\nset [clone? v] to [0]\n\n@Danger\n\nwhen I receive [tick v]\nPosition at x: ((x) - (CamX)) y: ((y) - (CamY)) costume: (costume)\n\nwhen I receive [setup v]\ncreate a clone at x: [0] y: [0] with costume: [2]\ncreate a clone at x: [330] y: [0] with costume: [3]\ncreate a clone at x: [760] y: [0] with costume: [4]\n\ndefine Position at x: (x) y: (y) costume: (costume)\nif <(Clone?) > [0]> then\n    switch costume to (position hack v)\n    go to x: (x) y: (y)\n    if <<(x) = (x position)> and <(y) = (y position)>> then\n        show\n    else\n        hide\n    end\n    switch costume to (costume)\nend\n\ndefine create a clone at x: (x) y: (y) with costume: (costume)\nset [x v] to (x)\nset [y v] to (y)\nset [costume v] to (costume)\nset [clone? v] to [1]\ngo to [front v] layer\ncreate clone of (_myself_ v)\nset [clone? v] to [0]\n\n@TM\n\nwhen flag clicked\nshow\nset [ghost v] effect to (100)\nforever\n    go to [front v] layer\nend\n\n