/**** * Plugins ****/ var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // Class for the apples 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(); } }; return self; }); // Class for the poisonous apples var PoisonousApple = Container.expand(function () { var self = Container.call(this); var appleGraphics = self.attachAsset('poisonousApple', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; return self; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for the main character, Super Yoshi var SuperYoshi = Container.expand(function () { var self = Container.call(this); var yoshiGraphics = self.attachAsset('yoshi', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.jumpHeight = 200; self.isJumping = false; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.y -= self.jumpHeight; LK.setTimeout(function () { self.y += self.jumpHeight; self.isJumping = false; }, 500); } }; self.update = function () { // Add any continuous updates for Yoshi here }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Init game with sky blue background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0.0, anchorY: 0.0, x: 0, y: 0 })); // Black color for poisonous apple var poisonousApples = []; var poisonousApplesEaten = 0; // Function to spawn poisonous apples function spawnPoisonousApple() { var poisonousApple = new PoisonousApple(); poisonousApple.x = Math.random() * 2048; poisonousApple.y = -50; poisonousApples.push(poisonousApple); game.addChild(poisonousApple); } game.move = function (x, y, obj) { yoshi.x = x; yoshi.y = y; }; var yoshi = game.addChild(new SuperYoshi()); yoshi.x = 2048 / 2; yoshi.y = 2732 - 150; // Position Yoshi at the bottom of the screen var apples = []; var score = 0; var highestScore = storage.highestScore || 0; var scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Function to spawn apples function spawnApple() { var apple = new Apple(); apple.x = Math.random() * 2048; apple.y = -50; apples.push(apple); game.addChild(apple); } // Handle touch events for jumping game.down = function (x, y, obj) { yoshi.jump(); }; // Update game state game.update = function () { yoshi.update(); for (var i = apples.length - 1; i >= 0; i--) { apples[i].update(); if (yoshi.intersects(apples[i])) { score += 1; if (score > highestScore) { highestScore = score; storage.highestScore = highestScore; if (score >= 100) { yoshiGraphics = yoshi.attachAsset('superYoshi', { anchorX: 0.5, anchorY: 0.5 }); } } scoreTxt.setText('Score: ' + score + ', Highest Score: ' + highestScore); apples[i].destroy(); apples.splice(i, 1); LK.getSound('yosh').play(); // Play 'yosh' sound } } for (var i = poisonousApples.length - 1; i >= 0; i--) { poisonousApples[i].update(); if (yoshi.intersects(poisonousApples[i])) { LK.getSound('yu').play(); // Play 'yu' sound poisonousApplesEaten += 1; if (poisonousApplesEaten >= 3) { LK.getSound('yu').play(); // Play 'yu' sound LK.showGameOver(); // Game over when Yoshi eats 3 poisonous apples score = 0; storage.highestScore = highestScore; } poisonousApples[i].destroy(); poisonousApples.splice(i, 1); } } if (LK.ticks % 60 === 0) { spawnApple(); } if (LK.ticks % 120 === 0) { // Spawn a poisonous apple every 120 frames spawnPoisonousApple(); } };
/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
// Class for the apples
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();
}
};
return self;
});
// Class for the poisonous apples
var PoisonousApple = Container.expand(function () {
var self = Container.call(this);
var appleGraphics = self.attachAsset('poisonousApple', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
return self;
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the main character, Super Yoshi
var SuperYoshi = Container.expand(function () {
var self = Container.call(this);
var yoshiGraphics = self.attachAsset('yoshi', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.jumpHeight = 200;
self.isJumping = false;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.y -= self.jumpHeight;
LK.setTimeout(function () {
self.y += self.jumpHeight;
self.isJumping = false;
}, 500);
}
};
self.update = function () {
// Add any continuous updates for Yoshi here
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
}));
// Black color for poisonous apple
var poisonousApples = [];
var poisonousApplesEaten = 0;
// Function to spawn poisonous apples
function spawnPoisonousApple() {
var poisonousApple = new PoisonousApple();
poisonousApple.x = Math.random() * 2048;
poisonousApple.y = -50;
poisonousApples.push(poisonousApple);
game.addChild(poisonousApple);
}
game.move = function (x, y, obj) {
yoshi.x = x;
yoshi.y = y;
};
var yoshi = game.addChild(new SuperYoshi());
yoshi.x = 2048 / 2;
yoshi.y = 2732 - 150; // Position Yoshi at the bottom of the screen
var apples = [];
var score = 0;
var highestScore = storage.highestScore || 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn apples
function spawnApple() {
var apple = new Apple();
apple.x = Math.random() * 2048;
apple.y = -50;
apples.push(apple);
game.addChild(apple);
}
// Handle touch events for jumping
game.down = function (x, y, obj) {
yoshi.jump();
};
// Update game state
game.update = function () {
yoshi.update();
for (var i = apples.length - 1; i >= 0; i--) {
apples[i].update();
if (yoshi.intersects(apples[i])) {
score += 1;
if (score > highestScore) {
highestScore = score;
storage.highestScore = highestScore;
if (score >= 100) {
yoshiGraphics = yoshi.attachAsset('superYoshi', {
anchorX: 0.5,
anchorY: 0.5
});
}
}
scoreTxt.setText('Score: ' + score + ', Highest Score: ' + highestScore);
apples[i].destroy();
apples.splice(i, 1);
LK.getSound('yosh').play(); // Play 'yosh' sound
}
}
for (var i = poisonousApples.length - 1; i >= 0; i--) {
poisonousApples[i].update();
if (yoshi.intersects(poisonousApples[i])) {
LK.getSound('yu').play(); // Play 'yu' sound
poisonousApplesEaten += 1;
if (poisonousApplesEaten >= 3) {
LK.getSound('yu').play(); // Play 'yu' sound
LK.showGameOver(); // Game over when Yoshi eats 3 poisonous apples
score = 0;
storage.highestScore = highestScore;
}
poisonousApples[i].destroy();
poisonousApples.splice(i, 1);
}
}
if (LK.ticks % 60 === 0) {
spawnApple();
}
if (LK.ticks % 120 === 0) {
// Spawn a poisonous apple every 120 frames
spawnPoisonousApple();
}
};