Code edit (3 edits merged)
Please save this source code
User prompt
For some reason I fucked it up and the dragon when falling does not stand still on top of a floor and continues its movement down. Please fix it - a falling dragon should stop always if in its way down it finds a floor
Code edit (10 edits merged)
Please save this source code
User prompt
Ok. Now what I want you to do is the following: - While you are jumping, please detect if the dragon intersects with a platform (not a floor, a platform). If so, make isFalling = true, isJumping=false, and create a flag called "canJump" that will set to false until the dragon hits a floor.
Code edit (8 edits merged)
Please save this source code
User prompt
Before this loop, please generate a random tint color and apply it to all the platforms inside that loop: for (var i = 0; i < platformLength; i++) { var newX = startX + i * 100; if (newX > 2000 || newX < 100) { continue; } var platform = LK.getAsset('floor', { anchorX: 0.5, anchorY: 0.5, x: startX + i * 100, y: platformYPositions[j] }); game.addChild(platform); floors.push(platform); }
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
You can't have overlapping platforms! You still create them on the same height !
User prompt
Too many heights. Use only 4 - 5 heights
User prompt
Revisit how you are creating the platforms because something is not right. Redo it again. - 1 platform per height only allowed. - Platforms can only have between 5 and 10 floor assets. - You can't create overlapping platforms - You You can't create platforms above 2300 height and below 400
User prompt
You can not create finish one platform on a height and start another on the same height. Only 1 platform for height.
User prompt
You are creating several floors overlapping each other. Make sure that when you create a platform on a height, there is a gamp between one platform and another if you want to create two. Never allow them overlapping
User prompt
I see overlapping floors, that should not happen at all!
Code edit (4 edits merged)
Please save this source code
User prompt
Every platform should have their floors tinted to a different color (random)
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
No, I mean var background - set tint to a random color
User prompt
Make that everytime the we start a new game, the color of the background is different
Code edit (3 edits merged)
Please save this source code
User prompt
No sorry, the enemies should have scale.x = -1 when they move left, scale.x = 1 when they move right
User prompt
As we do with the dragon, if the enemies are on the left half of the screen, then should be mirrored - (scale.x * -1)
Code edit (3 edits merged)
Please save this source code
User prompt
Ok the enemies should be on their platforms from the beginning of the platform to the end, not only 200 pixels
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Class for Bubbles var Bubble = Container.expand(function () { var self = Container.call(this); var bubbleGraphics = self.attachAsset('bubble', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.x += self.speed; // Check for intersection with any floor for (var i = 0; i < floors.length; i++) { if (self.intersects(floors[i])) { // Create a PoppedBubble at the bubble's position var pop = game.addChild(new PoppedBubble()); pop.x = self.x; pop.y = self.y; // Destroy the bubble self.destroy(); bubbles.splice(bubbles.indexOf(self), 1); // Destroy the PoppedBubble after 0.5 seconds LK.setTimeout(function () { pop.destroy(); }, 500); break; } } // Update last known positions self.lastX = self.x; self.lastY = self.y; }; }); //<Assets used in the game will automatically appear here> // Class for the Dragon character var Dragon = Container.expand(function () { var self = Container.call(this); var dragonGraphics = self.attachAsset('dragon', { anchorX: 0.5, anchorY: 0.5 }); self.isIntersectingBubble = false; // Add a variable to track if the dragon is intersecting a bubble self.shootBubble = function () { var bubble = new Bubble(); bubble.x = self.x + 200 * self.scaleX; bubble.y = self.y; // If the dragon is looking right, the bubble should move to the right if (self.scale.x == 1) { bubble.speed = 10; } else { // If the dragon is looking left, the bubble should move to the left bubble.speed = -10; } game.addChild(bubble); bubbles.push(bubble); }; }); // Class for Pop var PoppedBubble = Container.expand(function () { var self = Container.call(this); var popGraphics = self.attachAsset('poppedBubble', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var easingFunctions = [tween.linear, tween.easeIn, tween.easeOut, tween.easeInOut, tween.bounceIn, tween.elasticInOut]; // Attach the background image to the game var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); background.tint = Math.floor(Math.random() * 16777215); game.addChild(background); function isStandingOnFloor() { for (var i = 0; i < floors.length; i++) { if (dragon.intersects(floors[i])) { return true; } } return false; } function startDragonFall() { isFalling = true; } function updateFall() { if (isFalling || !isStandingOnFloor()) { dragon.y += 10; // Adjust fall speed as needed // Check for intersection with any floor for (var i = 0; i < floors.length; i++) { if (dragon.intersects(floors[i])) { isJumping = false; // Stop jumping isFalling = false; // Stop falling when colliding with a floor dragon.y -= floors[i].height / 8; dragon.targetX = undefined; // Reset targetX to allow movement after landing break; } } } } //<Assets used in the game will automatically appear here> // Handle mouse move events to move the dragon game.move = function (x, y, obj) { // Ignore the event if the target is outside the screen or close to its margins if (x > 150 && x < 2048 - 200) { // Set the target x position for the dragon dragon.targetX = x; } }; var isFalling = false; // Initialize isFalling to track dragon's fall state var dragon = game.addChild(new Dragon()); dragon.lastY = dragon.y; // Initialize lastY position dragon.x = 1024; // Center horizontally dragon.y = 2732 - 90 - dragon.height / 2; // Position the dragon on top of the floor var bubbles = []; var enemies = []; enemies.forEach(function (enemy) { enemy.isMoving = false; // Initialize isMoving flag to false }); var floors = []; // Handle game updates game.update = function () { // Move dragon incrementally towards target x if (dragon.targetX !== undefined) { var increment = (dragon.targetX - dragon.x) / 10; // Move in 0.5 seconds assuming 60 FPS if (!isJumping && dragon.targetX !== undefined && (increment > 0 && dragon.x < dragon.targetX || increment < 0 && dragon.x > dragon.targetX)) { dragon.x += increment; } // Update last known position dragon.lastX = dragon.x; dragon.lastY = dragon.y; // Track lastY position // Adjust dragon's scale based on x position if (dragon.targetX > 1024) { dragon.scale.x = -1; } else { dragon.scale.x = 1; } } updateFall(); updateEnemiesMovement(); updateBubbles(); }; // Handle touch events for shooting bubbles var lastShot = 0; var lastClick = 0; var isJumping = false; // Add a variable to track if the dragon is jumping game.down = function (x, y, obj) { var now = Date.now(); if (now - lastShot > 500) { dragon.shootBubble(); lastShot = now; } if (now - lastClick < 200 && (!isJumping && !isFalling || dragon.isIntersectingBubble)) { // Only allow the dragon to jump if it is not already jumping or if it is intersecting a bubble // Check if the jump trajectory is clear of floors var canJump = true; if (canJump) { isJumping = true; // Set isJumping to true when the dragon starts jumping // Make the dragon jump using a smooth animation tween(dragon, { y: dragon.y - 200 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { isJumping = false; // Reset jumping state after the jump // Start dragon fall after jump startDragonFall(); } }); } // If the dragon is intersecting a bubble, show the pop asset before destroying the bubble if (dragon.isIntersectingBubble) { for (var i = 0; i < bubbles.length; i++) { if (dragon.intersects(bubbles[i])) { var pop = game.addChild(new PoppedBubble()); pop.x = bubbles[i].x; pop.y = bubbles[i].y; bubbles[i].destroy(); bubbles.splice(i, 1); LK.setTimeout(function () { pop.destroy(); }, 500); break; } } } } lastClick = now; }; // Add a floor to the bottom of the screen for (var i = 0; i < 21; i++) { var floor = LK.getAsset('floor', { anchorX: 0.5, anchorY: 0.5, x: i * 100, y: 2732 - 30 }); game.addChild(floor); floors.push(floor); } // Add random platforms with irregular heights and positions var platformYPositions = []; var currentY = 2300; // Start further from the bottom var minPlatformHeight = 100; var maxPlatformHeight = 400; var minGap = 100; var maxGap = 300; var minPlatformLength = 5; var maxPlatformLength = 15; while (currentY > 400) { // Ensure platforms are not too close to the top var platformHeight = Math.floor(Math.random() * (maxPlatformHeight - minPlatformHeight + 1)) + minPlatformHeight; platformYPositions.push(currentY); currentY -= platformHeight + Math.floor(Math.random() * (maxGap - minGap + 1)) + minGap; } for (var j = 0; j < platformYPositions.length; j++) { var platformLength = Math.floor(Math.random() * (maxPlatformLength - minPlatformLength + 1)) + minPlatformLength; var startX = Math.floor(Math.random() * (2048 - platformLength * 100)); // Random start position for (var i = 0; i < platformLength; i++) { var platform = LK.getAsset('floor', { anchorX: 0.5, anchorY: 0.5, x: startX + i * 100, y: platformYPositions[j] }); game.addChild(platform); floors.push(platform); } } // Add continuous floor on the left margin of the screen for (var j = 0; j < 28; j++) { var leftFloor = LK.getAsset('floor', { anchorX: 0.5, anchorY: 0.5, x: 0, y: j * 100 }); game.addChild(leftFloor); floors.push(leftFloor); } // Add continuous floor on the right margin of the screen for (var k = 0; k < 28; k++) { var rightFloor = LK.getAsset('floor', { anchorX: 0.5, anchorY: 0.5, x: 2048 - 50, y: k * 100 }); game.addChild(rightFloor); floors.push(rightFloor); } // Add random platforms with irregular heights and positions for (var j = 0; j < platformYPositions.length; j++) { var platformLength = Math.floor(Math.random() * (maxPlatformLength - minPlatformLength + 1)) + minPlatformLength; var startX = Math.floor(Math.random() * (2048 - platformLength * 100)); // Random start position for (var i = 0; i < platformLength; i++) { var platform = LK.getAsset('floor', { anchorX: 0.5, anchorY: 0.5, x: startX + i * 100, y: platformYPositions[j] }); game.addChild(platform); floors.push(platform); } // Spawn an enemy on top of each platform var enemyType = 'enemy' + (i % 5 + 1); // Cycle through enemy1 to enemy5 var enemy = LK.getAsset(enemyType, { anchorX: 0.5, anchorY: 0.5, x: startX + 100, y: platformYPositions[j] - 100 // Position enemy on top of the platform }); game.addChild(enemy); enemies.push(enemy); } function updateEnemiesMovement() { // Check if all enemies are moving and start their movement if not enemies.forEach(function (enemy) { if (!enemy.isMoving) { enemy.isMoving = true; // Set isMoving flag to true // Start enemy movement var platformLength = floors.filter(function (floor) { return floor.y === enemy.y + 100; }).length * 40; // Calculate platform length tween(enemy, { x: enemy.x + platformLength - enemy.width }, { duration: 2000, easing: easingFunctions[Math.floor(Math.random() * easingFunctions.length)], onFinish: function onFinish() { tween(enemy, { x: enemy.x - (platformLength - enemy.width) }, { duration: 2000, easing: tween.linear, onFinish: function onFinish() { enemy.isMoving = false; // Reset isMoving flag } }); } }); } // Adjust enemy scale based on movement direction if (enemy.lastX < enemy.x) { enemy.scale.x = 1; // Moving right } else if (enemy.lastX > enemy.x) { enemy.scale.x = -1; // Moving left } // Update last known positions enemy.lastX = enemy.x; enemy.lastY = enemy.y; }); } function updateBubbles() { // Update bubbles for (var i = bubbles.length - 1; i >= 0; i--) { var bubble = bubbles[i]; if (!bubble) { continue; } // Check for bubble-bubble intersections for (var j = i - 1; j >= 0; j--) { var otherBubble = bubbles[j]; if (!otherBubble) { continue; } if (bubble.intersects(otherBubble)) { // Create a PoppedBubble for each intersecting bubble var pop1 = game.addChild(new PoppedBubble()); pop1.x = bubble.x; pop1.y = bubble.y; var pop2 = game.addChild(new PoppedBubble()); pop2.x = otherBubble.x; pop2.y = otherBubble.y; // Destroy both bubbles bubble.destroy(); otherBubble.destroy(); bubbles.splice(i, 1); bubbles.splice(j, 1); // Destroy the PoppedBubbles after 0.5 seconds LK.setTimeout(function () { pop1.destroy(); pop2.destroy(); }, 500); break; } } if (!bubble) { return; } if (bubble.y < -50) { bubble.destroy(); bubbles.splice(i, 1); } } // Check for bubble-enemy collisions for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; for (var j = bubbles.length - 1; j >= 0; j--) { var bubble = bubbles[j]; if (bubble.intersects(enemy)) { // Capture enemy enemy.destroy(); enemies.splice(i, 1); bubble.destroy(); bubbles.splice(j, 1); break; } } } // Check if the dragon is intersecting a bubble for (var i = 0; i < bubbles.length; i++) { if (dragon.intersects(bubbles[i])) { // Create a PoppedBubble at the bubble's position var pop = game.addChild(new PoppedBubble()); pop.x = bubbles[i].x; pop.y = bubbles[i].y; // Destroy the bubble bubbles[i].destroy(); bubbles.splice(i, 1); // Destroy the PoppedBubble after 0.5 seconds LK.setTimeout(function () { pop.destroy(); }, 500); break; } } }
===================================================================
--- original.js
+++ change.js
@@ -74,9 +74,9 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: Math.floor(Math.random() * 16777215) // Set a random background color
+ backgroundColor: 0x000000
});
/****
* Game Code
A pixel slime, funny, looking right. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
brick, brown color, pixel style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Draw wings to the dragon
better wings, pixel style, more contrasted, more visible, blue color
A pixel based enemy from the world of Bubble Bobble. It should be ghost-like. Make it very 80s 90s like in pixel, arcade style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
A pixel based enemy from the world of Bubble Bobble. It should be blob like. Make it very 80s 90s like in pixel, arcade style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a pixel clouds background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a pixel clouds background, with mountains, full height full width Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a similar image. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a pixel clouds background, with mountains, full height full width Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows