/**** * Classes ****/ // MessageDisplay class var MessageDisplay = Container.expand(function (text) { var self = Container.call(this); var messageText = new Text2(text, { size: 150, fill: "#ffffff", align: 'center' }); self.addChild(messageText); messageText.anchor.set(0.5, 0.5); self.x = 2048 / 2; self.y = 2732 / 2; self.show = function () { self.visible = true; LK.setTimeout(function () { self.visible = false; LK.showGameOver(); // This will reset the game state }, 2000); }; }); // NumberedObject class var NumberedObject = Container.expand(function (number) { var self = Container.call(this); var objectGraphics = self.createAsset('object' + number, 'Numbered object ' + number, 0.5, 0.5); }); // EndGameItem class var EndGameItem = Container.expand(function () { var self = Container.call(this); var endGraphics = self.createAsset('end', 'End game object', 0.5, 1); self.visible = false; }); // Skull class var Skull = Container.expand(function () { var self = Container.call(this); var skullGraphics = self.createAsset('skull', 'Skull effect', 0.5, 0.5); skullGraphics.alpha = 1; self.animate = function () { LK.setTimeout(function () { self.destroy(); }, 500); }; }); // HealthMeter class var HealthMeter = Container.expand(function () { var self = Container.call(this); var meterGraphics = self.createAsset('healthMeter', 'Health meter display', 0, 0); self.decreaseHealth = function () { meterGraphics.width -= meterGraphics.width / 3; if (meterGraphics.width <= 0) { meterGraphics.width = 0; // Trigger game over or any other necessary action } }; }); // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.createAsset('explosion', 'Explosion effect', 0.5, 0.5); explosionGraphics.alpha = 1; self.animate = function () { LK.setTimeout(function () { self.destroy(); }, 500); }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1); self.speed = 15; self.targetX = self.x; self.moveLeft = function () { if (self.x > self.targetX && self.x > playerGraphics.width / 2) { self.x -= self.speed; } }; self.moveRight = function () { if (self.x < self.targetX && self.x < 2048 - playerGraphics.width / 2) { self.x += self.speed; } }; }); // Player2 class var Player2 = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player2', 'Alternate player character', 0.5, 1); self.speed = 15; self.targetX = self.x; self.visible = false; self.moveLeft = function () { if (self.x > self.targetX && self.x > playerGraphics.width / 2) { self.x -= self.speed; } }; self.moveRight = function () { if (self.x < self.targetX && self.x < 2048 - playerGraphics.width / 2) { self.x += self.speed; } }; }); // Apple class var Apple = Container.expand(function () { var self = Container.call(this); var appleGraphics = self.createAsset('apple', 'Falling apple', 0.5, 0.5); self.speed = 9; self.move = function () { self.y += self.speed; }; self.isCaught = function (player) { var playerHeadY = player.y - player.height / 2; var appleBottomY = self.y + self.height / 2; if (self.intersects(player) && appleBottomY < playerHeadY) { var explosion = new Explosion(); explosion.x = self.x; explosion.y = self.y; game.addChild(explosion); explosion.animate(); numberedObjects[0].visible = true; return true; } return false; }; }); // GreenApple class var GreenApple = Container.expand(function () { var self = Container.call(this); var appleGraphics = self.createAsset('greenApple', 'Falling green apple', 0.5, 0.5); self.speed = 15; self.move = function () { self.y += self.speed; }; self.isCaught = function (player) { var playerHeadY = player.y - player.height / 2; var appleBottomY = self.y + self.height / 2; if (self.intersects(player) && appleBottomY < playerHeadY) { var skull = new Skull(); skull.x = self.x; skull.y = self.y; game.addChild(skull); skull.animate(); return true; } return false; }; }); // FormulaDisplay class var FormulaDisplay = Container.expand(function () { var self = Container.call(this); var formulaText = new Text2('F=G(Mm)/R^2', { size: 100, fill: "#000000", align: 'center' }); self.addChild(formulaText); formulaText.anchor.set(0.5, 0.5); self.x = 2048 - formulaText.width / 2 - 30; self.y = formulaText.height / 2 + 30; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize second background var background2 = game.addChild(LK.getAsset('background2', 'Second background', 0, 0)); background2.width = 2048; background2.height = 2732; background2.x = 0; background2.y = 0; background2.anchor.set(0, 0); // Initialize backgrounds var background = game.addChild(LK.getAsset('background', 'Game background', 0, 0)); background.width = 2048; background.height = 2732; background.x = 0; background.y = 0; background.anchor.set(0, 0); // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 50; // Positioned at the bottom of the screen // Initialize player2 var player2 = game.addChild(new Player2()); player2.x = 2048 / 2; player2.y = 2732 - 50; // Positioned at the bottom of the screen, same as player // Initialize apples array var apples = []; // Initialize and arrange numbered objects at the top of the screen in a single row var numberedObjects = []; for (var i = 0; i < 10; i++) { var numberedObject = game.addChild(new NumberedObject(i + 1)); var objectSpacing = 2048 / 10; var objectWidth = numberedObject.width; numberedObject.x = objectSpacing * i + objectSpacing / 2 - objectWidth / 2 + 200; numberedObject.y = 2732 - numberedObject.height / 2; numberedObject.visible = false; numberedObjects.push(numberedObject); } // Initialize health meters var healthMeters = []; for (var i = 0; i < 3; i++) { var healthMeter = game.addChild(new HealthMeter()); healthMeter.x = i * 70 + 330; // Assuming each health meter is 64 pixels wide plus some padding healthMeter.y = 40; healthMeters.push(healthMeter); } // Initialize and add the FormulaDisplay to the game var formulaDisplay = game.addChild(new FormulaDisplay()); // Handle touch movement function handleTouchMove(obj) { var touchPos = obj.event.getLocalPosition(game); player.targetX = touchPos.x; player2.targetX = touchPos.x; } // Attach touch move event to the game game.on('move', handleTouchMove); // Game tick event LK.on('tick', function () { // Move player towards targetX and control visibility of player and player2 // Only move if the targetX is not directly on the player if (Math.abs(player.x - player.targetX) > player.width / 2) { if (player.x < player.targetX) { player.moveRight(); player2.moveRight(); player.visible = false; player2.visible = true; } else if (player.x > player.targetX) { player.moveLeft(); player2.moveLeft(); player.visible = true; player2.visible = false; } } // Move apples for (var i = apples.length - 1; i >= 0; i--) { apples[i].move(); // Check if apple is caught by the player or player2 depending on their visibility if (player.visible && apples[i] instanceof Apple && apples[i].isCaught(player) || player2.visible && apples[i] instanceof Apple && apples[i].isCaught(player2)) { // Increase score LK.setScore(LK.getScore() + 1); // Show object2 on the second catch of a red apple if (LK.getScore() === 2) { numberedObjects[1].visible = true; } // Show object3 on the third catch of a red apple if (LK.getScore() === 3) { numberedObjects[2].visible = true; } // Show object4 on the fourth catch of a red apple if (LK.getScore() === 4) { numberedObjects[3].visible = true; } // Show object5 on the fifth catch of a red apple if (LK.getScore() === 5) { numberedObjects[4].visible = true; } // Show object6 on the sixth catch of a red apple if (LK.getScore() === 6) { numberedObjects[5].visible = true; } // Show object7 on the seventh catch of a red apple if (LK.getScore() === 7) { numberedObjects[6].visible = true; } // Show object8 on the eighth catch of a red apple if (LK.getScore() === 8) { numberedObjects[7].visible = true; } // Show object9 on the ninth catch of a red apple and display a message if (LK.getScore() === 9) { numberedObjects[8].visible = true; var message = new MessageDisplay('Congratulations!'); game.addChild(message); message.show(); } // Remove caught apple apples[i].destroy(); apples.splice(i, 1); } else if (player.visible && apples[i] instanceof GreenApple && apples[i].isCaught(player) || player2.visible && apples[i] instanceof GreenApple && apples[i].isCaught(player2)) { // Decrease health and check for game over if (healthMeters.length > 0) { var lastHealthMeter = healthMeters.pop(); lastHealthMeter.destroy(); if (healthMeters.length === 0) { // Trigger game over with golden effect LK.effects.flashScreen(0xFFFF00, 1000); var endGameItem = game.addChild(new EndGameItem()); endGameItem.x = player.x; endGameItem.y = player.y; endGameItem.visible = true; player.visible = false; player2.visible = false; LK.showGameOver(); } } // Remove caught green apple apples[i].destroy(); apples.splice(i, 1); } else if (apples[i].y > 2732) { // Remove apple if it falls off the screen apples[i].destroy(); apples.splice(i, 1); } } // Spawn apples less frequently if (LK.ticks % 90 == 0) { // Every two seconds var appleType = Math.random() < 0.25 ? new Apple() : new GreenApple(); // 25% chance for red apple, 75% for green apple var newApple = appleType; newApple.x = Math.random() * 2048; newApple.y = 2732 / 2; // Start at the middle of the screen in height apples.push(newApple); game.addChild(newApple); } });
/****
* Classes
****/
// MessageDisplay class
var MessageDisplay = Container.expand(function (text) {
var self = Container.call(this);
var messageText = new Text2(text, {
size: 150,
fill: "#ffffff",
align: 'center'
});
self.addChild(messageText);
messageText.anchor.set(0.5, 0.5);
self.x = 2048 / 2;
self.y = 2732 / 2;
self.show = function () {
self.visible = true;
LK.setTimeout(function () {
self.visible = false;
LK.showGameOver(); // This will reset the game state
}, 2000);
};
});
// NumberedObject class
var NumberedObject = Container.expand(function (number) {
var self = Container.call(this);
var objectGraphics = self.createAsset('object' + number, 'Numbered object ' + number, 0.5, 0.5);
});
// EndGameItem class
var EndGameItem = Container.expand(function () {
var self = Container.call(this);
var endGraphics = self.createAsset('end', 'End game object', 0.5, 1);
self.visible = false;
});
// Skull class
var Skull = Container.expand(function () {
var self = Container.call(this);
var skullGraphics = self.createAsset('skull', 'Skull effect', 0.5, 0.5);
skullGraphics.alpha = 1;
self.animate = function () {
LK.setTimeout(function () {
self.destroy();
}, 500);
};
});
// HealthMeter class
var HealthMeter = Container.expand(function () {
var self = Container.call(this);
var meterGraphics = self.createAsset('healthMeter', 'Health meter display', 0, 0);
self.decreaseHealth = function () {
meterGraphics.width -= meterGraphics.width / 3;
if (meterGraphics.width <= 0) {
meterGraphics.width = 0;
// Trigger game over or any other necessary action
}
};
});
// Explosion class
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.createAsset('explosion', 'Explosion effect', 0.5, 0.5);
explosionGraphics.alpha = 1;
self.animate = function () {
LK.setTimeout(function () {
self.destroy();
}, 500);
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1);
self.speed = 15;
self.targetX = self.x;
self.moveLeft = function () {
if (self.x > self.targetX && self.x > playerGraphics.width / 2) {
self.x -= self.speed;
}
};
self.moveRight = function () {
if (self.x < self.targetX && self.x < 2048 - playerGraphics.width / 2) {
self.x += self.speed;
}
};
});
// Player2 class
var Player2 = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player2', 'Alternate player character', 0.5, 1);
self.speed = 15;
self.targetX = self.x;
self.visible = false;
self.moveLeft = function () {
if (self.x > self.targetX && self.x > playerGraphics.width / 2) {
self.x -= self.speed;
}
};
self.moveRight = function () {
if (self.x < self.targetX && self.x < 2048 - playerGraphics.width / 2) {
self.x += self.speed;
}
};
});
// Apple class
var Apple = Container.expand(function () {
var self = Container.call(this);
var appleGraphics = self.createAsset('apple', 'Falling apple', 0.5, 0.5);
self.speed = 9;
self.move = function () {
self.y += self.speed;
};
self.isCaught = function (player) {
var playerHeadY = player.y - player.height / 2;
var appleBottomY = self.y + self.height / 2;
if (self.intersects(player) && appleBottomY < playerHeadY) {
var explosion = new Explosion();
explosion.x = self.x;
explosion.y = self.y;
game.addChild(explosion);
explosion.animate();
numberedObjects[0].visible = true;
return true;
}
return false;
};
});
// GreenApple class
var GreenApple = Container.expand(function () {
var self = Container.call(this);
var appleGraphics = self.createAsset('greenApple', 'Falling green apple', 0.5, 0.5);
self.speed = 15;
self.move = function () {
self.y += self.speed;
};
self.isCaught = function (player) {
var playerHeadY = player.y - player.height / 2;
var appleBottomY = self.y + self.height / 2;
if (self.intersects(player) && appleBottomY < playerHeadY) {
var skull = new Skull();
skull.x = self.x;
skull.y = self.y;
game.addChild(skull);
skull.animate();
return true;
}
return false;
};
});
// FormulaDisplay class
var FormulaDisplay = Container.expand(function () {
var self = Container.call(this);
var formulaText = new Text2('F=G(Mm)/R^2', {
size: 100,
fill: "#000000",
align: 'center'
});
self.addChild(formulaText);
formulaText.anchor.set(0.5, 0.5);
self.x = 2048 - formulaText.width / 2 - 30;
self.y = formulaText.height / 2 + 30;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize second background
var background2 = game.addChild(LK.getAsset('background2', 'Second background', 0, 0));
background2.width = 2048;
background2.height = 2732;
background2.x = 0;
background2.y = 0;
background2.anchor.set(0, 0);
// Initialize backgrounds
var background = game.addChild(LK.getAsset('background', 'Game background', 0, 0));
background.width = 2048;
background.height = 2732;
background.x = 0;
background.y = 0;
background.anchor.set(0, 0);
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 50; // Positioned at the bottom of the screen
// Initialize player2
var player2 = game.addChild(new Player2());
player2.x = 2048 / 2;
player2.y = 2732 - 50; // Positioned at the bottom of the screen, same as player
// Initialize apples array
var apples = [];
// Initialize and arrange numbered objects at the top of the screen in a single row
var numberedObjects = [];
for (var i = 0; i < 10; i++) {
var numberedObject = game.addChild(new NumberedObject(i + 1));
var objectSpacing = 2048 / 10;
var objectWidth = numberedObject.width;
numberedObject.x = objectSpacing * i + objectSpacing / 2 - objectWidth / 2 + 200;
numberedObject.y = 2732 - numberedObject.height / 2;
numberedObject.visible = false;
numberedObjects.push(numberedObject);
}
// Initialize health meters
var healthMeters = [];
for (var i = 0; i < 3; i++) {
var healthMeter = game.addChild(new HealthMeter());
healthMeter.x = i * 70 + 330; // Assuming each health meter is 64 pixels wide plus some padding
healthMeter.y = 40;
healthMeters.push(healthMeter);
} // Initialize and add the FormulaDisplay to the game
var formulaDisplay = game.addChild(new FormulaDisplay());
// Handle touch movement
function handleTouchMove(obj) {
var touchPos = obj.event.getLocalPosition(game);
player.targetX = touchPos.x;
player2.targetX = touchPos.x;
}
// Attach touch move event to the game
game.on('move', handleTouchMove);
// Game tick event
LK.on('tick', function () {
// Move player towards targetX and control visibility of player and player2
// Only move if the targetX is not directly on the player
if (Math.abs(player.x - player.targetX) > player.width / 2) {
if (player.x < player.targetX) {
player.moveRight();
player2.moveRight();
player.visible = false;
player2.visible = true;
} else if (player.x > player.targetX) {
player.moveLeft();
player2.moveLeft();
player.visible = true;
player2.visible = false;
}
}
// Move apples
for (var i = apples.length - 1; i >= 0; i--) {
apples[i].move();
// Check if apple is caught by the player or player2 depending on their visibility
if (player.visible && apples[i] instanceof Apple && apples[i].isCaught(player) || player2.visible && apples[i] instanceof Apple && apples[i].isCaught(player2)) {
// Increase score
LK.setScore(LK.getScore() + 1);
// Show object2 on the second catch of a red apple
if (LK.getScore() === 2) {
numberedObjects[1].visible = true;
}
// Show object3 on the third catch of a red apple
if (LK.getScore() === 3) {
numberedObjects[2].visible = true;
}
// Show object4 on the fourth catch of a red apple
if (LK.getScore() === 4) {
numberedObjects[3].visible = true;
}
// Show object5 on the fifth catch of a red apple
if (LK.getScore() === 5) {
numberedObjects[4].visible = true;
}
// Show object6 on the sixth catch of a red apple
if (LK.getScore() === 6) {
numberedObjects[5].visible = true;
}
// Show object7 on the seventh catch of a red apple
if (LK.getScore() === 7) {
numberedObjects[6].visible = true;
}
// Show object8 on the eighth catch of a red apple
if (LK.getScore() === 8) {
numberedObjects[7].visible = true;
}
// Show object9 on the ninth catch of a red apple and display a message
if (LK.getScore() === 9) {
numberedObjects[8].visible = true;
var message = new MessageDisplay('Congratulations!');
game.addChild(message);
message.show();
}
// Remove caught apple
apples[i].destroy();
apples.splice(i, 1);
} else if (player.visible && apples[i] instanceof GreenApple && apples[i].isCaught(player) || player2.visible && apples[i] instanceof GreenApple && apples[i].isCaught(player2)) {
// Decrease health and check for game over
if (healthMeters.length > 0) {
var lastHealthMeter = healthMeters.pop();
lastHealthMeter.destroy();
if (healthMeters.length === 0) {
// Trigger game over with golden effect
LK.effects.flashScreen(0xFFFF00, 1000);
var endGameItem = game.addChild(new EndGameItem());
endGameItem.x = player.x;
endGameItem.y = player.y;
endGameItem.visible = true;
player.visible = false;
player2.visible = false;
LK.showGameOver();
}
}
// Remove caught green apple
apples[i].destroy();
apples.splice(i, 1);
} else if (apples[i].y > 2732) {
// Remove apple if it falls off the screen
apples[i].destroy();
apples.splice(i, 1);
}
}
// Spawn apples less frequently
if (LK.ticks % 90 == 0) {
// Every two seconds
var appleType = Math.random() < 0.25 ? new Apple() : new GreenApple(); // 25% chance for red apple, 75% for green apple
var newApple = appleType;
newApple.x = Math.random() * 2048;
newApple.y = 2732 / 2; // Start at the middle of the screen in height
apples.push(newApple);
game.addChild(newApple);
}
});
grass
the fields of Britain, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
green apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
eureka moment, cartoon style, light, no people. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
heart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
stars flying on an ellipse, cartoon style, side view , no people. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white "=" on a green apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white "F" on a red apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
the "G" sign on the red apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white " (M" on a red apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white sign with a small "m" on a red apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white " /" on a green apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white "R" on a red apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
green
a white " 2" on a red apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.