Cloud Multiplayer Platformer
@Stage\n\nwhen flag clicked\nforever\n    play sound [Loading Music v] until done\nend\n\nwhen I receive [start music v]\nstop [other scripts in sprite v]\nforever\n    play sound [Play Music v] until done\nend\n\nwhen I receive [start loading music v]\nstop [other scripts in sprite v]\nforever\n    play sound [Loading Music v] until done\nend\n\n@Players\n\ndefine Movement (id)\nswitch costume to (hitbox v)\nif <<(speed y) < [4]> or <<key (up arrow v) pressed?> or <<<((mouse y) - (y position)) > [50]> and <mouse down?>> and <(Touching?) = [False]>>>> then\n    change [speed y v] by (-1)\nelse\n    change [speed y v] by (-2)\nend\nchange y by (speed y)\nTouch Ground <(speed y) > [0]>\nif <(wall jump) > [0]> then\n    change [wall jump v] by (-1)\nelse\n    set [speed x v] to ((speed x) * (0.7))\n    if <<key (left arrow v) pressed?> or <<<mouse down?> and <(x position) > (mouse x)>> and <(Touching?) = [False]>>> then\n        change [speed x v] by (-1.5)\n    end\n    if <<key (right arrow v) pressed?> or <<<mouse down?> and <(mouse x) > (x position)>> and <(Touching?) = [False]>>> then\n        change [speed x v] by (1.5)\n    end\nend\nif <(speed x) < [-0.5]> then\n    Walk (-90) (speed x)\nelse\n    if <(speed x) > [0.5]> then\n        Walk (90) (speed x)\n    else\n        set [frame v] to [0]\n    end\nend\nif <<key (up arrow v) pressed?> or <<<((mouse y) - (y position)) > [50]> and <mouse down?>> and <(Touching?) = [False]>>> 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    end\nelse\n    set [jump key v] to [0]\nend\nset [my x v] to (x position)\nset [my y v] to (y position)\nSet Costume\nSave My Data\nshow\nthink (Bubble)\n\nwhen I receive [initialise  v]\ngo to [front v] layer\ndelete all of [cloud buffer v]\nset [cloud timer v] to [0]\nset rotation style [left-right v]\nset [speed y v] to [0]\nset [falling? v] to [10]\nhide\nset [bubble v] to (username)\nset [clone id v] to [0]\nrepeat (11)\n    change [clone id v] by (1)\n    create clone of (_myself_ v)\nend\n\nwhen I receive [tick v]\nTick (Clone ID)\n\ndefine Player (id) (length)\nif <not <(id) = [11]>> then\n    if <(item (id) of [active check v]) = [Off]> then\n        hide\n    else\n        if <(item (((id) * (length)) - (0)) of [cloud list v]) = (Ground Costume)> then\n            show\n            set [color v] effect to (item (((id) * (length)) - (2)) of [cloud list v])\n            think (item (((id) * (length)) - (3)) of [cloud list v])\n            point in direction (item (((id) * (length)) - (1)) of [cloud list v])\n            if <not <(item (((id) * (length)) - (4)) of [cloud list v]) = (change)>> then\n                set [change v] to (item (((id) * (length)) - (4)) of [cloud list v])\n                set [n v] to [14]\n                repeat (3)\n                    change [n v] by (-3)\n                    add (item (((id) * (length)) - ((n) + (2))) of [cloud list v]) to [cloud buffer v]\n                    add (item (((id) * (length)) - ((n) + (1))) of [cloud list v]) to [cloud buffer v]\n                    add (item (((id) * (length)) - (n)) of [cloud list v]) to [cloud buffer v]\n                end\n            end\n            if <(length of [cloud buffer v]) > [0]> then\n                set x to (item (1) of [cloud buffer v])\n                delete (1) of [cloud buffer v]\n                set y to (item (1) of [cloud buffer v])\n                delete (1) of [cloud buffer v]\n                switch costume to (item (1) of [cloud buffer v])\n                delete (1) of [cloud buffer v]\n            end\n        else\n            hide\n        end\n    end\nelse\n    hide\nend\n\ndefine Save My Data\nadd (x position) to [player buffer v]\nadd (y position) to [player buffer v]\nadd (costume [number v]) to [player buffer v]\nchange [cloud timer v] by (1)\nif <(Cloud Timer) < [3]> then\n    stop [this script v]\nend\nset [cloud timer v] to [0]\ndelete all of [my list v]\nrepeat (length of [player buffer v])\n    add (item (1) of [player buffer v]) to [my list v]\n    delete (1) of [player buffer v]\nend\nadd (pick random (9999) to (999999)) to [my list v]\nadd (Bubble) to [my list v]\nadd (color) to [my list v]\nadd (direction) to [my list v]\nadd (Ground Costume) to [my list v]\n\ndefine Tick (id)\nif <(id) = (@PlayerSlot)> then\n    Movement (id)\nelse\n    Player (id) [14]\nend\n\ndefine Touch Ground <up?>\nchange [falling? v] by (1)\nrepeat until <not <touching (ground v)?>>\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    set [speed y v] to [0]\nend\n\ndefine Walk (direction) (speed)\npoint in direction (direction)\nchange x by (speed)\nset [slope v] to [0]\nrepeat until <<<(slope) = [8]> or <not <touching (ground v)?>>> or <<<((mouse y) - (y position)) > [50]> and <mouse down?>> and <(Touching?) = [False]>>>\n    change y by (1)\n    change [slope v] by (1)\nend\nif <(slope) = [8]> then\n    change x by ((0) - (speed))\n    change y by ((0) - (slope))\n    if <<<key (up arrow v) pressed?> or <<<((mouse y) - (y position)) > [50]> and <mouse down?>> and <(Touching?) = [False]>>> and <([abs v] of (speed) ) > [3]>> then\n        if <(wall jump) = [0]> 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        end\n    else\n        set [speed x v] to [0]\n    end\nend\nif <(speed) < [0]> then\n    change [frame v] by ((speed) / (-8))\nelse\n    change [frame v] by ((speed) / (8))\nend\n\ndefine Set Costume\nset [color v] effect to (color)\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 ((4) + ((frame) mod (8))) )\n    end\nelse\n    if <(speed y) > [0]> then\n        switch costume to (jump_1 v)\n    else\n        switch costume to (fall_1 v)\n    end\nend\n\nwhen [any v] key pressed\nif <key (1 v) pressed?> then\n    set [bubble v] to (item (1) of [messages v])\n    wait (2) seconds\n    set [bubble v] to (username)\nelse\n    if <key (2 v) pressed?> then\n        set [bubble v] to (item (2) of [messages v])\n        wait (2) seconds\n        set [bubble v] to (username)\n    else\n        if <key (3 v) pressed?> then\n            set [bubble v] to (item (3) of [messages v])\n            wait (2) seconds\n            set [bubble v] to (username)\n        else\n            if <key (4 v) pressed?> then\n                set [bubble v] to (item (4) of [messages v])\n                wait (2) seconds\n                set [bubble v] to (username)\n            else\n                if <key (5 v) pressed?> then\n                    set [bubble v] to (item (5) of [messages v])\n                    wait (2) seconds\n                    set [bubble v] to (username)\n                else\n                    if <key (6 v) pressed?> then\n                        set [bubble v] to (item (6) of [messages v])\n                        wait (2) seconds\n                        set [bubble v] to (username)\n                    else\n                        if <key (7 v) pressed?> then\n                            set [bubble v] to (item (7) of [messages v])\n                            wait (2) seconds\n                            set [bubble v] to (username)\n                        else\n                            if <key (8 v) pressed?> then\n                                set [bubble v] to (item (8) of [messages v])\n                                wait (2) seconds\n                                set [bubble v] to (username)\n                            else\n                                if <key (9 v) pressed?> then\n                                    set [bubble v] to (item (9) of [messages v])\n                                    wait (2) seconds\n                                    set [bubble v] to (username)\n                                else\n                                end\n                            end\n                        end\n                    end\n                end\n            end\n        end\n    end\nend\n\n@Cloud\n\ndefine Decode (data)\ndelete all of [cloud list v]\nset [output v] to []\nset [i v] to [0]\nrepeat ((length of (data)) / (2))\n    change [i v] by (2)\n    switch costume to (join (letter ((I) - (1)) of (data)) (letter (I) of (data)))\n    if <(costume [name v]) = [~]> then\n        add (Output) to [cloud list v]\n        set [output v] to []\n    else\n        set [output v] to (join (Output) (costume [name v]))\n    end\nend\n\ndefine Encode\nset [output v] to []\nset [n v] to [0]\nrepeat (length of [my list v])\n    set [i v] to [0]\n    change [n v] by (1)\n    repeat (length of (item (n) of [my list v]))\n        change [i v] by (1)\n        switch costume to (letter (I) of (item (n) of [my list v]))\n        if <(costume [number v]) < [10]> then\n            set [output v] to (join (Output) (join [0] (costume [number v])))\n        else\n            set [output v] to (join (Output) (costume [number v]))\n        end\n    end\n    set [output v] to (join (Output) [53])\nend\n\ndefine Update Players List (id)\nif <(id) = [1]> then\n    set [player list v] to [0]\n    delete all of [check v]\n    repeat (10)\n        change [player list v] by (1)\n        add (item (((Player List) * (14)) - (4)) of [cloud list v]) to [check v]\n    end\nelse\n    if <(id) = [2]> then\n        set [player list v] to [0]\n        repeat (10)\n            change [player list v] by (1)\n            if <not <(@PlayerSlot) = (Player List)>> then\n                if <(item (Player List) of [check v]) = (item (((Player List) * (14)) - (4)) of [cloud list v])> then\n                    replace item (Player List) of [active check v] with [Off]\n                else\n                    replace item (Player List) of [active check v] with [On]\n                end\n            end\n        end\n    end\nend\n\nwhen I receive [initialise  v]\ndelete all of [active check v]\nrepeat (10)\n    add [off] to [active check v]\nend\n\nwhen I receive [start v]\nforever\n    Update Players List [1]\n    wait (1) seconds\n    Update Players List [2]\nend\n\nwhen I receive [get data v]\nDecode Data\n\ndefine Save Data (id)\nEncode\nif <(id) = [1]> then\n    set [☁ p1 v] to (Output)\nelse\n    if <(id) = [2]> then\n        set [☁ p2 v] to (Output)\n    else\n        if <(id) = [3]> then\n            set [☁ p3 v] to (Output)\n        else\n            if <(id) = [4]> then\n                set [☁ p4 v] to (Output)\n            else\n                if <(id) = [5]> then\n                    set [☁ p5 v] to (Output)\n                else\n                    if <(id) = [6]> then\n                        set [☁ p6 v] to (Output)\n                    else\n                        if <(id) = [7]> then\n                            set [☁ p7 v] to (Output)\n                        else\n                            if <(id) = [8]> then\n                                set [☁ p8 v] to (Output)\n                            else\n                                if <(id) = [9]> then\n                                    set [☁ p9 v] to (Output)\n                                else\n                                    if <(id) = [10]> then\n                                        set [☁ p10 v] to (Output)\n                                    end\n                                end\n                            end\n                        end\n                    end\n                end\n            end\n        end\n    end\nend\n\nwhen I receive [tick v]\nDecode Data\nSave Data (@PlayerSlot)\nDetermine Players\n\ndefine Decode Data\nDecode (join (☁ P1) (join (☁ P2) (join (☁ P3) (join (☁ P4) (join (☁ P5) (join (☁ P6) (join (☁ P7) (join (☁ P8) (join (☁ P9) (☁ P10))))))))))\n\ndefine Determine Players\nset [players v] to [1]\nset [i v] to [0]\nrepeat (10)\n    change [i v] by (1)\n    if <(item (I) of [active check v]) = [On]> then\n        change [players v] by (1)\n    end\nend\n\nwhen I receive [do thingy v]\nDecode Data\nUpdate Players List [1]\nwait (1) seconds\nDecode Data\nUpdate Players List [2]\n\n@Above Layer Ground\n\nwhen I receive [initialise  v]\nswitch costume to (cloud ground2 v)\ngo to x: (0) y: (0)\nhide\n\nwhen I receive [start v]\nshow\n\n@Banners\n\ndefine Turbo mode detector\nreset timer\nrepeat (10)\n    move (0) steps\nend\nif <(timer) > [0.1]> then\n    set [turbo mode? v] to [false]\nelse\n    set [turbo mode? v] to [true]\n    broadcast (Turbo Mode v) and wait\nend\n\nwhen I receive [start v]\nif <(Full?) = [True]> then\n    repeat (10)\n        change [brightness v] effect by (-10)\n    end\n    switch costume to (full v)\n    repeat (10)\n        change [brightness v] effect by (10)\n    end\n    clear graphic effects\n    wait (3) seconds\n    broadcast (Spectator Mode v)\nelse\n    repeat (10)\n        change [ghost v] effect by (10)\n    end\n    hide\nend\n\nwhen I receive [initialise  v]\nswitch costume to (connecting v)\nshow\nclear graphic effects\ngo to x: (0) y: (0)\ngo to [front v] layer\nset [full? v] to [False]\nset [kick v] to [False]\nset [moved? v] to [800]\n\nwhen I receive [you have been booted. v]\nstop [other scripts in sprite v]\nset [@playerslot v] to [0]\nswitch costume to (booted v)\nshow\nclear graphic effects\ngo to x: (0) y: (0)\ngo to [front v] layer\nwait (3) seconds\nbroadcast (Spectator Mode v)\nbroadcast (Start Loading Music v)\n\nwhen I receive [tick v]\nif <<<<key (any v) pressed?> or <<(@PlayerSlot) = [0]> or <(username) = [Cloud-Multiplayer]>>> or <mouse down?>> or <(Full?) = [True]>> then\n    set [moved? v] to [800]\nend\nchange [moved? v] by (-1)\nCheck (username)\nif <(Moved?) < [1]> then\n    broadcast (You have been booted. v)\nend\n\nwhen flag clicked\nbroadcast (Initialise  v) and wait\nGet Player Slot\nset [moved? v] to [600]\nif <not <(@PlayerSlot) > [0]>> then\n    set [full? v] to [True]\nend\nbroadcast (start v)\nforever\n    broadcast (Tick v) and wait\nend\n\ndefine Get Player Slot\nset [@playerslot v] to [0]\nbroadcast (Get Data v) and wait\nset [moved? v] to [0]\ndelete all of [check v]\nrepeat (10)\n    change [moved? v] by (1)\n    add (item (((Moved?) * (14)) - (4)) of [cloud list v]) to [check v]\nend\nwait (pick random (2) to (3.2)) seconds\nbroadcast (Start Music v)\nbroadcast (Get Data v) and wait\nset [moved? v] to [0]\nrepeat (10)\n    change [moved? v] by (1)\n    if <(item (Moved?) of [check v]) = (item (((Moved?) * (14)) - (4)) of [cloud list v])> then\n        set [@playerslot v] to (Moved?)\n        stop [this script v]\n    end\nend\n\nwhen I receive [turbo mode v]\ngo to [front v] layer\nclear graphic effects\nswitch costume to (turbo mode v)\nshow\nstop [all v]\n\nwhen I receive [start v]\nforever\n    Turbo mode detector\nend\n\ndefine Check (username)\nset [i v] to [0]\ndelete all of [other check v]\nrepeat (10)\n    change [i v] by (1)\n    if <<not <(i) = (@PlayerSlot)>> and <not <(item (i) of [active check v]) = [Off]>>> then\n        add (item ((i) * (4)) of [cloud list v]) to [other check v]\n    end\nend\nset [i v] to [0]\nrepeat (length of [other check v])\n    change [i v] by (1)\n    if <<(item (i) of [other check v]) = (username)> and <(@PlayerSlot) < (i)>> then\n        set [@playerslot v] to [0]\n    end\nend\n\nwhen I receive [spectator mode v]\nswitch costume to (spectator mode v)\nshow\nclear graphic effects\ngo to x: (0) y: (0)\ngo to [front v] layer\n\nwhen I receive [start loading music v]\nforever\n    broadcast (Tick v) and wait\nend\n\n@Thumbnail\n\nwhen I receive [initialise  v]\nclear graphic effects\nset size to (100) %\ngo to [front v] layer\nset [ghost v] effect to (100)\ngo to x: (0) y: (0)\n\n@Ground\n\nwhen I receive [tick v]\nshow\nset [ghost v] effect to (100)\nset [ground costume v] to (costume [number v])\n\nwhen I receive [initialise  v]\ngo to x: (0) y: (0)\nhide\n\n@Color Wheel\n\nwhen I receive [initialise  v]\nset [color key v] to [0]\nset [color v] to [0]\n\nwhen I receive [tick v]\nif <(@PlayerSlot) = [0]> then\n    hide\nelse\n    if <(Color Key) = [1]> then\n        show\n        if <(item (((@PlayerSlot) * (14)) - (1)) of [cloud list v]) = [90]> then\n            go to x: ((-45) + (my x)) y: ((25) + (my y))\n        else\n            if <(item (((@PlayerSlot) * (14)) - (1)) of [cloud list v]) = [-90]> then\n                go to x: ((45) + (my x)) y: ((25) + (my y))\n            end\n        end\n    else\n        hide\n    end\nend\n\nwhen [c v] key pressed\nif <(Color Key) = [1]> then\n    set [color key v] to [0]\nelse\n    set [color key v] to [1]\nend\n\n@Selector\n\ndefine set color (with start at (degrees) °)\nif <(degrees) = [0]> then\n    if <(round (((direction) * (200)) / (360))) < [0]> then\n        set [color v] to ((200) + (round (((direction) * (200)) / (360))))\n    else\n        set [color v] to (round (((direction) * (200)) / (360)))\n    end\nend\n\nwhen I receive [initialise  v]\ngo to (color wheel v)\npoint in direction (0)\nhide\n\nwhen I receive [start v]\nforever\n    if <<mouse down?> and <touching (mouse-pointer v)?>> then\n        set [touching? v] to [True]\n        set size to (80) %\n        broadcast (set color v)\n        repeat until <not <mouse down?>>\n            go to [front v] layer\n            point towards (mouse-pointer v)\n            point in direction (round (direction))\n            set color (with start at [0] °)\n        end\n    else\n        set [touching? v] to [False]\n    end\nend\n\nwhen I receive [tick v]\nif <(@PlayerSlot) = [0]> then\n    hide\nelse\n    if <(Color Key) = [1]> then\n        show\n        go to (color wheel v)\n    else\n        hide\n    end\nend\n\n