Platformer

Instructions: Avoid the crabs and collect as many apples as you can before the time runs out.

@Stage\n\nwhen flag clicked\nforever\n    play sound [Video Game 1 v] until done\nend\n\n@Ground\n\nwhen flag clicked\ngo to x: (0) y: (0)\nset [ghost v] effect to (100)\n\n@Cat\n\nwhen flag clicked\nforever\n    if <key (left arrow v) pressed?> then\n        point in direction (-90)\n        walk [-6]\n    end\n    if <key (right arrow v) pressed?> then\n        point in direction (90)\n        walk [6]\n    end\n    if <<not <key (left arrow v) pressed?>> and <not <key (right arrow v) pressed?>>> then\n        set [frame v] to [0]\n    end\nend\n\nwhen flag clicked\nforever\n    if <(y position) < [-170]> then\n        set [y velocity v] to [0]\n        set y to (170)\n    end\nend\n\ndefine handle ground <moving up>\nswitch costume to (hitbox v)\nrepeat until <not <touching (ground v)?>>\n    if <moving up> then\n        change y by (-1)\n    else\n        change y by (1)\n        set [in air v] to [0]\n    end\n    set [y velocity v] to [0]\nend\nset correct costume\n\nwhen flag clicked\nset size to (30) %\nset rotation style [left-right v]\nset [y velocity v] to [0]\nset [frame v] to [0]\nset [frames per costume v] to [4]\nforever\n    change [y velocity v] by (-2)\n    change y by (y velocity)\n    change [in air v] by (1)\n    handle ground <(y velocity) > [0]>\nend\n\ndefine walk (steps)\nswitch costume to (hitbox v)\nchange x by (steps)\nset [ground lift v] to [0]\nrepeat until <<not <touching (ground v)?>> or <(ground lift) = [8]>>\n    change y by (1)\n    change [ground lift v] by (1)\nend\nif <(ground lift) = [8]> then\n    change x by ((-1) * (steps))\n    change y by (-8)\nend\nchange [frame v] by ((1) / (frames per costume))\nset correct costume\n\nwhen flag clicked\nforever\n    if <<key (up arrow v) pressed?> and <(in air) < [8]>> then\n        set [y velocity v] to [14]\n    end\nend\n\ndefine set correct costume\nif <(in air) < [50]> then\n    if <(frame) = [0]> then\n        switch costume to (stand v)\n    else\n        switch costume to ([floor v] of ((4) + ((frame) mod (8))) )\n    end\nelse\n    if <(y velocity) > [0]> then\n        switch costume to (jump01 v)\n    else\n        switch costume to (fall v)\n    end\nend\n\nwhen flag clicked\nforever\n    if <(x position) < [-230]> then\n        set x to (230)\n        if <(y position) < [5]> then\n            set y to (5)\n        end\n    else\n        if <(x position) > [230]> then\n            set x to (-230)\n        end\n    end\nend\n\n@Apple\n\nwhen flag clicked\nset [apples collected v] to [0]\nset size to (50) %\nforever\n    set [ghost v] effect to (100)\n    go to x: (pick random (-240) to (240)) y: (pick random (-180) to (80))\n    repeat until <not <touching (ground v)?>>\n        go to x: (pick random (-240) to (240)) y: (pick random (-180) to (80))\n    end\n    set [ghost v] effect to (0)\n    wait until <touching (cat v)?>\n    change [apples collected v] by (1)\nend\n\n@Crab\n\nwhen flag clicked\nforever\n    if <<(movement) = [left]> or <(movement) = [left jump]>> then\n        point in direction (-90)\n        walk [-4]\n    end\n    if <<(movement) = [right]> or <(movement) = [right jump]>> then\n        point in direction (90)\n        walk [4]\n    end\n    if <(movement) = [still]> then\n        set [frame v] to [0]\n    end\nend\n\nwhen flag clicked\nforever\n    if <(y position) < [-170]> then\n        set [y velocity v] to [0]\n        set y to (170)\n    end\nend\n\ndefine handle ground <moving up>\nswitch costume to (hitbox v)\nrepeat until <not <touching (ground v)?>>\n    if <moving up> then\n        change y by (-1)\n    else\n        change y by (1)\n        set [in air v] to [0]\n    end\n    set [y velocity v] to [0]\nend\nset correct costume\n\nwhen flag clicked\nset size to (30) %\nset rotation style [left-right v]\nset [y velocity v] to [0]\nset [frame v] to [0]\nset [frames per costume v] to [4]\nforever\n    change [y velocity v] by (-2)\n    change y by (y velocity)\n    change [in air v] by (1)\n    handle ground <(y velocity) > [0]>\nend\n\ndefine walk (steps)\nswitch costume to (hitbox v)\nchange x by (steps)\nset [ground lift v] to [0]\nrepeat until <<not <touching (ground v)?>> or <(ground lift) = [8]>>\n    change y by (1)\n    change [ground lift v] by (1)\nend\nif <(ground lift) = [8]> then\n    change x by ((-1) * (steps))\n    change y by (-8)\nend\nchange [frame v] by ((1) / (frames per costume))\nset correct costume\n\nwhen flag clicked\nforever\n    if <(in air) < [8]> then\n        if <<(movement) = [jump]> or <<(movement) = [left jump]> or <(movement) = [right jump]>>> then\n            set [y velocity v] to [14]\n        end\n    end\nend\n\ndefine set correct costume\nif <(frame) = [0]> then\n    switch costume to (crab-a v)\nelse\n    switch costume to ([floor v] of ((1) + ((frame) mod (2))) )\nend\n\nwhen flag clicked\nforever\n    if <(x position) < [-230]> then\n        set x to (230)\n        if <(y position) < [5]> then\n            set y to (5)\n        end\n    else\n        if <(x position) > [230]> then\n            set x to (-230)\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    set [movement v] to (pick random (1) to (6))\n    if <(movement) = [1]> then\n        set [movement v] to [left]\n    end\n    if <(movement) = [2]> then\n        set [movement v] to [right]\n    end\n    if <(movement) = [3]> then\n        set [movement v] to [jump]\n    end\n    if <(movement) = [4]> then\n        set [movement v] to [left jump]\n    end\n    if <(movement) = [5]> then\n        set [movement v] to [right jump]\n    end\n    if <(movement) = [6]> then\n        set [movement v] to [still]\n    end\n    wait (pick random (0.2) to (0.8)) seconds\nend\n\nwhen flag clicked\nforever\n    if <touching (cat v)?> then\n        if <(Apples Collected) > [0]> then\n            change [apples collected v] by (-1)\n            say [Got one!] for (2) seconds\n        else\n            say [Apples!] for (2) seconds\n        end\n    end\nend\n\n@Crab2\n\nwhen flag clicked\nforever\n    if <<(movement) = [left]> or <(movement) = [left jump]>> then\n        point in direction (-90)\n        walk [-4]\n    end\n    if <<(movement) = [right]> or <(movement) = [right jump]>> then\n        point in direction (90)\n        walk [4]\n    end\n    if <(movement) = [still]> then\n        set [frame v] to [0]\n    end\nend\n\nwhen flag clicked\nforever\n    if <(y position) < [-170]> then\n        set [y velocity v] to [0]\n        set y to (170)\n    end\nend\n\ndefine handle ground <moving up>\nswitch costume to (hitbox v)\nrepeat until <not <touching (ground v)?>>\n    if <moving up> then\n        change y by (-1)\n    else\n        change y by (1)\n        set [in air v] to [0]\n    end\n    set [y velocity v] to [0]\nend\nset correct costume\n\nwhen flag clicked\nset size to (30) %\nset rotation style [left-right v]\nset [y velocity v] to [0]\nset [frame v] to [0]\nset [frames per costume v] to [4]\nforever\n    change [y velocity v] by (-2)\n    change y by (y velocity)\n    change [in air v] by (1)\n    handle ground <(y velocity) > [0]>\nend\n\ndefine walk (steps)\nswitch costume to (hitbox v)\nchange x by (steps)\nset [ground lift v] to [0]\nrepeat until <<not <touching (ground v)?>> or <(ground lift) = [8]>>\n    change y by (1)\n    change [ground lift v] by (1)\nend\nif <(ground lift) = [8]> then\n    change x by ((-1) * (steps))\n    change y by (-8)\nend\nchange [frame v] by ((1) / (frames per costume))\nset correct costume\n\nwhen flag clicked\nforever\n    if <(in air) < [8]> then\n        if <<(movement) = [jump]> or <<(movement) = [left jump]> or <(movement) = [right jump]>>> then\n            set [y velocity v] to [14]\n        end\n    end\nend\n\ndefine set correct costume\nif <(frame) = [0]> then\n    switch costume to (crab-a v)\nelse\n    switch costume to ([floor v] of ((1) + ((frame) mod (2))) )\nend\n\nwhen flag clicked\nforever\n    if <(x position) < [-230]> then\n        set x to (230)\n        if <(y position) < [5]> then\n            set y to (5)\n        end\n    else\n        if <(x position) > [230]> then\n            set x to (-230)\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    set [movement v] to (pick random (1) to (6))\n    if <(movement) = [1]> then\n        set [movement v] to [left]\n    end\n    if <(movement) = [2]> then\n        set [movement v] to [right]\n    end\n    if <(movement) = [3]> then\n        set [movement v] to [jump]\n    end\n    if <(movement) = [4]> then\n        set [movement v] to [left jump]\n    end\n    if <(movement) = [5]> then\n        set [movement v] to [right jump]\n    end\n    if <(movement) = [6]> then\n        set [movement v] to [still]\n    end\n    wait (pick random (0.2) to (0.8)) seconds\nend\n\nwhen flag clicked\nforever\n    if <touching (cat v)?> then\n        if <(Apples Collected) > [0]> then\n            change [apples collected v] by (-1)\n            say [Got one!] for (2) seconds\n        else\n            say [Apples!] for (2) seconds\n        end\n    end\nend\n\n@TIME'S UP\n\nwhen flag clicked\nhide\nset [timer v] to [45]\nrepeat until <(Timer) = [0]>\n    wait (1) seconds\n    change [timer v] by (-1)\nend\nshow\nstop [all v]\n\n