Christmas Platformer V 1.2

Instructions: The game now works somewhat.\narrow keys or wasd you know the drill\ngeneric christmas themed platformer

@Stage\n\nwhen flag clicked\nforever\n    play sound [June - Bobby Richards v] until done\nend\n\n@Main\n\nwhen flag clicked\nset size to (50) %\nset [ghost v] effect to (100)\nset [level v] to [1]\nset [timer v] to [0]\nResetPlayer\nbroadcast (startGame v)\nbroadcast (startNewLevel v)\n\ndefine ResetPlayer\ngo to x: (-200) y: (0)\nset [g_isplayerdead? v] to [No]\nset [g_velocity v] to [0]\nset [g_onground v] to [0]\nset [g_gravity v] to [-1]\nset [jumping v] to [0]\n\ndefine MovementControl\nif <<key (right arrow v) pressed?> or <key (d v) pressed?>> then\n    set [g_speedx v] to [7]\nend\nif <<key (left arrow v) pressed?> or <key (a v) pressed?>> then\n    set [g_speedx v] to [-7]\nend\nset [g_speedx v] to ((G_SpeedX) * (0.8))\nif <([abs v] of (G_SpeedX) ) > [0.9]> then\n    MovePlayer (round (G_SpeedX))\nend\n\ndefine Jumping\nif <<key (up arrow v) pressed?> or <key (w v) pressed?>> then\n    if <(G_onGround) > [0]> then\n        set [g_onground v] to [0]\n        set [jumping v] to [1]\n        set [g_velocity v] to [15]\n    end\nend\n\nwhen I receive [startgame v]\nshow\nrepeat until <(G_isPlayerDead?) = [Yes]>\n    broadcast (startAllControl v)\n    broadcast (checkPlatformDetection v)\n    broadcast (checkPlayerPosition v)\nend\n\nwhen I receive [startallcontrol v]\nMovementControl\nJumping\nif <<key (up arrow v) pressed?> or <key (w v) pressed?>> then\n    change [g_velocity v] by (G_Gravity)\nelse\n    change [g_velocity v] by ((G_Gravity) * (2))\nend\nchange y by (G_Velocity)\n\ndefine CheckHitGround <isjumping?>\nrepeat until <not <touching (ground v)?>>\n    if <isjumping?> then\n        change y by (-1)\n        set [g_velocity v] to [0]\n    else\n        change y by (1)\n        set [g_velocity v] to [0]\n        set [g_onground v] to [1]\n        if <(Jumping) = [1]> then\n            set [jumping v] to [0]\n        end\n    end\nend\n\nwhen I receive [checkplatformdetection v]\nCheckHitGround <(G_Velocity) > [0]>\n\ndefine MovePlayer (sx)\nchange x by (sx)\nset [deviation v] to [0]\nrepeat until <<(deviation) = [8]> or <not <touching (ground v)?>>>\n    change y by (1)\n    change [deviation v] by (1)\nend\nif <touching (ground v)?> then\n    if <<key (up arrow v) pressed?> or <key (w v) pressed?>> then\n        if <(sx) > [0]> then\n            set [g_speedx v] to [-16]\n        else\n            set [g_speedx v] to [16]\n        end\n        set [g_onground v] to [0]\n        set [jumping v] to [1]\n        set [g_velocity v] to [10]\n        change x by (G_SpeedX)\n    else\n        set [g_speedx v] to [0]\n    end\nend\nif <(deviation) = [8]> then\n    change x by ((0) - (sx))\n    change y by ((0) - (deviation))\nend\n\nwhen I receive [checkplayerposition v]\nforever\n    if <<touching color (#ff0000)?> or <(y position) < [-170]>> then\n        broadcast (Die v)\n    end\n    if <<touching (green flag v)?> and <(LEVEL) < [11]>> then\n        change [level v] by (1)\n        broadcast (startNewLevel v)\n    end\n    if <(G_isPlayerDead?) = [Yes]> then\n        wait (0.1) seconds\n        ResetPlayer\n        broadcast (startGame v)\n    end\nend\n\nwhen I receive [die v]\nset [g_isplayerdead? v] to [Yes]\n\nwhen I receive [startnewlevel v]\nResetPlayer\nbroadcast (startGame v)\n\nwhen I receive [startnewlevel v]\nbroadcast (Reset v) and wait\nbroadcast (Setup v) and wait\n\nwhen [m v] key pressed\nset [g_mouseposition v] to (join (mouse x) (join [ ,] (mouse y)))\nshow variable [g_mouseposition v]\n\nwhen I receive [bounce v]\nset [g_velocity v] to [30]\n\nif <<(TIMER) < (item (3) of [high score table v])> or <(length of [high score table v]) = [2]>> then\n    insert (join (TIMER) (join [:] (username))) at (3) of [high score table v] \n    stop [this script v]\nend\nif <<(TIMER) < (item (4) of [high score table v])> or <(length of [high score table v]) = [3]>> then\n    insert (join (TIMER) (join [:] (username))) at (4) of [high score table v] \n    stop [this script v]\nend\nif <<(TIMER) < (item (5) of [high score table v])> or <(length of [high score table v]) = [4]>> then\n    insert (join (TIMER) (join [:] (username))) at (5) of [high score table v] \n    stop [this script v]\nend\n\n@Player\n\nwhen flag clicked\ngo to [front v] layer\nforever\n    go to (main v)\nend\n\nwhen flag clicked\nforever\n    if <<key (right arrow v) pressed?> or <key (d v) pressed?>> then\n        point in direction (90)\n    end\n    if <<key (left arrow v) pressed?> or <key (a v) pressed?>> then\n        point in direction (-90)\n    end\nend\n\n@Spikes\n\nwhen flag clicked\npoint in direction (90)\ngo to [front v] layer\nhide\n\ndefine Place Clone At (x) (y)\nset [x v] to (x)\nset [y v] to (y)\nshow\ncreate clone of (_myself_ v)\n\nwhen I receive [setup v]\nset [x v] to [0]\nset [y v] to [0]\nif <(LEVEL) = [1]> then\n    Place Clone At [-5] [-115]\nend\nif <(LEVEL) = [2]> then\n    Place Clone At [130] [45]\nend\nif <(LEVEL) = [6]> then\n    Place Clone At [47] [105]\nend\nif <(LEVEL) = [8]> then\n    Place Clone At [40] [-115]\n    Place Clone At [140] [-115]\nend\nif <(LEVEL) = [9]> then\n    point in direction (-90)\n    Place Clone At [12] [-10]\n    Place Clone At [90] [-10]\nend\nhide\nset [x v] to [-99999999]\n\nwhen I receive [reset v]\ndelete this clone\n\nwhen I start as a clone\ngo to x: (x) y: (y)\n\n@Ground\n\nwhen flag clicked\ngo to x: (0) y: (0)\nforever\n    if <(LEVEL) < [12]> then\n        switch costume to (LEVEL)\n    end\nend\n\n@Green Flag\n\ndefine Place Clone At (x) (y)\nset [x v] to (x)\nset [y v] to (y)\nshow\ncreate clone of (_myself_ v)\n\nwhen I receive [setup v]\nset [x v] to [0]\nset [y v] to [0]\nif <(LEVEL) = [1]> then\n    Place Clone At [210] [-107]\nend\nif <(LEVEL) = [2]> then\n    Place Clone At [210] [55]\nend\nif <(LEVEL) = [3]> then\n    Place Clone At [210] [127]\nend\nif <(LEVEL) = [4]> then\n    Place Clone At [210] [-107]\nend\nif <(LEVEL) = [5]> then\n    Place Clone At [210] [150]\nend\nif <(LEVEL) = [6]> then\n    Place Clone At [-203] [155]\nend\nif <(LEVEL) = [7]> then\n    Place Clone At [210] [145]\nend\nif <(LEVEL) = [8]> then\n    Place Clone At [210] [145]\nend\nif <(LEVEL) = [9]> then\n    Place Clone At [60] [60]\nend\nif <(LEVEL) = [10]> then\n    Place Clone At [210] [-95]\nend\nhide\nset [x v] to [-99999999]\n\nwhen flag clicked\nhide\n\nwhen I receive [reset v]\ndelete this clone\n\nwhen I start as a clone\ngo to x: (x) y: (y)\nforever\n    next costume\n    wait (0.2) seconds\nend\n\n@Trampoline\n\nwhen flag clicked\nhide\n\nwhen I receive [reset v]\ndelete this clone\n\ndefine Place Clone At (x) (y)\nset [x v] to (x)\nset [y v] to (y)\nswitch costume to (trampoline1 v)\nshow\ncreate clone of (_myself_ v)\n\nwhen I receive [setup v]\nset [x v] to [0]\nset [y v] to [0]\nif <(LEVEL) = [5]> then\n    Place Clone At [-140] [-115]\nend\nif <(LEVEL) = [9]> then\n    Place Clone At [0] [-115]\n    Place Clone At [100] [-115]\n    Place Clone At [180] [-115]\nend\nhide\nset [x v] to [-99999]\n\nwhen I start as a clone\ngo to x: (x) y: (y)\nforever\n    if <touching (main v)?> then\n        broadcast (Bounce v)\n        repeat (8)\n            next costume\n            wait (0.05) seconds\n        end\n        switch costume to (trampoline1 v)\n    end\nend\n\n@Snow\n\nwhen flag clicked\nforever\n    set [g_wind v] to (pick random (-1) to (1))\nend\n\nwhen flag clicked\nset [ghost v] effect to (100)\ngo to x: (-240) y: (240)\nforever\n    create clone of (_myself_ v)\n    wait (pick random (0.005) to (0.01)) seconds\nend\n\nwhen I start as a clone\nset size to (pick random (60) to (90)) %\ngo to x: (pick random (-240) to (240)) y: (220)\nrepeat (4)\n    change [ghost v] effect by (-20)\nend\nrepeat (2)\n    change y by (-5)\n    change x by (G_Wind)\nend\nrepeat until <<<touching (main v)?> or <<touching (spikes v)?> or <<touching (ground v)?> or <touching (green flag v)?>>>> or <touching (_edge_ v)?>>\n    change y by (-5)\n    change x by (G_Wind)\nend\nrepeat (10)\n    if <not <touching color (#ffffff)?>> then\n        change y by (-2)\n        change x by ((G_Wind) / (2.5))\n    end\n    change [ghost v] effect by (10)\nend\ndelete this clone\n\n@CalculateHighScore\n\nwhen flag clicked\nset [timer v] to [0]\nforever\n    set [timer v] to (timer)\n    if <(LEVEL) = [11]> then\n        if <(TIMER) < (☁ Fastest Time)> then\n            set [☁ fastest time v] to (TIMER)\n        end\n        stop [this script v]\n    end\nend\n\nwhen I receive [checkhighscore v]\nset [index v] to [1]\nset [eachplayerscoreandname v] to []\nset [insertedscoretotable v] to [N]\nif <(length of [high score table v]) = [0]> then\n    insert (join (TIMER) (join [:] (username))) at (1) of [high score table v] \n    stop [this script v]\nend\nrepeat until <<(insertedScoreToTable) = [Y]> or <(index) > (length of [high score table v])>>\n    set [eachplayerscoreandname v] to (item (index) of [high score table v])\n    CheckIndividualScore (eachPlayerScoreAndName)\n    change [index v] by (1)\nend\n\ndefine CheckIndividualScore (eachscore)\nset [indexscore v] to [1]\nset [eachplayerscore v] to []\nset [readytocompare v] to [N]\nrepeat until <(indexScore) > (length of (eachscore))>\n    set [currentcharacter v] to (letter (indexScore) of (eachscore))\n    if <not <(currentCharacter) = [:]>> then\n        set [eachplayerscore v] to (join (eachPlayerScore) (currentCharacter))\n    else\n        set [readytocompare v] to [Y]\n    end\n    if <(readyToCompare) = [Y]> then\n        if <(TIMER) < (eachPlayerScore)> then\n            insert (join (TIMER) (join [:] (username))) at (index) of [high score table v] \n            set [insertedscoretotable v] to [Y]\n        end\n        stop [this script v]\n    end\n    change [indexscore v] by (1)\nend\n\nwhen I receive [gethighscoretable v]\nset [index v] to [1]\nset [eachplayerscoreandname v] to []\nset [readytoadd v] to [N]\nif <(length of (☁ CloudHighScoreList)) = [0]> then\n    stop [this script v]\nend\nset [highscorelist v] to (join (☁ CloudHighScoreList) [ ])\nrepeat until <(index) > (length of (HighScoreList))>\n    set [currentcharacter v] to (letter (index) of (HighScoreList))\n    if <not <(currentCharacter) = [ ]>> then\n        if <(eachPlayerScoreAndName) = [ ]> then\n            set [eachplayerscoreandname v] to []\n        end\n        set [eachplayerscoreandname v] to (join (eachPlayerScoreAndName) (currentCharacter))\n    else\n        set [readytoadd v] to [Y]\n    end\n    if <(readyToAdd) = [Y]> then\n        add (eachPlayerScoreAndName) to [high score table v]\n        set [eachplayerscoreandname v] to []\n        set [readytoadd v] to [N]\n    end\n    change [index v] by (1)\nend\n\nset [timer v] to [0]\nshow list [high score table v]\ndelete all of [high score table v]\nbroadcast (GetHighScoreTable v) and wait\nforever\n    set [timer v] to (timer)\n    if <(LEVEL) = [11]> then\n        broadcast (CheckHighScore v) and wait\n        hide list [high score table v]\n        if <(length of [high score table v]) > [5]> then\n            delete (6) of [high score table v]\n        end\n        hide list [high score table v]\n        set [☁ cloudhighscorelist v] to (High Score Table)\n        stop [this script v]\n    end\nend\n\n