/****
* Classes
****/
// Apple class
var Apple = Container.expand(function () {
var self = Container.call(this);
var appleGraphics = self.attachAsset('apple', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Pumpkin class
var Pumpkin = Container.expand(function () {
var self = Container.call(this);
var pumpkinGraphics = self.attachAsset('pumpkin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
// Find and remove this pumpkin from the pumpkins array
for (var i = pumpkins.length - 1; i >= 0; i--) {
if (pumpkins[i] === self) {
pumpkins.splice(i, 1);
break;
}
}
self.destroy();
}
};
});
// RedApple class
var RedApple = Container.expand(function () {
var self = Container.call(this);
var redAppleGraphics = self.attachAsset('redApple', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Assets will be automatically created and loaded during gameplay
// Red Panda class
var RedPanda = Container.expand(function () {
var self = Container.call(this);
var pandaGraphics = self.attachAsset('redPanda', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Red Panda update logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background color
});
/****
* Game Code
****/
var moon = LK.getAsset('moon', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 1300
});
game.addChild(moon);
// Play Music1
LK.playMusic('Music1', {
loop: true,
fade: {
start: 0,
end: 1,
duration: 1000
}
});
// Play Owl1 sound
LK.getSound('owl1').play();
// Play Owl1 sound
LK.getSound('owl1').play();
var redPanda = game.addChild(new RedPanda());
redPanda.x = 2048 / 2;
redPanda.y = 2500;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var score = 0;
var apples = [];
var redApples = [];
var pumpkins = [];
var bamboos = [];
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
// Constrain y position to upper half of the map (y <= 1366, which is 2732/2)
if (y <= 1366) {
dragNode.y = y;
}
}
}
game.down = function (x, y, obj) {
dragNode = redPanda;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
game.move = handleMove;
game.update = function () {
for (var i = apples.length - 1; i >= 0; i--) {
if (apples[i].intersects(redPanda)) {
score += 1;
scoreTxt.setText(score);
// Create +1 text
var plusOneText = new Text2('+1', {
size: 100,
fill: 0xFFFFFF
});
plusOneText.anchor.set(0.5, 0.5);
plusOneText.x = apples[i].x;
plusOneText.y = apples[i].y - 50;
game.addChild(plusOneText);
// Animate +1 text upwards and fade out
LK.setTimeout(function () {
plusOneText.y -= 50;
plusOneText.alpha = 0;
plusOneText.destroy();
}, 1000);
apples[i].destroy();
apples.splice(i, 1);
if (score % 10 === 0) {
var newRedApple = new RedApple();
newRedApple.x = Math.random() * 2048;
newRedApple.y = -50;
redApples.push(newRedApple);
game.addChild(newRedApple);
LK.setTimeout(function () {
newRedApple.destroy();
}, 7000);
}
}
}
for (var i = redApples.length - 1; i >= 0; i--) {
if (redApples[i].intersects(redPanda)) {
score += 2;
scoreTxt.setText(score);
// Create +2 text
var plusTwoText = new Text2('+2', {
size: 100,
fill: 0xFFFFFF
});
plusTwoText.anchor.set(0.5, 0.5);
plusTwoText.x = redApples[i].x;
plusTwoText.y = redApples[i].y - 50;
game.addChild(plusTwoText);
// Animate +2 text upwards and fade out
LK.setTimeout(function () {
plusTwoText.y -= 50;
plusTwoText.alpha = 0;
plusTwoText.destroy();
}, 1000);
redApples[i].destroy();
redApples.splice(i, 1);
}
}
for (var j = pumpkins.length - 1; j >= 0; j--) {
// Use direct intersects method for precise edge-to-edge collision detection
if (pumpkins[j].intersects(redPanda)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
if (LK.ticks % 60 == 0) {
var newApple = new Apple();
newApple.x = Math.random() * 2048;
newApple.y = -50;
apples.push(newApple);
game.addChild(newApple);
}
if (LK.ticks % 120 == 0) {
var newPumpkin = new Pumpkin();
newPumpkin.x = Math.random() * 2048;
newPumpkin.y = -50;
pumpkins.push(newPumpkin);
game.addChild(newPumpkin);
}
}; /****
* Classes
****/
// Apple class
var Apple = Container.expand(function () {
var self = Container.call(this);
var appleGraphics = self.attachAsset('apple', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Pumpkin class
var Pumpkin = Container.expand(function () {
var self = Container.call(this);
var pumpkinGraphics = self.attachAsset('pumpkin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
// Find and remove this pumpkin from the pumpkins array
for (var i = pumpkins.length - 1; i >= 0; i--) {
if (pumpkins[i] === self) {
pumpkins.splice(i, 1);
break;
}
}
self.destroy();
}
};
});
// RedApple class
var RedApple = Container.expand(function () {
var self = Container.call(this);
var redAppleGraphics = self.attachAsset('redApple', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Assets will be automatically created and loaded during gameplay
// Red Panda class
var RedPanda = Container.expand(function () {
var self = Container.call(this);
var pandaGraphics = self.attachAsset('redPanda', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Red Panda update logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background color
});
/****
* Game Code
****/
var moon = LK.getAsset('moon', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 1300
});
game.addChild(moon);
// Play Music1
LK.playMusic('Music1', {
loop: true,
fade: {
start: 0,
end: 1,
duration: 1000
}
});
// Play Owl1 sound
LK.getSound('owl1').play();
// Play Owl1 sound
LK.getSound('owl1').play();
var redPanda = game.addChild(new RedPanda());
redPanda.x = 2048 / 2;
redPanda.y = 2500;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var score = 0;
var apples = [];
var redApples = [];
var pumpkins = [];
var bamboos = [];
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
// Constrain y position to upper half of the map (y <= 1366, which is 2732/2)
if (y <= 1366) {
dragNode.y = y;
}
}
}
game.down = function (x, y, obj) {
dragNode = redPanda;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
game.move = handleMove;
game.update = function () {
for (var i = apples.length - 1; i >= 0; i--) {
if (apples[i].intersects(redPanda)) {
score += 1;
scoreTxt.setText(score);
// Create +1 text
var plusOneText = new Text2('+1', {
size: 100,
fill: 0xFFFFFF
});
plusOneText.anchor.set(0.5, 0.5);
plusOneText.x = apples[i].x;
plusOneText.y = apples[i].y - 50;
game.addChild(plusOneText);
// Animate +1 text upwards and fade out
LK.setTimeout(function () {
plusOneText.y -= 50;
plusOneText.alpha = 0;
plusOneText.destroy();
}, 1000);
apples[i].destroy();
apples.splice(i, 1);
if (score % 10 === 0) {
var newRedApple = new RedApple();
newRedApple.x = Math.random() * 2048;
newRedApple.y = -50;
redApples.push(newRedApple);
game.addChild(newRedApple);
LK.setTimeout(function () {
newRedApple.destroy();
}, 7000);
}
}
}
for (var i = redApples.length - 1; i >= 0; i--) {
if (redApples[i].intersects(redPanda)) {
score += 2;
scoreTxt.setText(score);
// Create +2 text
var plusTwoText = new Text2('+2', {
size: 100,
fill: 0xFFFFFF
});
plusTwoText.anchor.set(0.5, 0.5);
plusTwoText.x = redApples[i].x;
plusTwoText.y = redApples[i].y - 50;
game.addChild(plusTwoText);
// Animate +2 text upwards and fade out
LK.setTimeout(function () {
plusTwoText.y -= 50;
plusTwoText.alpha = 0;
plusTwoText.destroy();
}, 1000);
redApples[i].destroy();
redApples.splice(i, 1);
}
}
for (var j = pumpkins.length - 1; j >= 0; j--) {
// Use direct intersects method for precise edge-to-edge collision detection
if (pumpkins[j].intersects(redPanda)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
if (LK.ticks % 60 == 0) {
var newApple = new Apple();
newApple.x = Math.random() * 2048;
newApple.y = -50;
apples.push(newApple);
game.addChild(newApple);
}
if (LK.ticks % 120 == 0) {
var newPumpkin = new Pumpkin();
newPumpkin.x = Math.random() * 2048;
newPumpkin.y = -50;
pumpkins.push(newPumpkin);
game.addChild(newPumpkin);
}
};