/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var FallingItem = Container.expand(function (itemType) {
var self = Container.call(this);
self.itemType = itemType;
self.speed = Math.random() * 3 + 2; // Random speed between 2-5
// Define item properties
var itemData = {
'book': {
value: 2,
asset: 'book'
},
'money': {
value: 4,
asset: 'money'
},
'movie': {
value: 6,
asset: 'movie'
},
'phone': {
value: 8,
asset: 'phone'
},
'laptop': {
value: 10,
asset: 'laptop'
},
'tablet': {
value: 12,
asset: 'tablet'
},
'headphones': {
value: 14,
asset: 'headphones'
},
'ticket': {
value: 16,
asset: 'ticket'
},
'soda': {
value: 18,
asset: 'soda'
},
'goldCircle': {
value: 180,
asset: 'goldCircle'
},
'maroonCircle': {
value: 0.01,
asset: 'maroonCircle'
},
'magentaCircle': {
value: 0.03,
asset: 'magentaCircle'
},
'grayCircle': {
value: 0.05,
asset: 'grayCircle'
},
'blackCircle': {
value: 0.09,
asset: 'blackCircle'
}
};
self.value = itemData[itemType].value;
var itemGraphics = self.attachAsset(itemData[itemType].asset, {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
return self;
});
var SettingsButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('settingsButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2('SET', {
size: 30,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
// Cycle through timer options: 5, 10, 15, 20, 25, 30, 35 minutes
var currentTimer = storage.gameTimer || 300; // Default 5 minutes
var timerOptions = [300, 600, 900, 1200, 1500, 1800, 2100]; // In seconds
var currentIndex = timerOptions.indexOf(currentTimer);
var nextIndex = (currentIndex + 1) % timerOptions.length;
var newTimer = timerOptions[nextIndex];
storage.gameTimer = newTimer;
gameTimer = newTimer;
timeRemaining = newTimer;
updateTimerDisplay();
};
return self;
});
/****
* Initialize Game
****/
// Game variables
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Sound effects
// Player character
// Small colored circles for cents
// Special golden circle
// Initialize all falling item assets with different colors
// Game variables
var player;
var fallingItems = [];
var totalMoney = 0;
var inventory = {
books: 0,
money: 0,
movies: 0,
phones: 0,
laptops: 0,
tablets: 0,
headphones: 0,
tickets: 0,
sodas: 0,
goldCircles: 0
};
// Timer variables
var gameTimer = storage.gameTimer || 300; // Default 5 minutes in seconds
var timeRemaining = gameTimer;
var gameStarted = false;
// Item spawn types and probabilities
var itemTypes = ['book', 'money', 'movie', 'phone', 'laptop', 'tablet', 'headphones', 'ticket', 'soda'];
var centTypes = ['maroonCircle', 'magentaCircle', 'grayCircle', 'blackCircle'];
// Create player
player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2500;
// Create UI elements
var moneyText = new Text2('$0.00', {
size: 80,
fill: 0x00FF00
});
moneyText.anchor.set(1, 0);
LK.gui.topRight.addChild(moneyText);
var timerText = new Text2('5:00', {
size: 60,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
var settingsButton = game.addChild(new SettingsButton());
settingsButton.x = 250;
settingsButton.y = 150;
function updateTimerDisplay() {
var minutes = Math.floor(timeRemaining / 60);
var seconds = timeRemaining % 60;
var timeString = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
timerText.setText(timeString);
}
function showGameOverWithInventory() {
var finalInventory = 'Final Collection:\n';
finalInventory += 'Books: ' + inventory.books + '\n';
finalInventory += 'Money: ' + inventory.money + '\n';
finalInventory += 'Movies: ' + inventory.movies + '\n';
finalInventory += 'Phones: ' + inventory.phones + '\n';
finalInventory += 'Laptops: ' + inventory.laptops + '\n';
finalInventory += 'Tablets: ' + inventory.tablets + '\n';
finalInventory += 'Headphones: ' + inventory.headphones + '\n';
finalInventory += 'Tickets: ' + inventory.tickets + '\n';
finalInventory += 'Sodas: ' + inventory.sodas + '\n';
if (inventory.goldCircles > 0) {
finalInventory += 'Gold Circles: ' + inventory.goldCircles + '\n';
}
finalInventory += '\nTotal Money: $' + totalMoney.toFixed(2);
console.log(finalInventory);
LK.showGameOver();
}
// Touch/mouse controls for player movement
var isMoving = false;
var targetX = 0;
game.move = function (x, y, obj) {
if (isMoving) {
targetX = x;
player.x = Math.max(50, Math.min(1998, targetX));
}
};
game.down = function (x, y, obj) {
isMoving = true;
targetX = x;
player.x = Math.max(50, Math.min(1998, targetX));
};
game.up = function (x, y, obj) {
isMoving = false;
};
// Spawn falling items
var spawnTimer = 0;
var spawnRate = 60; // Spawn every 60 ticks initially
function spawnItem() {
var itemType;
var rand = Math.random();
if (rand < 0.02) {
// 2% chance for gold circle
itemType = 'goldCircle';
} else if (rand < 0.15) {
// 13% chance for cent circles
itemType = centTypes[Math.floor(Math.random() * centTypes.length)];
} else {
// Regular items
itemType = itemTypes[Math.floor(Math.random() * itemTypes.length)];
}
var item = new FallingItem(itemType);
item.x = Math.random() * 1948 + 50; // Random X position with margins
item.y = -100;
item.lastY = item.y;
item.lastIntersecting = false;
fallingItems.push(item);
game.addChild(item);
}
game.update = function () {
// Start game on first item collection or movement
if (!gameStarted && (isMoving || fallingItems.length > 0)) {
gameStarted = true;
// Start background music when game begins
LK.playMusic('Uploaded', {
loop: true
});
}
// Update timer only when game has started
if (gameStarted) {
if (LK.ticks % 60 === 0 && timeRemaining > 0) {
// Update every second
timeRemaining--;
updateTimerDisplay();
if (timeRemaining <= 0) {
showGameOverWithInventory();
return;
}
}
}
// Spawn items
spawnTimer++;
if (spawnTimer >= spawnRate) {
spawnItem();
spawnTimer = 0;
// Gradually increase spawn rate
if (spawnRate > 20) {
spawnRate--;
}
}
// Update falling items
for (var i = fallingItems.length - 1; i >= 0; i--) {
var item = fallingItems[i];
// Check if item went off screen
if (item.lastY < 2800 && item.y >= 2800) {
item.destroy();
fallingItems.splice(i, 1);
continue;
}
// Check collision with player
var currentIntersecting = item.intersects(player);
if (!item.lastIntersecting && currentIntersecting) {
// Item collected!
var itemValue = item.value;
// Update inventory and money
if (item.itemType === 'book') inventory.books++;else if (item.itemType === 'money') inventory.money++;else if (item.itemType === 'movie') inventory.movies++;else if (item.itemType === 'phone') inventory.phones++;else if (item.itemType === 'laptop') inventory.laptops++;else if (item.itemType === 'tablet') inventory.tablets++;else if (item.itemType === 'headphones') inventory.headphones++;else if (item.itemType === 'ticket') inventory.tickets++;else if (item.itemType === 'soda') inventory.sodas++;else if (item.itemType === 'goldCircle') {
inventory.goldCircles++;
LK.getSound('special').play();
}
// Add value to total money
totalMoney += itemValue;
// Update displays
moneyText.setText('$' + totalMoney.toFixed(2));
// Play collect sound (except for gold which has its own)
if (item.itemType !== 'goldCircle') {
LK.getSound('collect').play();
}
// Flash effect for collection
LK.effects.flashObject(player, 0x00FF00, 200);
// Remove item
item.destroy();
fallingItems.splice(i, 1);
continue;
}
// Update last states
item.lastY = item.y;
item.lastIntersecting = currentIntersecting;
}
}; /****
* Plugins
****/
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var FallingItem = Container.expand(function (itemType) {
var self = Container.call(this);
self.itemType = itemType;
self.speed = Math.random() * 3 + 2; // Random speed between 2-5
// Define item properties
var itemData = {
'book': {
value: 2,
asset: 'book'
},
'money': {
value: 4,
asset: 'money'
},
'movie': {
value: 6,
asset: 'movie'
},
'phone': {
value: 8,
asset: 'phone'
},
'laptop': {
value: 10,
asset: 'laptop'
},
'tablet': {
value: 12,
asset: 'tablet'
},
'headphones': {
value: 14,
asset: 'headphones'
},
'ticket': {
value: 16,
asset: 'ticket'
},
'soda': {
value: 18,
asset: 'soda'
},
'goldCircle': {
value: 180,
asset: 'goldCircle'
},
'maroonCircle': {
value: 0.01,
asset: 'maroonCircle'
},
'magentaCircle': {
value: 0.03,
asset: 'magentaCircle'
},
'grayCircle': {
value: 0.05,
asset: 'grayCircle'
},
'blackCircle': {
value: 0.09,
asset: 'blackCircle'
}
};
self.value = itemData[itemType].value;
var itemGraphics = self.attachAsset(itemData[itemType].asset, {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
return self;
});
var SettingsButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('settingsButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2('SET', {
size: 30,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
// Cycle through timer options: 5, 10, 15, 20, 25, 30, 35 minutes
var currentTimer = storage.gameTimer || 300; // Default 5 minutes
var timerOptions = [300, 600, 900, 1200, 1500, 1800, 2100]; // In seconds
var currentIndex = timerOptions.indexOf(currentTimer);
var nextIndex = (currentIndex + 1) % timerOptions.length;
var newTimer = timerOptions[nextIndex];
storage.gameTimer = newTimer;
gameTimer = newTimer;
timeRemaining = newTimer;
updateTimerDisplay();
};
return self;
});
/****
* Initialize Game
****/
// Game variables
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Sound effects
// Player character
// Small colored circles for cents
// Special golden circle
// Initialize all falling item assets with different colors
// Game variables
var player;
var fallingItems = [];
var totalMoney = 0;
var inventory = {
books: 0,
money: 0,
movies: 0,
phones: 0,
laptops: 0,
tablets: 0,
headphones: 0,
tickets: 0,
sodas: 0,
goldCircles: 0
};
// Timer variables
var gameTimer = storage.gameTimer || 300; // Default 5 minutes in seconds
var timeRemaining = gameTimer;
var gameStarted = false;
// Item spawn types and probabilities
var itemTypes = ['book', 'money', 'movie', 'phone', 'laptop', 'tablet', 'headphones', 'ticket', 'soda'];
var centTypes = ['maroonCircle', 'magentaCircle', 'grayCircle', 'blackCircle'];
// Create player
player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2500;
// Create UI elements
var moneyText = new Text2('$0.00', {
size: 80,
fill: 0x00FF00
});
moneyText.anchor.set(1, 0);
LK.gui.topRight.addChild(moneyText);
var timerText = new Text2('5:00', {
size: 60,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
var settingsButton = game.addChild(new SettingsButton());
settingsButton.x = 250;
settingsButton.y = 150;
function updateTimerDisplay() {
var minutes = Math.floor(timeRemaining / 60);
var seconds = timeRemaining % 60;
var timeString = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
timerText.setText(timeString);
}
function showGameOverWithInventory() {
var finalInventory = 'Final Collection:\n';
finalInventory += 'Books: ' + inventory.books + '\n';
finalInventory += 'Money: ' + inventory.money + '\n';
finalInventory += 'Movies: ' + inventory.movies + '\n';
finalInventory += 'Phones: ' + inventory.phones + '\n';
finalInventory += 'Laptops: ' + inventory.laptops + '\n';
finalInventory += 'Tablets: ' + inventory.tablets + '\n';
finalInventory += 'Headphones: ' + inventory.headphones + '\n';
finalInventory += 'Tickets: ' + inventory.tickets + '\n';
finalInventory += 'Sodas: ' + inventory.sodas + '\n';
if (inventory.goldCircles > 0) {
finalInventory += 'Gold Circles: ' + inventory.goldCircles + '\n';
}
finalInventory += '\nTotal Money: $' + totalMoney.toFixed(2);
console.log(finalInventory);
LK.showGameOver();
}
// Touch/mouse controls for player movement
var isMoving = false;
var targetX = 0;
game.move = function (x, y, obj) {
if (isMoving) {
targetX = x;
player.x = Math.max(50, Math.min(1998, targetX));
}
};
game.down = function (x, y, obj) {
isMoving = true;
targetX = x;
player.x = Math.max(50, Math.min(1998, targetX));
};
game.up = function (x, y, obj) {
isMoving = false;
};
// Spawn falling items
var spawnTimer = 0;
var spawnRate = 60; // Spawn every 60 ticks initially
function spawnItem() {
var itemType;
var rand = Math.random();
if (rand < 0.02) {
// 2% chance for gold circle
itemType = 'goldCircle';
} else if (rand < 0.15) {
// 13% chance for cent circles
itemType = centTypes[Math.floor(Math.random() * centTypes.length)];
} else {
// Regular items
itemType = itemTypes[Math.floor(Math.random() * itemTypes.length)];
}
var item = new FallingItem(itemType);
item.x = Math.random() * 1948 + 50; // Random X position with margins
item.y = -100;
item.lastY = item.y;
item.lastIntersecting = false;
fallingItems.push(item);
game.addChild(item);
}
game.update = function () {
// Start game on first item collection or movement
if (!gameStarted && (isMoving || fallingItems.length > 0)) {
gameStarted = true;
// Start background music when game begins
LK.playMusic('Uploaded', {
loop: true
});
}
// Update timer only when game has started
if (gameStarted) {
if (LK.ticks % 60 === 0 && timeRemaining > 0) {
// Update every second
timeRemaining--;
updateTimerDisplay();
if (timeRemaining <= 0) {
showGameOverWithInventory();
return;
}
}
}
// Spawn items
spawnTimer++;
if (spawnTimer >= spawnRate) {
spawnItem();
spawnTimer = 0;
// Gradually increase spawn rate
if (spawnRate > 20) {
spawnRate--;
}
}
// Update falling items
for (var i = fallingItems.length - 1; i >= 0; i--) {
var item = fallingItems[i];
// Check if item went off screen
if (item.lastY < 2800 && item.y >= 2800) {
item.destroy();
fallingItems.splice(i, 1);
continue;
}
// Check collision with player
var currentIntersecting = item.intersects(player);
if (!item.lastIntersecting && currentIntersecting) {
// Item collected!
var itemValue = item.value;
// Update inventory and money
if (item.itemType === 'book') inventory.books++;else if (item.itemType === 'money') inventory.money++;else if (item.itemType === 'movie') inventory.movies++;else if (item.itemType === 'phone') inventory.phones++;else if (item.itemType === 'laptop') inventory.laptops++;else if (item.itemType === 'tablet') inventory.tablets++;else if (item.itemType === 'headphones') inventory.headphones++;else if (item.itemType === 'ticket') inventory.tickets++;else if (item.itemType === 'soda') inventory.sodas++;else if (item.itemType === 'goldCircle') {
inventory.goldCircles++;
LK.getSound('special').play();
}
// Add value to total money
totalMoney += itemValue;
// Update displays
moneyText.setText('$' + totalMoney.toFixed(2));
// Play collect sound (except for gold which has its own)
if (item.itemType !== 'goldCircle') {
LK.getSound('collect').play();
}
// Flash effect for collection
LK.effects.flashObject(player, 0x00FF00, 200);
// Remove item
item.destroy();
fallingItems.splice(i, 1);
continue;
}
// Update last states
item.lastY = item.y;
item.lastIntersecting = currentIntersecting;
}
};