Code edit (1 edits merged)
Please save this source code
User prompt
Why isnโt comic sans working?
Code edit (3 edits merged)
Please save this source code
User prompt
Change bubble text to comic sans
Code edit (2 edits merged)
Please save this source code
User prompt
Remove text labels from containers
Code edit (1 edits merged)
Please save this source code
User prompt
Change the container label text font to impact
Code edit (1 edits merged)
Please save this source code
User prompt
Give container label text a black background
Code edit (21 edits merged)
Please save this source code
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.containerPositions[i]')' in or related to this line: 'container.y = self.containerPositions[i].y;' Line Number: 142
Code edit (1 edits merged)
Please save this source code
User prompt
Adjust x positions of containers to ensure a 40px space between each container
Code edit (1 edits merged)
Please save this source code
User prompt
Set leveltxt to scale 100 at start of game
User prompt
Set leveltxt to scale 1 at start of game
User prompt
Why does level text vanish when leveling up
User prompt
Prevent ships from spawning in a lane thatโs already occupied
User prompt
When spawning a ship, pick a random position from possible y positions
User prompt
Spawn ships more often
User prompt
Spawn ships more often
Code edit (4 edits merged)
Please save this source code
User prompt
Up to 4 ships can be on screen at a time with different y coordinates
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0, lastScore: 0 }); /**** * Classes ****/ var ShippingContainer = Container.expand(function (type) { var self = Container.call(this); // Set container type and properties self.type = type || 'container'; self.targetted = false; self.speed = 3 + Math.random() * 2; self.value = 10; // Adjust value based on container type if (self.type === 'foodContainer') { self.value = 15; } else if (self.type === 'paperContainer') { self.value = 20; } else if (self.type === 'diaperContainer') { self.value = 25; } else if (self.type === 'carPartsContainer') { self.value = 30; } // Get and automatically addChild appropriate asset with anchor set var containerGraphics = self.attachAsset(self.type, { anchorX: 0.5, anchorY: 0.5 }); // Create label to show container type self.label = new Text2('', { size: 24, fill: 0xFFFFFF }); self.label.anchor.set(0.5, 0.5); // Set label text based on container type if (self.type === 'foodContainer') { self.label.setText("FOOD"); } else if (self.type === 'paperContainer') { self.label.setText("PAPER"); } else if (self.type === 'diaperContainer') { self.label.setText("DIAPERS"); } else if (self.type === 'carPartsContainer') { self.label.setText("CAR PARTS"); } else { self.label.setText("GOODS"); } self.addChild(self.label); // Tariff stamp that appears when tapped self.tariffStamp = self.attachAsset('tariffStamp', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); // Add text to stamp self.stampText = new Text2('TARIFF', { size: 30, fill: 0xFFFFFF }); self.stampText.anchor.set(0.5, 0.5); self.tariffStamp.addChild(self.stampText); // Update method called automatically each frame self.update = function () { // This method is now empty as container movement is controlled by the ship // Container position is relative to ship and doesn't need its own movement }; // Apply tariff to container self.applyTariff = function () { if (self.targetted) { return false; } self.targetted = true; // Show tariff stamp with animation self.tariffStamp.alpha = 1; self.tariffStamp.rotation = -0.3; tween(self.tariffStamp, { rotation: 0 }, { duration: 300, easing: tween.easeOut }); // Play slap sound LK.getSound('slap').play(); return true; }; // Tap/click handler self.down = function (x, y, obj) { // Call the global applyTariffToContainer function passing this container applyTariffToContainer(self); }; return self; }); var ShippingShip = Container.expand(function () { var self = Container.call(this); // Get and automatically addChild ship asset with anchor set var shipGraphics = self.attachAsset('ship', { anchorX: 0.5, anchorY: 0.5 }); // Add containers to the ship self.containers = []; self.containerPositions = [{ x: -350, y: -20 }, { x: -180, y: -20 }, { x: -10, y: -20 }, { x: 160, y: -20 }, { x: 330, y: -20 }]; // Create containers for the ship self.createContainers = function (level) { // Clear existing containers for (var i = 0; i < self.containers.length; i++) { if (self.containers[i]) { self.removeChild(self.containers[i]); } } self.containers = []; // Determine how many containers to create based on level var containerCount = Math.min(Math.floor(2 + level / 2), 5); // Randomly decide which container types to use var containerTypes = ['container', 'foodContainer', 'paperContainer', 'diaperContainer', 'carPartsContainer']; // Create and position containers for (var i = 0; i < containerCount; i++) { var randomType = containerTypes[Math.floor(Math.random() * containerTypes.length)]; var container = new ShippingContainer(randomType); // Set fixed positions relative to the ship container.x = self.containerPositions[i].x + 120; container.y = self.containerPositions[i].y; self.addChild(container); self.containers.push(container); } }; return self; }); var TrumpCharacter = Container.expand(function () { var self = Container.call(this); // Create Trump's face using shapes var face = self.attachAsset('trumpFace', { anchorX: 0.5, anchorY: 0.5 }); var hair = self.attachAsset('trumpHair', { anchorX: 0.5, anchorY: 0.5, y: -150 }); // Add speech bubble for occasional quotes self.speechBubble = new Container(); var bubbleText = new Text2('America First!', { size: 40, fill: 0x000000 }); bubbleText.anchor.set(0.5, 0.5); self.speechBubble.addChild(bubbleText); self.speechBubble.x = 200; self.speechBubble.y = -150; self.speechBubble.alpha = 0; self.addChild(self.speechBubble); // Method to show a random Trump quote self.showRandomQuote = function () { var quotes = ["America First!", "Huge Tariffs!", "The Best Tariffs!", "China!", "We're Winning!", "Tremendous!"]; bubbleText.setText(quotes[Math.floor(Math.random() * quotes.length)]); // Show speech bubble with animation tween(self.speechBubble, { alpha: 1 }, { duration: 300, easing: tween.easeOut }); // Hide speech bubble after delay LK.setTimeout(function () { tween(self.speechBubble, { alpha: 0 }, { duration: 300, easing: tween.easeIn }); }, 2000); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Game variables var score = 0; var level = 1; var combo = 0; var maxCombo = 0; var missedContainers = 0; var levelContainerCount = 0; var containersToNextLevel = 10; var isGameOver = false; var currentShip = null; var nextShipTimer = null; var ships = []; var trump = null; // Create UI elements var scoreTxt = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(scoreTxt); scoreTxt.x = -350; scoreTxt.y = 20; var levelTxt = new Text2('Level: 1', { size: 60, fill: 0xFFFFFF }); levelTxt.anchor.set(0, 0); LK.gui.top.addChild(levelTxt); levelTxt.y = 20; var comboTxt = new Text2('Combo: 0', { size: 40, fill: 0xFFFF00 }); comboTxt.anchor.set(0, 0); comboTxt.alpha = 0; LK.gui.topRight.addChild(comboTxt); comboTxt.x = -250; comboTxt.y = 90; // Initialize game function initGame() { // Reset game variables score = 0; level = 1; combo = 0; maxCombo = 0; missedContainers = 0; levelContainerCount = 0; containersToNextLevel = 10; isGameOver = false; ships = []; currentShip = null; if (nextShipTimer) { LK.clearTimeout(nextShipTimer); } nextShipTimer = null; // Update UI scoreTxt.setText('Score: 0'); levelTxt.setText('Level: 1'); comboTxt.setText('Combo: 0'); comboTxt.alpha = 0; // Create Trump character if (!trump) { trump = new TrumpCharacter(); trump.x = 300; trump.y = 400; game.addChild(trump); } // Start the game by spawning the first ship spawnNewShip(); // Play background music LK.playMusic('gameMusic'); } // Spawn a new shipping ship function spawnNewShip() { // Check if we already have 4 ships if (ships.length >= 4) { return; } // Create a new ship currentShip = new ShippingShip(); currentShip.x = 2048 + 600; // Start off-screen to the right // Assign different y coordinates for each ship // Simply pick a random position from possible positions var possibleYPositions = [700, 1000, 1700, 2400]; // Different y positions // Choose a random position from the available options var randomIndex = Math.floor(Math.random() * possibleYPositions.length); var yPosition = possibleYPositions[randomIndex]; currentShip.y = yPosition; // Create containers for the ship based on current level currentShip.createContainers(level); // Add ship to game and tracking array game.addChild(currentShip); ships.push(currentShip); } // Apply tariff to a container when tapped function applyTariffToContainer(container) { if (!isGameOver && container && !container.targetted) { if (container.applyTariff()) { // Increase score based on container value and combo var pointsGained = container.value * (1 + combo * 0.1); score += Math.floor(pointsGained); // Update score text scoreTxt.setText('Score: ' + score); // Increase combo combo++; if (combo > maxCombo) { maxCombo = combo; } // Show combo text if combo is greater than 1 if (combo > 1) { comboTxt.setText('Combo: ' + combo + 'x'); comboTxt.alpha = 1; // Animate combo text tween(comboTxt, { scale: 1.3 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(comboTxt, { scale: 1 }, { duration: 200, easing: tween.easeIn }); } }); } // Track containers for level progression levelContainerCount++; // Check if we should level up if (levelContainerCount >= containersToNextLevel) { levelUp(); } // Occasionally make Trump say something if (Math.random() < 0.2) { trump.showRandomQuote(); } } } } // Level up function function levelUp() { level++; levelContainerCount = 0; containersToNextLevel = 10 + level * 2; // Update level text levelTxt.setText('Level: ' + level); // Flash level text to indicate level up tween(levelTxt, { scale: 1.5 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { tween(levelTxt, { scale: 1 }, { duration: 300, easing: tween.easeIn }); } }); // Play level up sound LK.getSound('levelUp').play(); // Make Trump say something about the level up trump.showRandomQuote(); } // Game over function function endGame() { if (!isGameOver) { isGameOver = true; // Save high score if current score is higher if (score > storage.highScore) { storage.highScore = score; } // Save last score storage.lastScore = score; // Show game over screen LK.showGameOver(); } } // Check if all containers on a ship have tariffs function checkShipCompleted(ship) { if (!ship) { return false; } var allTariffed = true; for (var i = 0; i < ship.containers.length; i++) { if (!ship.containers[i].targetted) { allTariffed = false; break; } } return allTariffed; } // Game update function called every frame game.update = function () { // Skip if game is over if (isGameOver) { return; } // Update all ships for (var i = ships.length - 1; i >= 0; i--) { var ship = ships[i]; // Check if ship is completely off screen if (ship.x < -1000) { // Count missed containers for (var j = 0; j < ship.containers.length; j++) { if (!ship.containers[j].targetted) { missedContainers++; // Reset combo when containers are missed combo = 0; comboTxt.setText('Combo: 0'); comboTxt.alpha = 0; // Play miss sound LK.getSound('miss').play(); } } // Remove ship game.removeChild(ship); ships.splice(i, 1); // Check if game over (missed too many containers) if (missedContainers >= 10) { endGame(); return; } // Schedule next ship if we have fewer than 4 if (ship === currentShip) { currentShip = null; // Clear any existing timer if (nextShipTimer) { LK.clearTimeout(nextShipTimer); } nextShipTimer = LK.setTimeout(spawnNewShip, 200); // Reduced from 400ms to 200ms for even faster respawning } } // If ship is off-screen to the right, move it into view else if (ship.x > 2048) { ship.x -= 10; } // Normal ship movement else { ship.x -= 5 + level; // Check if ship is completed and speed it up if (checkShipCompleted(ship)) { ship.x -= 10; } } } // Spawn new ships until we have up to 4 ships if (ships.length < 4) { if (!nextShipTimer) { nextShipTimer = LK.setTimeout(spawnNewShip, 150); // Reduced from 300ms to 150ms for more frequent spawning } // More frequently spawn a ship immediately if we have fewer than 2 ships on screen if (ships.length < 2 && LK.ticks % 30 === 0) { // Check twice as often spawnNewShip(); } } }; // Initialize the game initGame();
===================================================================
--- original.js
+++ change.js
@@ -285,23 +285,13 @@
// Create a new ship
currentShip = new ShippingShip();
currentShip.x = 2048 + 600; // Start off-screen to the right
// Assign different y coordinates for each ship
- // Calculate an available y position that doesn't overlap with existing ships
+ // Simply pick a random position from possible positions
var possibleYPositions = [700, 1000, 1700, 2400]; // Different y positions
- var usedPositions = [];
- // Check which positions are already used
- for (var i = 0; i < ships.length; i++) {
- usedPositions.push(ships[i].y);
- }
- // Find an available position
- var yPosition = possibleYPositions[0];
- for (var i = 0; i < possibleYPositions.length; i++) {
- if (usedPositions.indexOf(possibleYPositions[i]) === -1) {
- yPosition = possibleYPositions[i];
- break;
- }
- }
+ // Choose a random position from the available options
+ var randomIndex = Math.floor(Math.random() * possibleYPositions.length);
+ var yPosition = possibleYPositions[randomIndex];
currentShip.y = yPosition;
// Create containers for the ship based on current level
currentShip.createContainers(level);
// Add ship to game and tracking array
Long Cargo ship top down. In-Game asset. 2d. High contrast. No shadows
Trump face oval no hair. In-Game asset. 2d. High contrast. No shadows
Box of toilet paper top down. In-Game asset. 2d. High contrast. No shadows
Diaper container top down. In-Game asset. 2d. High contrast. No shadows
Bag of rice top down. In-Game asset. 2d. High contrast. No shadows
Car parts in crate top down. In-Game asset. 2d. High contrast. No shadows