/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bucket = Container.expand(function () {
var self = Container.call(this);
var bucketGraphics = self.attachAsset('bucket', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = self.x;
self.update = function () {
var diff = self.targetX - self.x;
self.x += diff * 0.15;
};
return self;
});
var Popcorn = Container.expand(function () {
var self = Container.call(this);
var popcornGraphics = self.attachAsset('popcorn', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3 + Math.random() * 4;
self.rotationSpeed = (Math.random() - 0.5) * 0.2;
self.lastY = self.y;
self.caught = false;
self.update = function () {
if (self.caught) return;
self.y += self.speed;
popcornGraphics.rotation += self.rotationSpeed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Game variables
var gameEnded = false;
var popcorns = [];
var gameTime = 0;
var streak = 0;
var missedPopcorn = 0;
var maxMisses = 10;
var spawnRate = 120; // frames between spawns
// Create movie theater setup
var movieFrame = game.addChild(LK.getAsset('movieFrame', {
anchorX: 0.5,
anchorY: 0.5
}));
movieFrame.x = 1024;
movieFrame.y = 600;
var movieScreen = game.addChild(LK.getAsset('movieScreen', {
anchorX: 0.5,
anchorY: 0.5
}));
movieScreen.x = 1024;
movieScreen.y = 600;
// Add "Now Playing" text on screen
var movieText = new Text2('🎬 MOVIE NIGHT 🎬\nCatch the popcorn!', {
size: 80,
fill: 0xFFFFFF
});
movieText.anchor.set(0.5, 0.5);
movieText.x = 1024;
movieText.y = 600;
game.addChild(movieText);
// Create bucket
var bucket = game.addChild(new Bucket());
bucket.x = 1024;
bucket.y = 2400;
// Score display
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var missText = new Text2('Missed: 0/10', {
size: 60,
fill: 0xFF6B6B
});
missText.anchor.set(0.5, 0);
missText.y = 100;
LK.gui.top.addChild(missText);
var streakText = new Text2('Streak: 0', {
size: 50,
fill: 0xF39C12
});
streakText.anchor.set(1, 0);
streakText.y = 200;
LK.gui.topRight.addChild(streakText);
// Game functions
function spawnPopcorn() {
if (gameEnded) return;
var popcorn = new Popcorn();
popcorn.x = 200 + Math.random() * 1648; // Random X position across screen
popcorn.y = -50; // Start above screen
popcorn.lastY = popcorn.y;
popcorns.push(popcorn);
game.addChild(popcorn);
LK.getSound('pop').play();
}
function catchPopcorn(popcorn) {
if (popcorn.caught) return;
popcorn.caught = true;
LK.getSound('catch').play();
var points = 10 + streak * 2;
LK.setScore(LK.getScore() + points);
streak++;
scoreText.setText('Score: ' + LK.getScore());
streakText.setText('Streak: ' + streak);
// Remove popcorn
for (var i = 0; i < popcorns.length; i++) {
if (popcorns[i] === popcorn) {
popcorns[i].destroy();
popcorns.splice(i, 1);
break;
}
}
}
function missPopcorn() {
LK.getSound('miss').play();
missedPopcorn++;
streak = 0;
streakText.setText('Streak: ' + streak);
missText.setText('Missed: ' + missedPopcorn + '/' + maxMisses);
if (missedPopcorn >= maxMisses) {
endGame();
}
}
function endGame() {
gameEnded = true;
// Save high score
var highScore = storage.highScore || 0;
if (LK.getScore() > highScore) {
storage.highScore = LK.getScore();
}
storage.gamesPlayed = (storage.gamesPlayed || 0) + 1;
if (LK.getScore() >= 500) {
LK.showYouWin();
} else {
LK.showGameOver();
}
}
// Touch controls
game.move = function (x, y, obj) {
if (gameEnded) return;
bucket.targetX = x;
};
game.down = function (x, y, obj) {
if (gameEnded) return;
bucket.targetX = x;
};
// Main game update
game.update = function () {
if (gameEnded) return;
gameTime++;
// Spawn popcorn
if (gameTime % spawnRate === 0) {
spawnPopcorn();
// Increase difficulty over time
if (spawnRate > 30) {
spawnRate -= 1;
}
}
// Update popcorns and check collisions
for (var i = popcorns.length - 1; i >= 0; i--) {
var popcorn = popcorns[i];
if (popcorn.caught) continue;
// Check if popcorn fell off screen
if (popcorn.lastY <= 2732 && popcorn.y > 2732) {
missPopcorn();
popcorns[i].destroy();
popcorns.splice(i, 1);
continue;
}
// Check collision with bucket
if (popcorn.intersects(bucket)) {
catchPopcorn(popcorn);
continue;
}
popcorn.lastY = popcorn.y;
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bucket = Container.expand(function () {
var self = Container.call(this);
var bucketGraphics = self.attachAsset('bucket', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = self.x;
self.update = function () {
var diff = self.targetX - self.x;
self.x += diff * 0.15;
};
return self;
});
var Popcorn = Container.expand(function () {
var self = Container.call(this);
var popcornGraphics = self.attachAsset('popcorn', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3 + Math.random() * 4;
self.rotationSpeed = (Math.random() - 0.5) * 0.2;
self.lastY = self.y;
self.caught = false;
self.update = function () {
if (self.caught) return;
self.y += self.speed;
popcornGraphics.rotation += self.rotationSpeed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Game variables
var gameEnded = false;
var popcorns = [];
var gameTime = 0;
var streak = 0;
var missedPopcorn = 0;
var maxMisses = 10;
var spawnRate = 120; // frames between spawns
// Create movie theater setup
var movieFrame = game.addChild(LK.getAsset('movieFrame', {
anchorX: 0.5,
anchorY: 0.5
}));
movieFrame.x = 1024;
movieFrame.y = 600;
var movieScreen = game.addChild(LK.getAsset('movieScreen', {
anchorX: 0.5,
anchorY: 0.5
}));
movieScreen.x = 1024;
movieScreen.y = 600;
// Add "Now Playing" text on screen
var movieText = new Text2('🎬 MOVIE NIGHT 🎬\nCatch the popcorn!', {
size: 80,
fill: 0xFFFFFF
});
movieText.anchor.set(0.5, 0.5);
movieText.x = 1024;
movieText.y = 600;
game.addChild(movieText);
// Create bucket
var bucket = game.addChild(new Bucket());
bucket.x = 1024;
bucket.y = 2400;
// Score display
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var missText = new Text2('Missed: 0/10', {
size: 60,
fill: 0xFF6B6B
});
missText.anchor.set(0.5, 0);
missText.y = 100;
LK.gui.top.addChild(missText);
var streakText = new Text2('Streak: 0', {
size: 50,
fill: 0xF39C12
});
streakText.anchor.set(1, 0);
streakText.y = 200;
LK.gui.topRight.addChild(streakText);
// Game functions
function spawnPopcorn() {
if (gameEnded) return;
var popcorn = new Popcorn();
popcorn.x = 200 + Math.random() * 1648; // Random X position across screen
popcorn.y = -50; // Start above screen
popcorn.lastY = popcorn.y;
popcorns.push(popcorn);
game.addChild(popcorn);
LK.getSound('pop').play();
}
function catchPopcorn(popcorn) {
if (popcorn.caught) return;
popcorn.caught = true;
LK.getSound('catch').play();
var points = 10 + streak * 2;
LK.setScore(LK.getScore() + points);
streak++;
scoreText.setText('Score: ' + LK.getScore());
streakText.setText('Streak: ' + streak);
// Remove popcorn
for (var i = 0; i < popcorns.length; i++) {
if (popcorns[i] === popcorn) {
popcorns[i].destroy();
popcorns.splice(i, 1);
break;
}
}
}
function missPopcorn() {
LK.getSound('miss').play();
missedPopcorn++;
streak = 0;
streakText.setText('Streak: ' + streak);
missText.setText('Missed: ' + missedPopcorn + '/' + maxMisses);
if (missedPopcorn >= maxMisses) {
endGame();
}
}
function endGame() {
gameEnded = true;
// Save high score
var highScore = storage.highScore || 0;
if (LK.getScore() > highScore) {
storage.highScore = LK.getScore();
}
storage.gamesPlayed = (storage.gamesPlayed || 0) + 1;
if (LK.getScore() >= 500) {
LK.showYouWin();
} else {
LK.showGameOver();
}
}
// Touch controls
game.move = function (x, y, obj) {
if (gameEnded) return;
bucket.targetX = x;
};
game.down = function (x, y, obj) {
if (gameEnded) return;
bucket.targetX = x;
};
// Main game update
game.update = function () {
if (gameEnded) return;
gameTime++;
// Spawn popcorn
if (gameTime % spawnRate === 0) {
spawnPopcorn();
// Increase difficulty over time
if (spawnRate > 30) {
spawnRate -= 1;
}
}
// Update popcorns and check collisions
for (var i = popcorns.length - 1; i >= 0; i--) {
var popcorn = popcorns[i];
if (popcorn.caught) continue;
// Check if popcorn fell off screen
if (popcorn.lastY <= 2732 && popcorn.y > 2732) {
missPopcorn();
popcorns[i].destroy();
popcorns.splice(i, 1);
continue;
}
// Check collision with bucket
if (popcorn.intersects(bucket)) {
catchPopcorn(popcorn);
continue;
}
popcorn.lastY = popcorn.y;
}
};