[DEMO] Acorn - A Scrolling Platformer


@Stage\n\n@Main\n\nforever\n    change [scroll x v] by (-5)\n    if <(Scroll X) < [-980]> then\n        stop [this script v]\n    end\nend\n\nset [level v] to [2]\n\nset [scroll x v] to [890]\n\nwhen flag clicked\ngo to x: (0) y: (0)\nset size to (100) %\nswitch costume to (dot v)\nset size to (600) %\nforever\n    switch costume to (Level)\n    set x to (Scroll X)\nend\n\nchange [scroll x v] by (5)\n\n@Ground\n\nwhen flag clicked\ngo to x: (0) y: (0)\nset size to (100) %\nswitch costume to (dot v)\nset size to (600) %\nforever\n    switch costume to (Level)\n    set x to (Scroll X)\nend\n\n@Player_Codes\n\ndefine Gravity\nif <<(speed y) < [4]> or <<<key (w v) pressed?> or <key (up arrow v) pressed?>> or <key (space v) pressed?>>> then\n    change [speed y v] by (-1)\nelse\n    change [speed y v] by (-2)\nend\nchange y by (speed y)\nchange [falling? v] by (1)\n\nwhen I receive [start game v]\nif <(First Start?) = [1]> then\n    Reset Level\n    set [first start? v] to [0]\nend\nwait (0.3) seconds\nforever\n    switch costume to (hitbox v)\n    Controls - Jump, Crouch\n    Gravity\n    Check Hit Ceiling / Floor <(speed y) > [0]>\n    if <(y position) < [-160]> then\n        Set Costume\n        broadcast (Red v)\n        wait (0.3) seconds\n        Reset Level\n    end\n    if <(wall jump) > [0]> then\n        change [wall jump v] by (-1)\n    else\n        Controls - Left and Right\n    end\n    if <(speed x) < [-0.5]> then\n        Walk / Scroll (0) (speed x) max step (([ceiling v] of ([abs v] of ((speed x) * (1.3)) ) ) + (1))\n    else\n        if <(speed x) > [0.5]> then\n            Walk / Scroll (1) (speed x) max step (([ceiling v] of ([abs v] of ((speed x) * (1.3)) ) ) + (1))\n        else\n            set [frame v] to [0]\n        end\n    end\n    Set Costume\n    set [playerfalling? v] to (falling?)\nend\n\nwhen flag clicked\nhide\n\ndefine Controls - Jump, Crouch\nif <<<key (w v) pressed?> or <key (up arrow v) pressed?>> or <key (space v) pressed?>> then\n    if <<(jump key) = [0]> and <(falling?) < [3]>> then\n        set [speed y v] to [14]\n        set [falling? v] to [6]\n        set [jump key v] to [1]\n        if <(Jump Animation?) = [0]> then\n            broadcast (Jump Animation v)\n        end\n    end\nelse\n    set [jump key v] to [0]\nend\n\ndefine Controls - Left and Right\nset [speed x v] to ((speed x) * (0.7))\nif <<key (a v) pressed?> or <key (left arrow v) pressed?>> then\n    change [speed x v] by (-1.5)\nend\nif <<key (d v) pressed?> or <key (right arrow v) pressed?>> then\n    change [speed x v] by (1.5)\nend\n\nif <(speed y) > [0]> then\n    switch costume to (jump_1 v)\nelse\n    switch costume to (fall_1 v)\nend\n\ndefine Reset Level\nclear graphic effects\nswitch costume to (stand_1 v)\nshow\nset [ghost v] effect to (100)\nset [scroll x v] to [890]\nset rotation style [left-right v]\ngo to x: (-200) y: (-80)\npoint in direction (90)\nset size to (70) %\nreset timer\nset [speed x v] to [0]\nset [speed y v] to [0]\nset [falling? v] to [10]\nset [in platforrm v] to [1]\nset [frame v] to [0]\nset [wall jump v] to [0]\nbroadcast (Start Game v)\n\ndefine Check Hit Ceiling / Floor <>\nGet Touching <not >\nif <(touch) = [0]> then\n    set [in platforrm v] to [1]\nelse\n    if <<up?> and <(touch) = [1]>> then\n        set [in platforrm v] to [2]\n    end\nend\nrepeat until <(touch) < (in platforrm)>\n    if <up?> then\n        change y by (-1)\n    else\n        change y by (1)\n        set [falling? v] to [0]\n    end\n    Get Touching <not <up?>>\n    set [speed y v] to [0]\nend\n\ndefine None\nif <(speed x) < [0.5]> then\n    if <not <(Scroll X) > [890]>> then\n        change [scroll x v] by (((speed) - ((speed) + (speed))) + (0.6))\n    end\nelse\n    change [scroll x v] by ((join [-] (speed)) - (0.6))\nend\n\ndefine Get Touching <>\nif <touching (ground v)?> then\n    set [touch v] to [9]\nelse\n    if <<check platform?> and <touching (platforms v)?>> then\n        set [touch v] to [1]\n    else\n        set [touch v] to [0]\n    end\nend\n\nwhen I receive [reset level v]\nwait (0.3) seconds\nReset Level\n\ndefine Set Costume\nif <(falling?) < [6]> then\n    if <(frame) = [0]> then\n        switch costume to (stand_1 v)\n    else\n        switch costume to ([floor v] of ((2) + ((frame) mod (8))) )\n    end\nelse\n    switch costume to (stand_1 v)\nend\n\ndefine None\nif <(direction) = [0]> then\n    point in direction (90)\nelse\n    point in direction (-90)\nend\nif <(Scroll X) < [-980]> then\n    change x by (speed)\n    if <(x position) < [-201]> then\n        set x to (-200)\n        Scroll (Embed) (speed)\n    end\nelse\n    if <<(x position) > [-201]> and <(x position) < [-120]>> then\n        change x by (speed)\n        if <(x position) < [-201]> then\n            set x to (-200)\n            Scroll (Embed) (speed)\n        end\n        if <(x position) > [-120]> then\n            set x to (-121)\n            Scroll (Embed) (speed)\n        end\n    end\nend\nchange [frame v] by (([abs v] of (speed) ) / (8))\nset [slope v] to [0]\nGet Touching <(in platforrm) = [1]>\nrepeat until <<(slope) = (step)> or <(touch) = [0]>>\n    change y by (1)\n    change [slope v] by (1)\n    Get Touching <(in platforrm) = [1]>\nend\nif <(slope) = (step)> then\n    change [scroll x v] by ((0) - (speed))\n    change y by ((0) - (slope))\n    if <<(touch) = [1]> and <(in platforrm) = [1]>> then\n        set [in platforrm v] to [2]\n        Walk / Scroll (direction) (speed) max step (step)\n        if <(speed x) = [0]> then\n            set [in platforrm v] to [1]\n        end\n    else\n        if <<<<<key (w v) pressed?> or <key (up arrow v) pressed?>> or <key (space v) pressed?>> and <([abs v] of (speed) ) > [3.5]>> and <(touch) > [1]>> then\n            set [speed x v] to ((-1.2) * (speed))\n            set [speed y v] to [11]\n            set [falling? v] to [6]\n            set [wall jump v] to [15]\n        else\n            set [speed x v] to [0]\n        end\n    end\nend\n\n@Game Manager\n\nwhen flag clicked\nset [first start? v] to [1]\nset [level v] to [1]\nset [scroll x v] to [890]\nhide\nbroadcast (Start Game v)\nbroadcast (White v)\n\nwhen flag clicked\nset [music v] to [1]\nforever\n    if <(First Start?) = [1]> then\n        set volume to (0) %\n        broadcast (Change Music v)\n        repeat until <(volume) = [100]>\n            change volume by (1)\n        end\n    else\n        set volume to (100) %\n        broadcast (Change Music v)\n    end\n    set [music_backup v] to (Level)\n    wait until <not <(Level) = (Music_Backup)>>\n    stop [other scripts in sprite v]\n    repeat until <(volume) = [0]>\n        change volume by (-1)\n    end\nend\n\nwhen flag clicked\nforever\n    if <([x position v] of [player_codes v]) > [220]> then\n        if <(Level) < [2]> then\n            change [level v] by (1)\n            broadcast (White v)\n            broadcast (Reset Level v)\n        end\n    end\nend\n\nwhen I receive [change music v]\nforever\n    play sound (Level) until done\nend\n\nbroadcast (Change Music v)\n\n@Screen Effect\n\nwhen I receive [white v]\ngo to [front v] layer\ngo [backward v] (1) layers\ngo to x: (0) y: (0)\nswitch costume to (Level)\ncreate clone of (_myself_ v)\nswitch costume to (white v)\nset [ghost v] effect to (100)\nshow\nrepeat (10)\n    change [ghost v] effect by (-10)\nend\nwait (0.5) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\nend\nhide\nclear graphic effects\n\nwhen I receive [red v]\nif <(Level) = [1]> then\n    switch costume to (red v)\nend\nif <(Level) = [2]> then\n    switch costume to (green v)\nend\ngo to [front v] layer\ngo to x: (0) y: (0)\nset [ghost v] effect to (100)\nshow\nrepeat (10)\n    change [ghost v] effect by (-10)\n    go to [front v] layer\nend\nwait (0.3) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\n    go to [front v] layer\nend\nhide\nclear graphic effects\n\nwhen I start as a clone\ngo to [front v] layer\ngo to x: (0) y: (0)\nset [ghost v] effect to (100)\nshow\nrepeat (10)\n    change [ghost v] effect by (-10)\nend\nwait (0.5) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\nend\nhide\nclear graphic effects\n\n@Player_Appearance\n\nwhen flag clicked\nhide\n\nwhen I receive [jump animation v]\nif <(Jump Animation?) = [0]> then\n    change [jump animation? v] by (1)\n    repeat (24)\n        set rotation style [all around v]\n        turn right (15) degrees\n        if <(PlayerFalling?) = [0]> then\n            set [jump animation? v] to [0]\n            point in direction (90)\n            stop [this script v]\n        end\n    end\n    set [jump animation? v] to [0]\n    point in direction (90)\n    wait (0.1) seconds\nend\n\ndefine Animate\n\nwhen I receive [start game v]\nwait (0.3) seconds\nset rotation style [all around v]\nshow\nclear graphic effects\nset [jump animation? v] to [0]\npoint in direction (90)\nforever\n    go to (player_codes v)\n    switch costume to (([costume # v] of [player_codes v]) + ((9) * ((Level) - (1))))\nend\n\nif <(Jump Animation?) = [0 ]> then\n    set rotation style [left-right v]\n    point in direction ([direction v] of [player_codes v])\nend\n\n@Platforms\n\nwhen flag clicked\ngo to x: (0) y: (0)\nset size to (100) %\nswitch costume to (dot v)\nset size to (600) %\nset [ghost v] effect to (100)\nforever\n    switch costume to (Level)\n    set x to (Scroll X)\nend\n\nclear graphic effects\n\n@Acorn_Thumb\n\nwhen flag clicked\nhide\n\nshow\nset size to (100) %\nclear graphic effects\ngo to [front v] layer\ngo to x: (0) y: (0)\npoint in direction (90)\n\n