platformer engine with moving camera

Instructions: L+R Arrows, A, D - Move left/right\nSpace, Z, W - Jump\nU+D Arrows - Look up/down (also pan camera)\nQ - Reset position (debug feature i guess)

@Stage\n\n@Alex\n\ndefine Ground/Physics <up?>\nif <<<key (space v) pressed?> or <<key (z v) pressed?> or <key (w v) pressed?>>> and <not <(vel y) < [-4]>>> then\n    change [vel y v] by (-1)\nelse\n    if <(vel y) < [-3]> then\n        change [vel y v] by (-1)\n    else\n        change [vel y v] by (-3)\n    end\nend\nset [old falling v] to (falling)\nchange y by (vel y)\nchange [falling v] by (1)\nif <touching (ground v)?> then\n    repeat ([abs v] of (vel y) )\n        if <touching (ground v)?> then\n            if <up?> then\n                change y by (-1)\n            else\n                set [falling v] to [0]\n                change y by (1)\n            end\n        end\n        set [vel y v] to [0]\n    end\n    if <<<key (space v) pressed?> or <<key (z v) pressed?> or <key (w v) pressed?>>> and <(Jump key) = [0]>> then\n        if <not <up?>> then\n            set [falling v] to [3]\n            set [jump key v] to [1]\n            set [vel y v] to ((12.5) + (([abs v] of (vel x) ) / (4)))\n            start sound [Jump v]\n        end\n    else\n        if <not <<key (z v) pressed?> or <<key (space v) pressed?> or <key (w v) pressed?>>>> then\n            set [jump key v] to [0]\n        end\n    end\nend\nif <(slope) > [0]> then\n\nwhen flag clicked\nStart-up\nGame loop\n\ndefine Walking (slope limit)\nset [slope v] to [0]\nif <(wall jump) > [0 ]> then\n    change [wall jump v] by (-1)\nelse\n    if <(falling) > [3]> then\n        if <<key (a v) pressed?> or <key (left arrow v) pressed?>> then\n            change [vel x v] by (-1.2)\n            set [facing v] to [L]\n        end\n        if <<key (d v) pressed?> or <key (right arrow v) pressed?>> then\n            change [vel x v] by (1.2)\n            set [facing v] to [R]\n        end\n        set [vel x v] to ((vel x) * ((5) / (6)))\n    else\n        if <<key (a v) pressed?> or <key (left arrow v) pressed?>> then\n            change [vel x v] by (-4)\n            set [facing v] to [L]\n        end\n        if <<key (d v) pressed?> or <key (right arrow v) pressed?>> then\n            change [vel x v] by (4)\n            set [facing v] to [R]\n        end\n        set [vel x v] to ((vel x) * (0.6))\n    end\nend\nif <([abs v] of (vel x) ) > [1]> then\n    change x by (vel x)\nend\nrepeat until <<(slope) = (slope limit)> or <not <touching (ground v)?>>>\n    change [slope v] by (1)\n    change y by (1)\n    if <(slope) > [1]> then\n        if <(vel x) > [1]> then\n            turn left (slope) degrees\n        else\n            if <(vel x) < [-1]> then\n                turn right (slope) degrees\n            end\n        end\n        if <(direction) < ((90) - ((slope) * (6)))> then\n            turn right (slope) degrees\n        else\n            if <(direction) > ((90) - ((slope) * (-6)))> then\n                turn left (slope) degrees\n            end\n        end\n    else\n        if <(vel x) > [1]> then\n            turn left (slope) degrees\n        else\n            if <(vel x) < [-1]> then\n                turn right (slope) degrees\n            end\n        end\n        if <(direction) < ((90) - ((slope) * (6)))> then\n            turn right (slope) degrees\n        else\n            if <(direction) > ((90) - ((slope) * (-6)))> then\n                turn left (slope) degrees\n            end\n        end\n    end\nend\nif <(slope) = (slope limit)> then\n    change y by ((0) - (slope))\n    repeat ([abs v] of (vel x) )\n        if <touching (ground v)?> then\n            if <(vel x) > [1]> then\n                change x by (-2)\n            else\n                if <(vel x) < [-1]> then\n                    change x by (2)\n                end\n            end\n        end\n    end\n    if <(vel y) < [-3]> then\n    if <<<key (space v) pressed?> or <<key (z v) pressed?> or <key (w v) pressed?>>> and <(falling) > [3]>> then\n        set [jump key v] to [1]\n        set [wall jump v] to [10]\n        set [vel y v] to ([abs v] of ((vel x) * (2)) )\n        set [vel x v] to ((vel x) * (-1))\n        if <(facing) = [R]> then\n            set [facing v] to [L]\n        else\n            set [facing v] to [R]\n        end\n    else\n        set [vel x v] to [0]\n    end\nend\nif <(slope) > [0s]> then\n    set [oldslope v] to (slope)\nend\n\npoint in direction (135)\n\nif <(direction) < [45]> then\n    point in direction (45)\nelse\n    if <(direction) > [135]> then\n        point in direction (135)\n    end\nend\n\ndefine Start-up\nset [vel x v] to [0]\nset [vel y v] to [0]\nset [scroll x v] to [0]\nset [scroll y v] to [0]\nset [xcameracenter v] to [0]\nset [ycameracenter v] to [0]\nset [cameraxlocked v] to [0]\npoint in direction (90)\ngo to x: (0) y: (0)\nbroadcast (tick v)\n\ndefine Game loop\nStart-up\nforever\n    erase all\n    switch costume to (hitbox v)\n    set rotation style [don't rotate v]\n    Ground/Physics <(vel y) > [0]>\n    Walking (8)\n    Sound effects\n    set rotation style [all around v]\n    change [counter v] by (1)\n    Set costume\n    if <(timer) > [1]> then\n        reset timer\n        set [fps v] to (counter)\n        set [counter v] to [0]\n    end\n    Scroll screen\nend\n\nwhen I start as a clone\nset rotation style [all around v]\nrepeat (4)\n    change [ghost v] effect by (25)\nend\ndelete this clone\n\npoint in direction (90)\n\n\n\ndefine Sound effects\nif <<(falling) = [0]> and <(old falling) > [0]>> then\n    start sound [Landing v]\nelse\n    if <<([abs v] of (vel x) ) > [5]> and <(falling) = [0]>> then\n        change [i v] by (([abs v] of (vel x) ) / (36))\n        if <(i) > [1]> then\n            set [i v] to [0]\n            start sound [Foot step 2 v]\n        end\n    else\n        set [i v] to [0]\n    end\nend\n\ndefine Set costume\nswitch costume to (join [AlexIdle] (facing))\nchange [blinktimer v] by (-1)\nif <(blinkTimer) < (pick random (-60) to (-1024))> then\n    set [blinktimer v] to [3]\nend\nif <(blinkTimer) > [0]> then\n    switch costume to (join [AlexBlink] (facing))\nend\nif <(lookUp) > [0]> then\n    switch costume to (join [AlexLookUp] (facing))\nend\nif <[0] > (lookUp)> then\n    switch costume to (join [AlexLookDown] (facing))\nend\nif <([abs v] of (vel x) ) > [1]> then\n    change [running v] by (([abs v] of (vel x) ) / (12))\n    switch costume to (join [AlexRun] (join (facing) ((round (running)) mod (6))))\nelse\n    set [running v] to [0]\nend\nif <<(falling) > [0]> and <(Jump key) = [1]>> then\n    if <(vel y) > [3]> then\n        if <(wall jump) > [0]> then\n            switch costume to (join [AlexJump] (join (facing) [3]))\n        else\n            switch costume to (join [AlexJump] (join (facing) [0]))\n        end\n    else\n        if <(vel y) > [-3]> then\n            switch costume to (join [AlexJump] (join (facing) [1]))\n        else\n            switch costume to (join [AlexJump] (join (facing) [2]))\n        end\n    end\nend\n\ndefine Scroll screen\nset [scroll x v] to [0]\nset [scroll y v] to [0]\nif <([abs v] of ((x position) - (xCameraCenter)) ) > [30]> then\n    set [scroll x v] to ([floor v] of ((((30) * (([abs v] of ((x position) - (xCameraCenter)) ) / ((x position) - (xCameraCenter)))) - ((x position) - (xCameraCenter))) / (3)) )\nend\nset [scroll y v] to ([floor v] of (((yCameraCenter) - (y position)) / (3)) )\nbroadcast (tick v)\nif <(cameraXLocked) = [0]> then\n    change x by (Scroll X)\nend\nif <(cameraYLocked) = [0]> then\n    change y by (Scroll Y)\nend\nif <<key (up arrow v) pressed?> and <not <key (down arrow v) pressed?>>> then\n    change [lookup v] by (1)\nelse\n    if <<key (down arrow v) pressed?> and <not <key (up arrow v) pressed?>>> then\n        change [lookup v] by (-1)\n    else\n        set [lookup v] to [0]\n    end\nend\nif <(lookUp) = [0]> then\n    if <[0] > (yCameraCenter)> then\n        change [ycameracenter v] by (10)\n    else\n        if <(yCameraCenter) > [0]> then\n            change [ycameracenter v] by (-10)\n        else\n        end\n    end\n    if <([abs v] of (yCameraCenter) ) < [10]> then\n        set [ycameracenter v] to [0]\n    end\nelse\n    if <(lookUp) > [32]> then\n        if <(yCameraCenter) > [-80]> then\n            change [ycameracenter v] by (-3)\n        else\n            set [ycameracenter v] to [-80]\n        end\n    end\n    if <[-32] > (lookUp)> then\n        if <[80] > (yCameraCenter)> then\n            change [ycameracenter v] by (3)\n        else\n            set [ycameracenter v] to [80]\n        end\n    end\nend\n\nset [xcameracenter v] to [0]\nset [ycameracenter v] to [0]\n\nset [cameraxlocked v] to [0]\n\nrepeat (10)\n\nchange [xcameracenter v] by (3)\nchange [scroll x v] by (3)\nchange x by (3)\n\nif <(cameraXLocked) = [0]> then\n\nwhen [q v] key pressed\nStart-up\n\nif <(vel y) = [24]> then\n    start sound [Jump v]\nend\n\nchange [scroll y v] by (-3)\nchange y by (-3)\n\nif <(yCameraCenter) > [-80]> then\n    change [ycameracenter v] by (-4)\nend\n\npoint in direction (90)\n\n@Ground\n\nwhen I receive [tick v]\nset [cameraxlocked v] to [0]\nset [cameraylocked v] to [0]\nchange x by (Scroll X)\nchange y by (Scroll Y)\nif <(x position) > [720]> then\n    set x to (720)\n    set [cameraxlocked v] to [1]\nelse\n    if <[-720] > (x position)> then\n        set x to (-720)\n        set [cameraxlocked v] to [1]\n    else\n        set [cameraxlocked v] to [0]\n    end\nend\nif <(y position) > [540]> then\n    set y to (540)\n    set [cameraylocked v] to [1]\nelse\n    if <[-540] > (y position)> then\n        set y to (-540)\n        set [cameraylocked v] to [1]\n    else\n        set [cameraylocked v] to [0]\n    end\nend\n\nwhen flag clicked\nswitch costume to (costume2 v)\nset size to (400) %\nswitch costume to (costume5 v)\ngo to x: (720) y: (-540)\n\n\n\nif <[-720] > (x position)> then\n\n\nwhen [q v] key pressed\nswitch costume to (costume2 v)\nset size to (400) %\nswitch costume to (costume5 v)\ngo to x: (720) y: (-540)\n\n