Code edit (2 edits merged)
Please save this source code
User prompt
When finishing the jumping and intersecting the dragon with the floor, something weird is happening. It's ok to land on a floor, in that case the dragon should stop at that y of the floor (a little bit higher, you can take the floor height / 2 or something like that)
Code edit (1 edits merged)
Please save this source code
User prompt
In game.move, ignore the event if the target is outside the screen or close to its margins
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: increment is not defined' in or related to this line: 'if (dragon.intersects(floors[i]) && increment < 0) {' Line Number: 242
Code edit (1 edits merged)
Please save this source code
User prompt
No. The collisions of the dragon and the floor is not right. Let me explain again and please, redo it. 1. The dragon can NEVER cross or intersect a floor during a trajectory. 2. If during a trajectory to the mouse position (targetX) the dragon finds a floor, it's an obstacle. The targetX then should be set to the obstacle.x - obstacle.width / 2 probably, if it's moving right. If it's moving left, it's probably obstable.x + obstacle.width / 2 3. Make sure the dragon can not move any further that direction, but it can move in the other direction if there is no obstacle of course.
User prompt
No but not preventing it from moving at all! If ther eis a floor on the right, it prevents the dragon to move to the right. If its on the left, it prevents the dragon to move to the left.
User prompt
The dragon can never cross a floor object, its trajectory should be stopped just before!
User prompt
If the dragon intersects with a bubble, pop it as usual - render a poppedbubble, then destroy, etc. As you are doing in the rest of the game
User prompt
Stop dragon movement when intersecting with a floor during trajectory, targetX should be set as the current x and stop any increments
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in or related to this line: 'if (bubble.intersects(otherBubble)) {' Line Number: 142
User prompt
Please fix the bug: 'Uncaught ReferenceError: tween is not defined' in or related to this line: 'tween(dragon, {' Line Number: 205 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (2 edits merged)
Please save this source code
User prompt
Do it
Code edit (1 edits merged)
Please save this source code
User prompt
You don't have it right. You have added the increments inside game.move, which means they will only happen when I move again the mouse! No, I have already moved it, I need the increments to happen even if I'm not moving the mouse anymore
Code edit (1 edits merged)
Please save this source code
User prompt
Don't use tween for interpolating the movement of the dragon to left or right. Use just dragon.x and an increment
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'lastX')' in or related to this line: 'if (dragon.lastX !== undefined && dragon.x !== dragon.lastX) {' Line Number: 105
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'lastX')' in or related to this line: 'if (dragon.lastX !== undefined && dragon.x !== dragon.lastX) {' Line Number: 105
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'lastX')' in or related to this line: 'if (dragon.lastX !== undefined && dragon.x !== dragon.lastX) {' Line Number: 105
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'lastX')' in or related to this line: 'if (dragon.lastX !== undefined && dragon.x !== dragon.lastX) {' Line Number: 105
/**** * 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 = 5; } else { // If the dragon is looking left, the bubble should move to the left bubble.speed = -5; } game.addChild(bubble); bubbles.push(bubble); }; }); // Class for Enemies var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Enemy movement logic }; }); // 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 //Init game with black background }); /**** * Game Code ****/ // Check for dragon movement and floor intersection if (dragon.lastX !== undefined && dragon.x !== dragon.lastX) { for (var i = 0; i < floors.length; i++) { if (dragon.intersects(floors[i])) { // Stop the dragon at the point of intersection tween.stop(dragon, { x: true }); break; } } } // Update last known dragon position dragon.lastX = dragon.x; //<Assets used in the game will automatically appear here> game.move = function (x, y, obj) { // Interpolate dragon's x position to target x over 0.5 seconds tween(dragon, { x: x }, { duration: 500, easing: tween.linear }); // Adjust dragon's scale based on x position if (x > 1024) { dragon.scale.x = -1; } else { dragon.scale.x = 1; } }; var dragon = game.addChild(new Dragon()); dragon.lastX = dragon.x; // Initialize lastX to prevent undefined error dragon.lastX = dragon.x; // Initialize lastX to prevent undefined error dragon.x = 1024; // Center horizontally dragon.y = 2732 - 100 - dragon.height / 2; // Position the dragon on top of the floor var bubbles = []; var enemies = []; var floors = []; // Handle game updates game.update = function () { // Update bubbles for (var i = bubbles.length - 1; i >= 0; i--) { var bubble = bubbles[i]; bubble.update(); // Check for bubble-bubble intersections for (var j = i - 1; j >= 0; j--) { var otherBubble = bubbles[j]; 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.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])) { dragon.isIntersectingBubble = true; break; } else { dragon.isIntersectingBubble = false; } } }; // 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 || dragon.isIntersectingBubble)) { // Only allow the dragon to jump if it is not already jumping or if it is intersecting a bubble 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: 500, easing: tween.easeOut, onFinish: function onFinish() { // After the jump, make the dragon fall down until it intersects a floor var fallInterval = LK.setInterval(function () { dragon.y += 5; // Apply a downward speed for (var i = 0; i < floors.length; i++) { if (dragon.intersects(floors[i])) { isJumping = false; // Stop falling when intersecting a floor LK.clearInterval(fallInterval); // Clear the interval to stop the dragon from falling break; } } }, 16); // Run the interval at approximately 60 FPS } }); // 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 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); }
===================================================================
--- original.js
+++ change.js
A version of this bubble but exploded
brick, brown color, pixel style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
better wings, pixel style, more contrasted, more visible, blue color
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
A popped blue bobble, pixel style, bubble booble arcade game inspired. In-Game asset. 2d. High contrast. No shadows
A bubble popping, pixel style, retro. In-Game asset. 2d. High contrast. No shadows