/**** * Classes ****/ // Create BackgroundContainer class var BackgroundContainer = Container.expand(function () { var self = Container.call(this); return self; }); // Create DigestionSystem class var DigestionSystem = Container.expand(function () { var self = Container.call(this); self.units = []; self.maxUnits = 10; self.unitWidth = 100; self.unitHeight = 100; self.unitSpacing = 50; self.unitFullAlpha = 1; self.unitEmptyAlpha = 0.5; // Initialize with 10 empty units for (var i = 0; i < self.maxUnits; i++) { var unit = self.attachAsset('Unit', { anchorX: 0.5, anchorY: 0.5, x: i * (self.unitWidth + self.unitSpacing), alpha: self.unitEmptyAlpha }); self.units.push(unit); } // Add text display for points under each unit self.unitTexts = []; for (var i = 0; i < self.maxUnits; i++) { var unitText = new Text2('', { size: 60, fill: "#ffffff", stroke: "#000000", strokeThickness: 10 }); unitText.anchor.set(0.5, 0.5); unitText.x = i * (self.unitWidth + self.unitSpacing); unitText.y = +100; self.addChild(unitText); self.unitTexts.push(unitText); } return self; }); // Create Food class var Food = Container.expand(function (assetId, points) { var self = Container.call(this); // Attach Food asset to the food self.foodAsset = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); // Set food speed self.speed = -3; // Points awarded by this food item self.points = points; // This is automatically called every game tick, if the food is attached! self.update = function () { self.speed -= 0.3 + foodAccelerationIncrement; // acceleration with increment self.x += self.speed; }; return self; }); // Create ForegroundContainer class var ForegroundContainer = Container.expand(function () { var self = Container.call(this); return self; }); // Create MidgroundContainer class var MidgroundContainer = Container.expand(function () { var self = Container.call(this); return self; }); // Create Player class var Player = Container.expand(function () { var self = Container.call(this); // Attach Player_Up asset to the player self.playerUp = self.attachAsset('Player_Up', { anchorX: 0.5, anchorY: 1.0, scaleX: 1.5, scaleY: 1.5 }); // Attach Player_Down asset to the player self.playerDown = self.attachAsset('Player_Down', { anchorX: 0.5, anchorY: 1.0, x: -120, scaleX: 1.5, scaleY: 1.5 }); // Initially, Player_Down is not visible self.playerDown.visible = false; // Method to switch between Player_Up and Player_Down self.switchFrame = function () { self.playerUp.visible = !self.playerUp.visible; self.playerDown.visible = !self.playerDown.visible; if (self.playerDown.visible) { LK.getSound('Pooping').play(); // Store the number of filled units when transitioning to the down state filledUnits = digestionSystem.units.filter(function (unit) { return unit.alpha === digestionSystem.unitFullAlpha; }).length; } else { LK.getSound('Flush').play(); // Decrease the score for each remaining unit when the player prematurely moves back up var remainingUnits = digestionSystem.units.filter(function (unit) { return unit.alpha === digestionSystem.unitFullAlpha; }).length; score -= remainingUnits * filledUnits; scoreTxt.setText(score); if (score <= 0) { LK.showGameOver(); return; } else { // Only display UI_Crappy asset if there are still filled units if (remainingUnits > 0) { // Display UI_Crappy asset in the center of the screen var uiCrappy = foregroundContainer.attachAsset('UI_Crappy', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 - 700 }); foregroundContainer.addChild(uiCrappy); // Set a timeout to remove the UI_Crappy asset after 1 second LK.setTimeout(function () { foregroundContainer.removeChild(uiCrappy); }, 2000); } } // Display the appropriate UI element based on the number of units collected if (filledUnits > 0 && digestionSystem.units.every(function (unit) { return unit.alpha === digestionSystem.unitEmptyAlpha; })) { uiElementDisplay.displayUIElement(filledUnits); filledUnits = 0; // Reset filledUnits to ensure UI elements are shown only once } filledUnits = digestionSystem.units.filter(function (unit) { return unit.alpha === digestionSystem.unitFullAlpha; }).length; // Update points display under each unit digestionSystem.units.forEach(function (unit, index) { if (unit.alpha === digestionSystem.unitFullAlpha) { digestionSystem.unitTexts[index].setText(filledUnits); } else { digestionSystem.unitTexts[index].setText(''); } }); digestionSystem.units.forEach(function (unit, index) { unit.alpha = digestionSystem.unitEmptyAlpha; digestionSystem.unitTexts[index].setText(''); // Clear points display under each unit }); filledUnits = 0; LK.getSound('Pooping').stop(); foodAccelerationIncrement += 0.1; // Increase the acceleration increment for food items foodSpawnTimeDecrement += 1; // Decrease the spawn time for food items } }; // Method to check if the player collides with a food object self.checkCollision = function (food) { // Only player_up can collect food if (self.playerUp.visible) { var playerBounds = self.playerUp.getBounds(); if (food) { var foodBounds = food.getBounds(); var foodCenter = { x: foodBounds.x + foodBounds.width / 2, y: foodBounds.y + foodBounds.height / 2 }; } var playerCenter = { x: playerBounds.x + playerBounds.width / 2, y: playerBounds.y + playerBounds.height / 2 }; // Check if the center of the food is within the bounds of the player if (foodCenter && playerBounds.contains(foodCenter.x, foodCenter.y)) { // Do not add a unit to the Digestion System here return true; } if (food) { var foodBounds = food.getBounds(); var foodCenter = { x: foodBounds.x + foodBounds.width / 2, y: foodBounds.y + foodBounds.height / 2 }; if (playerBounds.contains(foodCenter.x, foodCenter.y)) { return true; } if (food && food.foodAsset && food.foodAsset.getBounds) { var foodAssetBounds = food.foodAsset.getBounds(); var foodAssetCenter = { x: foodAssetBounds.x + foodAssetBounds.width / 2, y: foodAssetBounds.y + foodAssetBounds.height / 2 }; if (playerBounds.contains(foodAssetCenter.x, foodAssetCenter.y)) { return true; } } } return false; } return false; }; return self; }); // Create UIElementDisplay class var UIElementDisplay = Container.expand(function () { var self = Container.call(this); self.displayUIElement = function (unitsCollected) { var uiElementId; if (unitsCollected >= 1 && unitsCollected <= 3) { uiElementId = 'UI_1'; } else if (unitsCollected >= 4 && unitsCollected <= 6) { uiElementId = 'UI_2'; } else if (unitsCollected >= 7 && unitsCollected <= 8) { uiElementId = 'UI_3'; } else if (unitsCollected === 9) { uiElementId = 'UI_4'; } else if (unitsCollected === 10) { uiElementId = 'UI_5'; } if (uiElementId) { LK.getSound('Splash').play(); var uiElement = foregroundContainer.attachAsset(uiElementId, { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 - 700 }); foregroundContainer.addChild(uiElement); // Animate the UI element to grow to its original size in less than a second uiElement.scale.set(0.01, 0.01); var growInterval = LK.setInterval(function () { uiElement.scale.x += 0.1; uiElement.scale.y += 0.1; if (uiElement.scale.x >= 1 && uiElement.scale.y >= 1) { LK.clearInterval(growInterval); } }, 10); // Set a timeout to remove the UI element after 1 second LK.setTimeout(function () { foregroundContainer.removeChild(uiElement); }, 2000); } }; return self; }); /**** * Initialize Game ****/ //<Assets used in the game will automatically appear here> var game = new LK.Game({ backgroundColor: 0xfdfff4 // Init game with white background }); /**** * Game Code ****/ // Initialize the UIElementDisplay class var uiElementDisplay = new UIElementDisplay(); // Play background music LK.playMusic('background_music'); var backgroundContainer = game.addChild(new BackgroundContainer()); var background = backgroundContainer.attachAsset('background', { anchorX: 0.5, anchorY: 1.0, x: 2048 / 2, y: 2732 }); var midgroundContainer = game.addChild(new MidgroundContainer()); var foregroundContainer = game.addChild(new ForegroundContainer()); // Add the Digestion System to the game var digestionSystem = game.addChild(new DigestionSystem()); digestionSystem.x = 2048 / 2 - 180 - digestionSystem.unitWidth * digestionSystem.maxUnits / 2; digestionSystem.y = 100; var score = 0; var scoreTxt; var filledUnits = 0; var foodSpawnTimeDecrement = 0; // Global variable to track spawn time decrement for food items var foodAccelerationIncrement = 0; // Global variable to track acceleration increment for food items var filledUnits = 0; scoreTxt = new Text2('0', { size: 150, fill: "#ffffff", stroke: "#000000", strokeThickness: 15 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); scoreTxt.x -= 10; // Move the score 10 pixels to the left scoreTxt.y += 920; // Add the Player in the center of the screen var player = midgroundContainer.addChild(new Player()); player.x = 2048 / 2 - 500; player.y = 2732 + 30; // Switch the player's frame on tap game.down = function (x, y, obj) { if (!game.isGameOver) { player.switchFrame(); } }; // Spawn food from the right edge of the screen at y position of 500 game.update = function () { if (LK.ticks == 0) { score = 0; scoreTxt.setText(score); filledUnits = 0; // Reset the Digestion System digestionSystem.units.forEach(function (unit) { unit.alpha = digestionSystem.unitEmptyAlpha; }); // Clear points display under each unit digestionSystem.unitTexts.forEach(function (unitText) { unitText.setText(''); }); } if (LK.ticks % (60 - foodSpawnTimeDecrement) == 0 && !game.isGameOver) { // every second var foodBucket = []; for (var i = 0; i < 100; i++) { foodBucket.push(new Food('Food', 1)); } for (var i = 0; i < 40; i++) { foodBucket.push(new Food('Food_2', 3)); } for (var i = 0; i < 10; i++) { foodBucket.push(new Food('Food_3', 5)); } var newFood = foodBucket[Math.floor(Math.random() * foodBucket.length)]; newFood.x = 2048; // right edge of the screen newFood.y = 1900; foregroundContainer.addChild(newFood); } // Check for collision between the player and the food // Remove a unit from the Digestion System when the player is in the Down state if (!player.playerUp.visible) { if (LK.ticks % 20 == 0) { var fullUnits = digestionSystem.units.filter(function (unit) { return unit.alpha === digestionSystem.unitFullAlpha; }); if (fullUnits.length > 0) { fullUnits[fullUnits.length - 1].alpha = digestionSystem.unitEmptyAlpha; score += filledUnits; // Add points based on the fixed number of filled units // Update points display under each unit digestionSystem.units.forEach(function (unit, index) { if (unit.alpha === digestionSystem.unitFullAlpha) { digestionSystem.unitTexts[index].setText(filledUnits); } else { digestionSystem.unitTexts[index].setText(''); } }); scoreTxt.setText(score); if (score <= 0) { LK.showGameOver(); return; } // Display the appropriate UI element based on the number of units collected only once if (filledUnits > 0 && digestionSystem.units.every(function (unit) { return unit.alpha === digestionSystem.unitEmptyAlpha; })) { uiElementDisplay.displayUIElement(filledUnits); filledUnits = 0; // Reset filledUnits to ensure UI elements are shown only once } } else { LK.getSound('Pooping').stop(); } } } else { LK.getSound('Pooping').stop(); } for (var i = foregroundContainer.children.length - 1; i >= 0; i--) { var food = foregroundContainer.children[i]; if (food && food.x <= 0 && !game.isGameOver) { // Only decrease the score if the digestive system unit is 0 var fullUnits = digestionSystem.units.filter(function (unit) { return unit.alpha === digestionSystem.unitFullAlpha; }).length; if (fullUnits === 0) { // Decrease the score based on the points the food was supposed to increase score -= food.points; scoreTxt.setText(score); if (score <= 0) { LK.showGameOver(); return; } } food.destroy(); } else if (food && (player.checkCollision(food) || player.checkCollision(food.foodAsset))) { // Increment the score score += food.points; // Add units to the Digestion System based on the points of the food for (var i = 0; i < food.points; i++) { var fullUnits = digestionSystem.units.filter(function (unit) { return unit.alpha === digestionSystem.unitFullAlpha; }); if (fullUnits.length < digestionSystem.maxUnits) { digestionSystem.units[fullUnits.length].alpha = digestionSystem.unitFullAlpha; filledUnits = fullUnits.length + 1; // Update filledUnits } else { // Display Game_Over asset var gameOverAsset = foregroundContainer.attachAsset('Game_Over', { anchorX: 0.5, anchorY: 1.0, x: 2048 / 2, y: 2732 }); foregroundContainer.addChild(gameOverAsset); // Display Game_Over asset 300 pixels above the center of the screen var bustedAsset = foregroundContainer.attachAsset('Busted', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 - 1000 }); foregroundContainer.addChild(bustedAsset); // Play the Game_Over sound LK.getSound('Game_Over').play(); // Remove all other visual assets midgroundContainer.removeChildren(); backgroundContainer.removeChildren(); digestionSystem.removeChildren(); scoreTxt.visible = false; game.isGameOver = true; game.down = function () {}; // Change the background color to edf5f9 during the game over screen state game.setBackgroundColor(0xedf5f9); // Set a timeout to show the Game_Over asset for 1.5 seconds before going to the actual game over state LK.setTimeout(function () { LK.showGameOver(); }, 1500); return; } } // Update points display under each unit digestionSystem.units.forEach(function (unit, index) { if (unit.alpha === digestionSystem.unitFullAlpha) { digestionSystem.unitTexts[index].setText(filledUnits); } else { digestionSystem.unitTexts[index].setText(''); } }); scoreTxt.setText(score); // Play a random Eat sound var eatSounds = ['Eat', 'Eat_2', 'Eat_3']; var randomEatSound = eatSounds[Math.floor(Math.random() * eatSounds.length)]; LK.getSound(randomEatSound).play(); // Remove the food from the game food.destroy(); } } };
/****
* Classes
****/
// Create BackgroundContainer class
var BackgroundContainer = Container.expand(function () {
var self = Container.call(this);
return self;
});
// Create DigestionSystem class
var DigestionSystem = Container.expand(function () {
var self = Container.call(this);
self.units = [];
self.maxUnits = 10;
self.unitWidth = 100;
self.unitHeight = 100;
self.unitSpacing = 50;
self.unitFullAlpha = 1;
self.unitEmptyAlpha = 0.5;
// Initialize with 10 empty units
for (var i = 0; i < self.maxUnits; i++) {
var unit = self.attachAsset('Unit', {
anchorX: 0.5,
anchorY: 0.5,
x: i * (self.unitWidth + self.unitSpacing),
alpha: self.unitEmptyAlpha
});
self.units.push(unit);
}
// Add text display for points under each unit
self.unitTexts = [];
for (var i = 0; i < self.maxUnits; i++) {
var unitText = new Text2('', {
size: 60,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 10
});
unitText.anchor.set(0.5, 0.5);
unitText.x = i * (self.unitWidth + self.unitSpacing);
unitText.y = +100;
self.addChild(unitText);
self.unitTexts.push(unitText);
}
return self;
});
// Create Food class
var Food = Container.expand(function (assetId, points) {
var self = Container.call(this);
// Attach Food asset to the food
self.foodAsset = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
// Set food speed
self.speed = -3;
// Points awarded by this food item
self.points = points;
// This is automatically called every game tick, if the food is attached!
self.update = function () {
self.speed -= 0.3 + foodAccelerationIncrement; // acceleration with increment
self.x += self.speed;
};
return self;
});
// Create ForegroundContainer class
var ForegroundContainer = Container.expand(function () {
var self = Container.call(this);
return self;
});
// Create MidgroundContainer class
var MidgroundContainer = Container.expand(function () {
var self = Container.call(this);
return self;
});
// Create Player class
var Player = Container.expand(function () {
var self = Container.call(this);
// Attach Player_Up asset to the player
self.playerUp = self.attachAsset('Player_Up', {
anchorX: 0.5,
anchorY: 1.0,
scaleX: 1.5,
scaleY: 1.5
});
// Attach Player_Down asset to the player
self.playerDown = self.attachAsset('Player_Down', {
anchorX: 0.5,
anchorY: 1.0,
x: -120,
scaleX: 1.5,
scaleY: 1.5
});
// Initially, Player_Down is not visible
self.playerDown.visible = false;
// Method to switch between Player_Up and Player_Down
self.switchFrame = function () {
self.playerUp.visible = !self.playerUp.visible;
self.playerDown.visible = !self.playerDown.visible;
if (self.playerDown.visible) {
LK.getSound('Pooping').play();
// Store the number of filled units when transitioning to the down state
filledUnits = digestionSystem.units.filter(function (unit) {
return unit.alpha === digestionSystem.unitFullAlpha;
}).length;
} else {
LK.getSound('Flush').play();
// Decrease the score for each remaining unit when the player prematurely moves back up
var remainingUnits = digestionSystem.units.filter(function (unit) {
return unit.alpha === digestionSystem.unitFullAlpha;
}).length;
score -= remainingUnits * filledUnits;
scoreTxt.setText(score);
if (score <= 0) {
LK.showGameOver();
return;
} else {
// Only display UI_Crappy asset if there are still filled units
if (remainingUnits > 0) {
// Display UI_Crappy asset in the center of the screen
var uiCrappy = foregroundContainer.attachAsset('UI_Crappy', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2 - 700
});
foregroundContainer.addChild(uiCrappy);
// Set a timeout to remove the UI_Crappy asset after 1 second
LK.setTimeout(function () {
foregroundContainer.removeChild(uiCrappy);
}, 2000);
}
}
// Display the appropriate UI element based on the number of units collected
if (filledUnits > 0 && digestionSystem.units.every(function (unit) {
return unit.alpha === digestionSystem.unitEmptyAlpha;
})) {
uiElementDisplay.displayUIElement(filledUnits);
filledUnits = 0; // Reset filledUnits to ensure UI elements are shown only once
}
filledUnits = digestionSystem.units.filter(function (unit) {
return unit.alpha === digestionSystem.unitFullAlpha;
}).length;
// Update points display under each unit
digestionSystem.units.forEach(function (unit, index) {
if (unit.alpha === digestionSystem.unitFullAlpha) {
digestionSystem.unitTexts[index].setText(filledUnits);
} else {
digestionSystem.unitTexts[index].setText('');
}
});
digestionSystem.units.forEach(function (unit, index) {
unit.alpha = digestionSystem.unitEmptyAlpha;
digestionSystem.unitTexts[index].setText(''); // Clear points display under each unit
});
filledUnits = 0;
LK.getSound('Pooping').stop();
foodAccelerationIncrement += 0.1; // Increase the acceleration increment for food items
foodSpawnTimeDecrement += 1; // Decrease the spawn time for food items
}
};
// Method to check if the player collides with a food object
self.checkCollision = function (food) {
// Only player_up can collect food
if (self.playerUp.visible) {
var playerBounds = self.playerUp.getBounds();
if (food) {
var foodBounds = food.getBounds();
var foodCenter = {
x: foodBounds.x + foodBounds.width / 2,
y: foodBounds.y + foodBounds.height / 2
};
}
var playerCenter = {
x: playerBounds.x + playerBounds.width / 2,
y: playerBounds.y + playerBounds.height / 2
};
// Check if the center of the food is within the bounds of the player
if (foodCenter && playerBounds.contains(foodCenter.x, foodCenter.y)) {
// Do not add a unit to the Digestion System here
return true;
}
if (food) {
var foodBounds = food.getBounds();
var foodCenter = {
x: foodBounds.x + foodBounds.width / 2,
y: foodBounds.y + foodBounds.height / 2
};
if (playerBounds.contains(foodCenter.x, foodCenter.y)) {
return true;
}
if (food && food.foodAsset && food.foodAsset.getBounds) {
var foodAssetBounds = food.foodAsset.getBounds();
var foodAssetCenter = {
x: foodAssetBounds.x + foodAssetBounds.width / 2,
y: foodAssetBounds.y + foodAssetBounds.height / 2
};
if (playerBounds.contains(foodAssetCenter.x, foodAssetCenter.y)) {
return true;
}
}
}
return false;
}
return false;
};
return self;
});
// Create UIElementDisplay class
var UIElementDisplay = Container.expand(function () {
var self = Container.call(this);
self.displayUIElement = function (unitsCollected) {
var uiElementId;
if (unitsCollected >= 1 && unitsCollected <= 3) {
uiElementId = 'UI_1';
} else if (unitsCollected >= 4 && unitsCollected <= 6) {
uiElementId = 'UI_2';
} else if (unitsCollected >= 7 && unitsCollected <= 8) {
uiElementId = 'UI_3';
} else if (unitsCollected === 9) {
uiElementId = 'UI_4';
} else if (unitsCollected === 10) {
uiElementId = 'UI_5';
}
if (uiElementId) {
LK.getSound('Splash').play();
var uiElement = foregroundContainer.attachAsset(uiElementId, {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2 - 700
});
foregroundContainer.addChild(uiElement);
// Animate the UI element to grow to its original size in less than a second
uiElement.scale.set(0.01, 0.01);
var growInterval = LK.setInterval(function () {
uiElement.scale.x += 0.1;
uiElement.scale.y += 0.1;
if (uiElement.scale.x >= 1 && uiElement.scale.y >= 1) {
LK.clearInterval(growInterval);
}
}, 10);
// Set a timeout to remove the UI element after 1 second
LK.setTimeout(function () {
foregroundContainer.removeChild(uiElement);
}, 2000);
}
};
return self;
});
/****
* Initialize Game
****/
//<Assets used in the game will automatically appear here>
var game = new LK.Game({
backgroundColor: 0xfdfff4 // Init game with white background
});
/****
* Game Code
****/
// Initialize the UIElementDisplay class
var uiElementDisplay = new UIElementDisplay();
// Play background music
LK.playMusic('background_music');
var backgroundContainer = game.addChild(new BackgroundContainer());
var background = backgroundContainer.attachAsset('background', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
var midgroundContainer = game.addChild(new MidgroundContainer());
var foregroundContainer = game.addChild(new ForegroundContainer());
// Add the Digestion System to the game
var digestionSystem = game.addChild(new DigestionSystem());
digestionSystem.x = 2048 / 2 - 180 - digestionSystem.unitWidth * digestionSystem.maxUnits / 2;
digestionSystem.y = 100;
var score = 0;
var scoreTxt;
var filledUnits = 0;
var foodSpawnTimeDecrement = 0; // Global variable to track spawn time decrement for food items
var foodAccelerationIncrement = 0; // Global variable to track acceleration increment for food items
var filledUnits = 0;
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 15
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.x -= 10; // Move the score 10 pixels to the left
scoreTxt.y += 920;
// Add the Player in the center of the screen
var player = midgroundContainer.addChild(new Player());
player.x = 2048 / 2 - 500;
player.y = 2732 + 30;
// Switch the player's frame on tap
game.down = function (x, y, obj) {
if (!game.isGameOver) {
player.switchFrame();
}
};
// Spawn food from the right edge of the screen at y position of 500
game.update = function () {
if (LK.ticks == 0) {
score = 0;
scoreTxt.setText(score);
filledUnits = 0;
// Reset the Digestion System
digestionSystem.units.forEach(function (unit) {
unit.alpha = digestionSystem.unitEmptyAlpha;
});
// Clear points display under each unit
digestionSystem.unitTexts.forEach(function (unitText) {
unitText.setText('');
});
}
if (LK.ticks % (60 - foodSpawnTimeDecrement) == 0 && !game.isGameOver) {
// every second
var foodBucket = [];
for (var i = 0; i < 100; i++) {
foodBucket.push(new Food('Food', 1));
}
for (var i = 0; i < 40; i++) {
foodBucket.push(new Food('Food_2', 3));
}
for (var i = 0; i < 10; i++) {
foodBucket.push(new Food('Food_3', 5));
}
var newFood = foodBucket[Math.floor(Math.random() * foodBucket.length)];
newFood.x = 2048; // right edge of the screen
newFood.y = 1900;
foregroundContainer.addChild(newFood);
}
// Check for collision between the player and the food
// Remove a unit from the Digestion System when the player is in the Down state
if (!player.playerUp.visible) {
if (LK.ticks % 20 == 0) {
var fullUnits = digestionSystem.units.filter(function (unit) {
return unit.alpha === digestionSystem.unitFullAlpha;
});
if (fullUnits.length > 0) {
fullUnits[fullUnits.length - 1].alpha = digestionSystem.unitEmptyAlpha;
score += filledUnits; // Add points based on the fixed number of filled units
// Update points display under each unit
digestionSystem.units.forEach(function (unit, index) {
if (unit.alpha === digestionSystem.unitFullAlpha) {
digestionSystem.unitTexts[index].setText(filledUnits);
} else {
digestionSystem.unitTexts[index].setText('');
}
});
scoreTxt.setText(score);
if (score <= 0) {
LK.showGameOver();
return;
}
// Display the appropriate UI element based on the number of units collected only once
if (filledUnits > 0 && digestionSystem.units.every(function (unit) {
return unit.alpha === digestionSystem.unitEmptyAlpha;
})) {
uiElementDisplay.displayUIElement(filledUnits);
filledUnits = 0; // Reset filledUnits to ensure UI elements are shown only once
}
} else {
LK.getSound('Pooping').stop();
}
}
} else {
LK.getSound('Pooping').stop();
}
for (var i = foregroundContainer.children.length - 1; i >= 0; i--) {
var food = foregroundContainer.children[i];
if (food && food.x <= 0 && !game.isGameOver) {
// Only decrease the score if the digestive system unit is 0
var fullUnits = digestionSystem.units.filter(function (unit) {
return unit.alpha === digestionSystem.unitFullAlpha;
}).length;
if (fullUnits === 0) {
// Decrease the score based on the points the food was supposed to increase
score -= food.points;
scoreTxt.setText(score);
if (score <= 0) {
LK.showGameOver();
return;
}
}
food.destroy();
} else if (food && (player.checkCollision(food) || player.checkCollision(food.foodAsset))) {
// Increment the score
score += food.points;
// Add units to the Digestion System based on the points of the food
for (var i = 0; i < food.points; i++) {
var fullUnits = digestionSystem.units.filter(function (unit) {
return unit.alpha === digestionSystem.unitFullAlpha;
});
if (fullUnits.length < digestionSystem.maxUnits) {
digestionSystem.units[fullUnits.length].alpha = digestionSystem.unitFullAlpha;
filledUnits = fullUnits.length + 1; // Update filledUnits
} else {
// Display Game_Over asset
var gameOverAsset = foregroundContainer.attachAsset('Game_Over', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
foregroundContainer.addChild(gameOverAsset);
// Display Game_Over asset 300 pixels above the center of the screen
var bustedAsset = foregroundContainer.attachAsset('Busted', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2 - 1000
});
foregroundContainer.addChild(bustedAsset);
// Play the Game_Over sound
LK.getSound('Game_Over').play();
// Remove all other visual assets
midgroundContainer.removeChildren();
backgroundContainer.removeChildren();
digestionSystem.removeChildren();
scoreTxt.visible = false;
game.isGameOver = true;
game.down = function () {};
// Change the background color to edf5f9 during the game over screen state
game.setBackgroundColor(0xedf5f9);
// Set a timeout to show the Game_Over asset for 1.5 seconds before going to the actual game over state
LK.setTimeout(function () {
LK.showGameOver();
}, 1500);
return;
}
}
// Update points display under each unit
digestionSystem.units.forEach(function (unit, index) {
if (unit.alpha === digestionSystem.unitFullAlpha) {
digestionSystem.unitTexts[index].setText(filledUnits);
} else {
digestionSystem.unitTexts[index].setText('');
}
});
scoreTxt.setText(score);
// Play a random Eat sound
var eatSounds = ['Eat', 'Eat_2', 'Eat_3'];
var randomEatSound = eatSounds[Math.floor(Math.random() * eatSounds.length)];
LK.getSound(randomEatSound).play();
// Remove the food from the game
food.destroy();
}
}
};
hamburger. pixelated. 8-bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
poop UI element . pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
text saying "Constipated" against a poop banner. pixelated. 8-bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
text saying "You’re on a roll!" against a toilet paper banner. pixelated. 8-bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
text saying "Holy Crap!" against a divine angelic poop banner. pixelated. 8-bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixelated text saying "Shit Yeah!" as a shitty newspaper headline. pixelated. 8-bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
macdonalds fries but with the M letter rotated so it looks like a 3. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
large KFC bucket with the digit 5 on it. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pixelated image of a video game character sitting with hands on a large belly, wearing a white shirt and brown pants. The setting is a simple bathroom, with the character as the main focus. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.