User prompt
when the character goes to the right handle collisions of only the player2 when the character goes to the left handle collisions of only the player
User prompt
when the character goes to the right handle collisions only player when the character goes to the left handle collisions only player2
User prompt
collisions don't work properly. Fix it.
User prompt
to double the speed of the apples
User prompt
increase the speed of the players
User prompt
limit the birthplace of apples to the middle of the screen in height.
User prompt
to increase the life span of all apples
User prompt
when players collide with red apples, show an explosion in their place for half a second
User prompt
make the apples be born in the first third of the frame in height.
User prompt
make the apples grow taller.
User prompt
sometimes apples disappear without interaction with players all redo everything
User prompt
to increase the longevity of all apples without decreasing their fall rate
User prompt
to increase the longevity of all apples
User prompt
sometimes green apples spontaneously disappear far away from players fix the bug
User prompt
sometimes apples spontaneously disappear far away from players fix the bug
User prompt
sometimes apples spontaneously disappear, fix the error.
User prompt
sometimes apples spontaneously disappear, fix the error.
User prompt
sometimes apples spontaneously disappear, fix the error.
User prompt
sometimes apples spontaneously disappear, fix the error.
User prompt
sometimes apples spontaneously disappear, fix the error.
User prompt
sometimes apples spontaneously disappear, fix the error.
User prompt
sometimes apples spontaneously disappear, fix the error.
User prompt
sometimes apples spontaneously disappear, fix the error.
User prompt
reduce player collision
User prompt
apples sometimes interact with players at a great distance, clarify player collisions
/**** * Classes ****/ // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1); self.speed = 10; 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 = 10; 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 = 6; self.move = function () { self.y += self.speed; }; self.isCaught = function (player, player2) { var playerBounds = player.getBounds(); var player2Bounds = player2.getBounds(); var appleBounds = self.getBounds(); return appleBounds.y + appleBounds.height > playerBounds.y && appleBounds.x + appleBounds.width / 2 > playerBounds.x && appleBounds.x - appleBounds.width / 2 < playerBounds.x + playerBounds.width || appleBounds.y + appleBounds.height > player2Bounds.y && appleBounds.x + appleBounds.width / 2 > player2Bounds.x && appleBounds.x - appleBounds.width / 2 < player2Bounds.x + player2Bounds.width; }; }); // 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 = 10; self.move = function () { self.y += self.speed; }; self.isCaught = function (player, player2) { var playerBounds = player.getBounds(); var player2Bounds = player2.getBounds(); var appleBounds = self.getBounds(); return appleBounds.y + appleBounds.height > playerBounds.y && appleBounds.x + appleBounds.width / 2 > playerBounds.x && appleBounds.x - appleBounds.width / 2 < playerBounds.x + playerBounds.width || appleBounds.y + appleBounds.height > player2Bounds.y && appleBounds.x + appleBounds.width / 2 > player2Bounds.x && appleBounds.x - appleBounds.width / 2 < player2Bounds.x + player2Bounds.width; }; }); // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.createAsset('explosion', 'Explosion effect', 0.5, 0.5); self.visible = false; self.show = function (x, y) { self.x = x; self.y = y; self.visible = true; LK.setTimeout(function () { self.visible = false; self.destroy(); }, 300); }; }); // Health class var Health = Container.expand(function () { var self = Container.call(this); self.lives = 3; var heartGraphics = []; for (var i = 0; i < self.lives; i++) { heartGraphics[i] = self.createAsset('heart', 'Health heart', 0, 0); heartGraphics[i].x = i * (heartGraphics[i].width + 10); heartGraphics[i].y = 0; } self.loseLife = function () { if (self.lives > 0) { self.lives--; heartGraphics[self.lives].visible = false; if (self.lives === 0) { LK.showGameOver(); } } }; }); /**** * 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 health meter var health = game.addChild(new Health()); health.x = 10; health.y = 10; // Initialize apples array var apples = []; // 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 if (apples[i].isCaught(player, player2)) { // Increase score for red apples if (apples[i] instanceof Apple) { LK.setScore(LK.getScore() + 1); var explosion = new Explosion(); explosion.show(apples[i].x, apples[i].y); game.addChild(explosion); } // Decrease health for green apples if (apples[i] instanceof GreenApple) { health.loseLife(); } // Remove caught 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 % 120 == 0) { // Every two seconds var newApple = Math.random() < 0.5 ? new Apple() : new GreenApple(); newApple.x = Math.random() * 2048; // Apples should be born in the second-highest half of the screen newApple.y = Math.random() * (2732 / 2 - newApple.height) + 2732 / 4; apples.push(newApple); game.addChild(newApple); } });
/****
* Classes
****/
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1);
self.speed = 10;
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 = 10;
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 = 6;
self.move = function () {
self.y += self.speed;
};
self.isCaught = function (player, player2) {
var playerBounds = player.getBounds();
var player2Bounds = player2.getBounds();
var appleBounds = self.getBounds();
return appleBounds.y + appleBounds.height > playerBounds.y && appleBounds.x + appleBounds.width / 2 > playerBounds.x && appleBounds.x - appleBounds.width / 2 < playerBounds.x + playerBounds.width || appleBounds.y + appleBounds.height > player2Bounds.y && appleBounds.x + appleBounds.width / 2 > player2Bounds.x && appleBounds.x - appleBounds.width / 2 < player2Bounds.x + player2Bounds.width;
};
});
// 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 = 10;
self.move = function () {
self.y += self.speed;
};
self.isCaught = function (player, player2) {
var playerBounds = player.getBounds();
var player2Bounds = player2.getBounds();
var appleBounds = self.getBounds();
return appleBounds.y + appleBounds.height > playerBounds.y && appleBounds.x + appleBounds.width / 2 > playerBounds.x && appleBounds.x - appleBounds.width / 2 < playerBounds.x + playerBounds.width || appleBounds.y + appleBounds.height > player2Bounds.y && appleBounds.x + appleBounds.width / 2 > player2Bounds.x && appleBounds.x - appleBounds.width / 2 < player2Bounds.x + player2Bounds.width;
};
});
// Explosion class
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.createAsset('explosion', 'Explosion effect', 0.5, 0.5);
self.visible = false;
self.show = function (x, y) {
self.x = x;
self.y = y;
self.visible = true;
LK.setTimeout(function () {
self.visible = false;
self.destroy();
}, 300);
};
});
// Health class
var Health = Container.expand(function () {
var self = Container.call(this);
self.lives = 3;
var heartGraphics = [];
for (var i = 0; i < self.lives; i++) {
heartGraphics[i] = self.createAsset('heart', 'Health heart', 0, 0);
heartGraphics[i].x = i * (heartGraphics[i].width + 10);
heartGraphics[i].y = 0;
}
self.loseLife = function () {
if (self.lives > 0) {
self.lives--;
heartGraphics[self.lives].visible = false;
if (self.lives === 0) {
LK.showGameOver();
}
}
};
});
/****
* 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 health meter
var health = game.addChild(new Health());
health.x = 10;
health.y = 10;
// Initialize apples array
var apples = [];
// 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
if (apples[i].isCaught(player, player2)) {
// Increase score for red apples
if (apples[i] instanceof Apple) {
LK.setScore(LK.getScore() + 1);
var explosion = new Explosion();
explosion.show(apples[i].x, apples[i].y);
game.addChild(explosion);
}
// Decrease health for green apples
if (apples[i] instanceof GreenApple) {
health.loseLife();
}
// Remove caught 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 % 120 == 0) {
// Every two seconds
var newApple = Math.random() < 0.5 ? new Apple() : new GreenApple();
newApple.x = Math.random() * 2048;
// Apples should be born in the second-highest half of the screen
newApple.y = Math.random() * (2732 / 2 - newApple.height) + 2732 / 4;
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.