Quest to Infinity | A Platformer
@Stage\n\n@Blocks\n\nwhen flag clicked\nhide\nerase all\ndelete (all) of [leveldata v]\nshow list [export code v]\ndelete (all) of [export code v]\nset [showingexportcode v] to [0]\nset [numberofblocks v] to [22]\nset [currentblock v] to [1]\nset [currentlevel v] to [1]\nshow variable [currentlevel v]\nswitch costume to (currentBlock)\nswitch backdrop to (playmode v)\nerase all\nGenerate: LevelData from (item (currentLevel) of [levels v])\n\ndefine Generate: LevelData from []\nset [import: index v] to [0]\ngo to x: (-240) y: (-190)\nrepeat (19)\n    set x to (-240)\n    repeat (25)\n        change [import: index v] by (1)\n        set [import: currentcharacter v] to (letter (import: index) of (string))\n        add (import: currentCharacter) to [leveldata v]\n        if <not <(import: currentCharacter) = [0]>> then\n            switch costume to (import: currentCharacter)\n            stamp\n        end\n        switch costume to (1 v)\n        change x by (20)\n    end\n    change y by (20)\nend\nswitch costume to (currentBlock)\n\ndefine None\nstamp\nset [leveldataindex v] to (((((x) + (240)) * (0.05)) + (1)) + ((((y) + (180)) * (0.05)) * (25)))\nreplace item (levelDataIndex) of [leveldata v] with (type)\nif <(smartMode) = [1]> then\n    Find: SmartMode | type: (type)\n    if <not <(currentSmartMode) = []>> then\n        if <<(item ((levelDataIndex) + (25)) of [leveldata v]) = (letter (1) of (currentSmartMode))> or <(item ((levelDataIndex) + (25)) of [leveldata v]) = (letter (2) of (currentSmartMode))>> then\n            replace item (levelDataIndex) of [leveldata v] with (letter (2) of (currentSmartMode))\n            switch costume to (letter (2) of (currentSmartMode))\n            stamp\n            switch costume to (type)\n        end\n        if <(item ((levelDataIndex) - (25)) of [leveldata v]) = (letter (1) of (currentSmartMode))> then\n            replace item ((levelDataIndex) - (25)) of [leveldata v] with (letter (2) of (currentSmartMode))\n            switch costume to (letter (2) of (currentSmartMode))\n            change y by (-20)\n            stamp\n            switch costume to (type)\n        end\n    end\nend\n\ndefine Find: SmartMode | type: []\nset [smartmode_upperindex v] to [0]\nset [currentsmartmode v] to []\nrepeat (length of [smartmode_upper v])\n    change [smartmode_upperindex v] by (1)\n    if <(type) = (letter (1) of (item (SmartMode_UpperIndex) of [smartmode_upper v]))> then\n        set [currentsmartmode v] to (item (SmartMode_UpperIndex) of [smartmode_upper v])\n    end\nend\n\ndefine Import: LevelData []\ndelete (all) of [leveldata v]\nerase all\nGenerate: LevelData from (string)\n\nwhen flag clicked\nforever\n    play sound (pick random (1) to (5)) until done\nend\n\nforever\n    wait until <key (a v) pressed?>\n    ask [LD: ] and wait\n    if <not <(answer) = []>> then\n        insert (answer) at (length of [levels v]) of [levels v] \n    end\nend\n\nwhen I receive [level v]\nerase all\nGenerate: LevelData from (item (currentLevel) of [levels v])\n\nwhen [timer v] > (2)\nforever\n    play sound (pick random (1) to (5)) until done\nend\n\nask [LD: ] and wait\nif <not <(answer) = []>> then\n    insert (answer) at (length of [levels v]) of [levels v] \nend\n\n@Player\n\ndefine GroundCheck\nCheck: TouchingGround\nif <(p: touchingGround) = [0]> then\n    set [p: falling v] to [1]\nelse\n    set [p: anti-error: counter v] to [0]\n    repeat until <<(p: touchingGround) = [0]> or <(p: Anti-Error: counter) > [400]>>\n        if <(p: yV) > [0]> then\n            change y by ((p: yV) * (-1))\n        else\n            change y by (1)\n            set [p: falling v] to [0]\n        end\n        Check: TouchingGround\n        change [p: anti-error: counter v] by (1)\n    end\n    set [p: yv v] to [0]\nend\n\ndefine Physics\nCheck: Touching Lava\nCheck: Touching Ladder\nif <<(p: touchingLadder) = [1]> and <not <(p: touchingGround) = [1]>>> then\n    if <key (up arrow v) pressed?> then\n        set [p: yv v] to [2]\n    else\n        if <key (down arrow v) pressed?> then\n            set [p: yv v] to [-2]\n        else\n            set [p: yv v] to [0]\n        end\n    end\nelse\n    change [p: yv v] by (p: gravity)\nend\nset [p: anti-error: counter v] to [0]\nAdvancedGroundCheck\nif <(p: Anti-Error: counter) > [400]> then\n    set [error_code v] to [Error In GroundCheck:                                            Player was stuck in Blocks of type Ground                                                                 Probable cause: Player got stuck inside wall     ======================================= Recommendation: Pretend nothing ever happend and press J]\n    create clone of (_myself_ v)\n    Reset: Player\n    broadcast (ERROR v) and wait\nend\nif <<(p: falling) = [0]> or <(p: touchingLadder) = [1]>> then\n    if <key (up arrow v) pressed?> then\n        set [p: yv v] to (p: jumpStrength)\n    end\nend\nset [p: ismoving v] to [0]\nif <key (left arrow v) pressed?> then\n    if <(p: xV) > [0]> then\n        change [p: xv v] by (((p: xV) * (-0.25)) + (((p: speed) - (0.05)) * (-1)))\n    else\n        change [p: xv v] by ((p: speed) * (-1))\n    end\n    set [p: ismoving v] to [1]\nend\nif <key (right arrow v) pressed?> then\n    if <(p: xV) < [0]> then\n        change [p: xv v] by (((p: xV) * (-0.25)) + ((p: speed) - (0.05)))\n    else\n        change [p: xv v] by (p: speed)\n    end\n    set [p: ismoving v] to [1]\nend\nif <(p: isMoving) = [1]> then\n    set [p: xv v] to ((p: xV) * (0.9))\nelse\n    set [p: xv v] to ((p: xV) * (0.8))\nend\nif <(p: touchingLadder) = [1]> then\n    set [p: xv v] to ((p: xV) * (0.75))\nend\nif <([abs v] of (p: xV) ) > [0]> then\n    Move (p: xV)\nend\nCheck: Touching Lava\nif <(p: touchingLava) = [1]> then\n    if <(p: invincible) = [0]> then\n        create clone of (_myself_ v)\n        Reset: Player\n    else\n        set [p: yv v] to [7]\n    end\nend\nCheck: Touching Spikes\nif <<(p: touchingSpikes) = [1]> and <(p: invincible) = [0]>> then\n    create clone of (_myself_ v)\n    Reset: Player\nend\nCheck: Touching JumpPad\nif <(p: touchingJumpPad) = [1]> then\n    set [p: yv v] to [17]\nend\nif <(y position) < [-175]> then\n    create clone of (_myself_ v)\n    Reset: Player\nend\nCheck: Touching Flag\nif <(p: touchingFlag) = [1]> then\n    Reset: Player\n    change [currentlevel v] by (1)\n    set [p: deaths on level v] to [0]\n    if <(p: randomLevel) = [1]> then\n        set [currentlevel v] to (pick random (1) to ((length of [levels v]) - (1)))\n    end\n    broadcast (DEATH v)\n    broadcast (Level v) and wait\n    if <(currentLevel) = (length of [levels v])> then\n        broadcast (Level v) and wait\n        broadcast (END v)\n        repeat (10)\n            change [ghost v] effect by (10)\n        end\n        stop [other scripts in sprite v]\n        stop [this script v]\n    end\nend\nif <touching color (#1966a2)?> then\n    wait until <not <touching color (#1966a2)?>>\nend\n\ndefine Check: Touching Ladder\nif <<touching color (#b77847)?> or > then\n    set [p: touchingladder v] to [1]\nelse\n    set [p: touchingladder v] to [0]\nend\n\ndefine Check: Touching Lava\nif <<touching color (#ff1212)?> or > then\n    set [p: touchinglava v] to [1]\nelse\n    set [p: touchinglava v] to [0]\nend\n\nwhen flag clicked\nset [p: gravity v] to [-1]\nset [error_code v] to []\nset [p: jumpstrength v] to [10.75]\nset [p: deaths on level v] to [0]\nset [p: speed v] to [0.7]\nhide variable [error_code v]\nReset: Player\ngo to x: (-200) y: (-80)\nrepeat (10)\n    Physics\nend\n\nwhen flag clicked\nforever\n    reset timer\nend\n\ndefine Check: TouchingGround\nif <<touching color (#62c34c)?> or <<touching color (#8d4914)?> or <<touching color (#70695d)?> or <<touching color (#706a60)?> or <<touching color (#5e574e)?> or >>>>> then\n    set [p: touchingground v] to [1]\nelse\n    set [p: touchingground v] to [0]\nend\n\nwhen I start as a clone\nset [deathanimation: yvel v] to [5]\nrepeat (20)\n    change y by (deathAnimation: yVel)\n    change [deathanimation: yvel v] by (-1)\n    change [ghost v] effect by (5)\nend\ndelete this clone\n\ndefine Check: Touching JumpPad\nif <<touching color (#82cc7d)?> or > then\n    set [p: touchingjumppad v] to [1]\nelse\n    set [p: touchingjumppad v] to [0]\nend\n\ndefine None\nchange x by (vel)\nCheck: TouchingGround\nif <(p: touchingGround) = [1]> then\n    change x by ((p: xV) * (-0.5))\n    if <<([abs v] of (p: xV) ) > [1]> and <<key (up arrow v) pressed?> and <<key (right arrow v) pressed?> or <key (left arrow v) pressed?>>>> then\n        change x by ((p: xV) * (-0.5))\n        if <(p: xV) > [0]> then\n            set [p: xv v] to [-2]\n            change x by (p: xV)\n        else\n            set [p: xv v] to [2]\n            change x by (p: xV)\n        end\n        set [p: yv v] to [8]\n    else\n        change x by ((p: xV) * (-0.5))\n        set [p: xv v] to ((p: xV) * (-0.5))\n    end\nend\n\ndefine Check: Touching Flag\nif <<touching color (#ff4949)?> or <<touching color (#c62d2d)?> or >> then\n    set [p: touchingflag v] to [1]\nelse\n    set [p: touchingflag v] to [0]\nend\n\ndefine AdvancedGroundCheck\nif <([abs v] of (p: yV) ) < [16]> then\n    change y by (p: yV)\n    GroundCheck\nelse\n    set [p: groundcheck: repeat v] to ([abs v] of ([ceiling v] of ((p: yV) / (15)) ) )\n    set [p: groundcheck: counter v] to [0]\n    repeat ((p: groundCheck: repeat) + (1))\n        change [p: groundcheck: counter v] by (1)\n        if <(p: groundCheck: counter) = (p: groundCheck: repeat)> then\n            set [p: groundcheck: ychange v] to (([abs v] of (p: yV) ) mod (15))\n        else\n            set [p: groundcheck: ychange v] to [15]\n            if <(p: yV) > [0]> then\n                change y by (p: groundCheck: yChange)\n            else\n                change y by ((p: groundCheck: yChange) * (-1))\n            end\n            GroundCheck\n        end\n    end\nend\n\ndefine Reset: Player\nset [p: yv v] to [0]\nset [p: xv v] to [0]\nset [p: falling v] to [0]\nset [p: touchingground v] to [0]\ngo to x: (-200) y: (-80)\nchange [p: deaths on level v] by (1)\nbroadcast (DEATH v)\n\ndefine Check: Touching Spikes\nif <<touching color (#8a8a8a)?> or > then\n    set [p: touchingspikes v] to [1]\nelse\n    set [p: touchingspikes v] to [0]\nend\n\nwhen I receive [start v]\nforever\n    Physics\nend\n\nwhen I receive [skip v]\nReset: Player\nchange [currentlevel v] by (1)\nset [p: deaths on level v] to [0]\nbroadcast (DEATH v)\nbroadcast (Level v) and wait\nif <(currentLevel) = (length of [levels v])> then\n    broadcast (Level v) and wait\n    broadcast (END v)\n    repeat (10)\n        change [ghost v] effect by (10)\n    end\n    stop [other scripts in sprite v]\n    stop [this script v]\nelse\nend\n\n@Thumbnail\n\nset size to (100) %\n\nwhen flag clicked\ngo to [front v] layer\ngo to x: (0) y: (0)\nhide\n\nshow\n\n@Error\n\nwhen I receive [error v]\ndelete (all) of [error_message v]\nadd (ERROR_CODE) to [error_message v]\nadd [] to [error_message v]\nadd [Press J to continue] to [error_message v]\nhide list [error_message v]\nwait until <key (j v) pressed?>\nshow list [error_message v]\nbroadcast (Level v)\n\nwhen flag clicked\nshow list [error_message v]\n\n@End\n\nwhen flag clicked\ngo to x: (0) y: (0)\nset [brightness v] effect to (-5)\nhide\n\nset [brightness v] effect to (0)\n\nwhen I receive [end v]\nset [ghost v] effect to (100)\nshow\nrepeat (20)\n    change [ghost v] effect by (-5)\nend\n\n@Storyline\n\nwhen flag clicked\ngo to x: (0) y: (0)\nhide\nswitch costume to (kostüm2 v)\nshow\nFade In\nwait (1) seconds\nNext\nwait (4) seconds\nNext\nwait (5) seconds\nbroadcast (Start v)\nNext\nwait (6) seconds\nFade Out\nhide\nwait until <(currentLevel) = [6]>\nnext costume\nshow\nFade In\nwait (5) seconds\nFade Out\nhide\nwait until <(currentLevel) = [7]>\nnext costume\nshow\nFade In\nwait (6) seconds\nFade Out\nhide\nwait until <(currentLevel) = [34]>\nnext costume\nshow\nFade In\nwait (6) seconds\nFade Out\nhide\n\ndefine Next\ncreate clone of (_myself_ v)\nFade Out\nnext costume\nset [ghost v] effect to (0)\n\ndefine Fade In\nset [ghost v] effect to (100)\nrepeat (20)\n    change [ghost v] effect by (-5)\nend\n\ndefine Fade Out\nset [ghost v] effect to (0)\nrepeat (20)\n    change [ghost v] effect by (5)\nend\n\nwhen I start as a clone\nnext costume\ngo [backward v] (1) layers\nFade In\nwait (1) seconds\ndelete this clone\n\n@Skip\n\nwhen flag clicked\nset [skip: state v] to [0]\nhide\ngo to x: (202) y: (164)\nforever\n    if <<(skip: state) = [1]> and <not <(currentLevel) = (length of [levels v])>>> then\n        set [ghost v] effect to ((150) - (distance to [player v]))\n    else\n    end\nend\n\ndefine Fade In\nset [ghost v] effect to (100)\nshow\nrepeat (10)\n    change [ghost v] effect by (-10)\nend\n\nwhen I receive [death v]\nif <(p: deaths on level) > [9]> then\n    if <not <(skip: state) = [1]>> then\n        Fade In\n        set [skip: state v] to [1]\n    end\nelse\n    if <not <(skip: state) = [0]>> then\n        set [skip: state v] to [0]\n        Fade Out\n    end\nend\n\nwhen this sprite clicked\nbroadcast (SKIP v)\nFade Out\n\ndefine Fade Out\nset [ghost v] effect to (0)\nrepeat (10)\n    change [ghost v] effect by (10)\nend\nhide\n\n@Modifiers\n\ndefine Fade Out\nset [ghost v] effect to (0)\nrepeat (10)\n    change [ghost v] effect by (10)\nend\n\ndefine Fade In\nset [ghost v] effect to (100)\nshow\nrepeat (10)\n    change [ghost v] effect by (-10)\nend\n\nwhen this sprite clicked\nif <(costume [number v]) = [1]> then\n    show variable [p: speed v]\n    show variable [p: gravity v]\n    show variable [p: jumpstrength v]\n    show variable [p: randomlevel v]\n    show variable [p: invincible v]\nelse\n    hide variable [p: jumpstrength v]\n    hide variable [p: gravity v]\n    hide variable [p: speed v]\n    hide variable [p: randomlevel v]\n    hide variable [p: invincible v]\nend\nhide\nnext costume\nif <(costume [number v]) = [2]> then\n    go to x: (0) y: (-15)\nelse\n    go to x: (179) y: (-173)\nend\nnext costume\nFade Out\nnext costume\nFade In\n\nwhen flag clicked\nshow\nswitch costume to (button v)\ngo to x: (179) y: (-173)\nset [p: randomlevel v] to [0]\nset [p: invincible v] to [0]\nhide variable [p: jumpstrength v]\nhide variable [p: gravity v]\nhide variable [p: speed v]\nhide variable [p: randomlevel v]\nhide variable [p: invincible v]\n\nwhen flag clicked\nforever\n    wait (0.1) seconds\n    if <not <(costume [number v]) = [2]>> then\n        set [ghost v] effect to ((150) - (distance to [player v]))\n    else\n        set [ghost v] effect to (0)\n    end\nend\n\n@Rainbow\n\nwhen flag clicked\ngo to x: (155) y: (-170)\nforever\n    set [ghost v] effect to ((150) - (distance to [player v]))\nend\n\n