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
===================================================================
--- original.js
+++ change.js
@@ -1,12 +1,23 @@
/****
* Classes
****/
+// 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 = 10;
+ self.speed = 5;
self.targetX = self.x;
self.moveLeft = function () {
if (self.x > self.targetX && self.x > playerGraphics.width / 2) {
self.x -= self.speed;
@@ -21,9 +32,9 @@
// 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.speed = 5;
self.targetX = self.x;
self.visible = false;
self.moveLeft = function () {
if (self.x > self.targetX && self.x > playerGraphics.width / 2) {
@@ -39,24 +50,32 @@
// 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.speed = 3;
self.move = function () {
self.y += self.speed;
};
self.isCaught = function (player, player2) {
var playerHeadY = player.y - player.height / 2;
var player2HeadY = player2.y - player2.height / 2;
var appleBottomY = self.y + self.height / 2;
- return self.intersects(player) && appleBottomY < playerHeadY || self.intersects(player2) && appleBottomY < player2HeadY;
+ if (self.intersects(player) && appleBottomY < playerHeadY || self.intersects(player2) && appleBottomY < player2HeadY) {
+ var explosion = new Explosion();
+ explosion.x = self.x;
+ explosion.y = self.y;
+ game.addChild(explosion);
+ explosion.animate();
+ 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 = 10;
+ self.speed = 5;
self.move = function () {
self.y += self.speed;
};
self.isCaught = function (player, player2) {
@@ -65,23 +84,8 @@
var appleBottomY = self.y + self.height / 2;
return self.intersects(player) && appleBottomY < playerHeadY || self.intersects(player2) && appleBottomY < player2HeadY;
};
});
-// 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);
- };
-});
/****
* Initialize Game
****/
@@ -153,14 +157,8 @@
// Check if apple is caught by the player
if (apples[i].isCaught(player, player2)) {
// Increase score
LK.setScore(LK.getScore() + 1);
- // Show explosion at the apple's position only if it's not a green apple
- if (!(apples[i] instanceof GreenApple)) {
- var explosion = new Explosion();
- explosion.show(apples[i].x, apples[i].y);
- game.addChild(explosion);
- }
// Remove caught apple
apples[i].destroy();
apples.splice(i, 1);
} else if (apples[i].y > 2732) {
@@ -174,10 +172,9 @@
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 first third of the screen in height
- newApple.y = Math.random() * (2732 / 3 - newApple.height);
+ newApple.y = -50; // Start off-screen
apples.push(newApple);
game.addChild(newApple);
}
});
\ No newline at end of file
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.