var PAUSING = 1, PLAYING = 2, GAME_OVER = 3;
var plat1X = 100, plat1Y = 0, plat2X = 200, plat2Y = 250;
var platSpeed = 1, platWidth = 100, platHeight = 10;
var playerX = 220, playerY = 150, playerWidth = 50, playerHeight = 80;
var jumpValue = 0, changeInJump = 0.125;
var isPlayerStanding = false;
if( gameMode == PLAYING ) {
if( isKeyPressed && key == "p" ) {
else if( gameMode == PAUSING ) {
if( isKeyPressed && key == "r" ) {
else if( gameMode == GAME_OVER ) {
if( isKeyPressed && key == "r" ) {
function updatePlayer() {
if( isKeyPressed && key == 'a' ) {
if( isKeyPressed && key == 'd' ) {
if( isPlayerStanding && abs(playerY + playerHeight - plat1Y) < 5 && ( playerX + playerWidth < plat1X || playerX > plat1X + platWidth )
if( isPlayerStanding && abs(playerY + playerHeight - plat2Y) < 5 && ( playerX + playerWidth < plat2X || playerX > plat2X + platWidth )
if( isPlayerStanding && (overPlat1 == false || overPlat2 == false) ) {
isPlayerStanding = false;
if( isPlayerStanding == true ) {
if( isKeyPressed && key == " " ) {
isPlayerStanding = false;
print("falling or jumping");
if( playerX + playerWidth > plat1X && playerX < plat1X + platWidth &&
playerY + playerHeight < plat1Y && playerY + playerHeight - jumpValue > plat1Y) {
playerY = plat1Y - playerHeight;
print("collided with platform 1");
if(playerX + playerWidth > plat2X && playerX < plat2X + platWidth &&
playerY + playerHeight < plat2Y && playerY + playerHeight - jumpValue > plat2Y) {
playerY = plat2Y - playerHeight;
print("collided with platform 2");
jumpValue -= changeInJump;
rect( playerX, playerY, playerWidth, playerHeight );
text("Score: " + score , 0, 40);
function updatePlatforms() {
plat1X = random( 0, width - platWidth );
plat2X = random( 0, width - platWidth );
function drawPlatforms() {
rect( plat1X, plat1Y, platWidth, platHeight );
rect( plat2X, plat2Y, platWidth, platHeight );
textAlign(CENTER, CENTER);
text("End of the game", width/2, height/2 );
text("Type r to restart", width/2, height/2 + 50);