User prompt
Please fix the bug: 'ReferenceError: obstacles is not defined' in or related to this line: 'for (var i = 0; i < obstacles.length; i++) {' Line Number: 118
User prompt
add a wave spawn system for obstacles. each wave will have a shape, ammount of obstaccles, speed and asset attribute
User prompt
make sure backgorund in behind the z axis of the shield
Code edit (4 edits merged)
Please save this source code
User prompt
make sure shiedl is in front of backgound
User prompt
add background moving from top down to pretend and endelss scrolling
User prompt
x direction of obstacles should be permanently affected by shiedl. should not go back to the original one
User prompt
make pushing from shield to obstacles smoother
User prompt
obstacles should have a small rotations on their axis
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'bg1.y += 2;' Line Number: 27
User prompt
add paralax scrollin on bot sides of the screen. diver is moving down so scrolling hsould be up
User prompt
if obstacle colides with diver then game over
User prompt
bring player as the topmost asset in the z axis
Code edit (1 edits merged)
Please save this source code
User prompt
flipper should be in the same position but below the z axis of the diver
User prompt
make flipper below on the z axis from diver
User prompt
add rocks on both sides of theh screen. they will move upwards to convery a feeling of the diver moving dowwrds while stayin gin the same place. rocks should spawn in random intnervals and never stop comming
User prompt
obstacles speed and rotations should be permanently impacted by shield hitting them, but they shoudd also alwasy keep the upward movement
User prompt
obstacles should also be impacted on their rotations when shield shits them
User prompt
on game start destroy player and create him again
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'y')' in or related to this line: 'rightFlipper.y = diver.y;' Line Number: 146
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'rightFlipper.x = diver.x + 50;' Line Number: 143
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'y')' in or related to this line: 'leftFlipper.y = diver.y;' Line Number: 138
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'leftFlipper.x = diver.x - 50;' Line Number: 135
User prompt
remove flipper from diver classs. shoudl be indepentend from ddiver
/**** * Classes ****/ // Background class var Background = Container.expand(function () { var self = Container.call(this); var backgroundGraphics = self.attachAsset('background', { anchorX: 0.5, anchorY: 0.5 }); // Set background speed self.speed = -2; // This is automatically called every game tick, if the background is attached! self.update = function () { // Move the background downwards self.y += self.speed; // Reset the position of the background when it reaches the end if (self.y <= -2732) { self.y = 2732; } }; }); // Diver class var Diver = Container.expand(function () { var self = Container.call(this); var diverGraphics = self.attachAsset('diver', { anchorX: 0.5, anchorY: 0.5 }); // Add a sideways movement to the diver self.movement = 0; self.direction = 1; self.update = function () { self.movement += self.direction * 0.03; if (self.movement > 0.5 || self.movement < -0.5) { self.direction *= -1; } self.x += self.movement; }; // Add flippers to the diver var leftFlipper = self.addChild(new Flipper()); leftFlipper.x = -50; leftFlipper.depth = -1; var rightFlipper = self.addChild(new Flipper()); rightFlipper.x = 50; rightFlipper.depth = -1; }); // Flipper class var Flipper = Container.expand(function () { var self = Container.call(this); var flipperGraphics = self.attachAsset('flippers', { anchorX: 0.5, anchorY: 1.0 }); // Set flipper movement self.movement = 0; self.direction = 1; // This is automatically called every game tick, if the flipper is attached! self.update = function () { // Move the flipper subtly to simulate flipping self.movement += self.direction * 0.03; if (self.movement > 0.5 || self.movement < -0.5) { self.direction *= -1; } self.rotation = self.movement; }; }); // Obstacle1 class var Obstacle1 = Container.expand(function () { var self = Container.call(this); var obstacle1Graphics = self.attachAsset('obstacle1', { anchorX: 0.5, anchorY: 0.5 }); // Set obstacle1 speed self.speed = -5; // This is automatically called every game tick, if the obstacle1 is attached! self.update = function () { // Check if the obstacle is colliding with the shield if (self.intersects(shield)) { // Push the obstacle to the right if the shield is on its left if (self.x < shield.x) { self.x -= 2.5; if (self.intersects(shield)) { self.x -= 2.5; } } else if (self.x > shield.x) { self.x += 2.5; if (self.intersects(shield)) { self.x += 2.5; } } } // Check for collision with diver if (self.intersects(diver)) { // Flash screen red for 1 second (1000ms) to show game over LK.effects.flashScreen(0xff0000, 1000); // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); } // Continue moving upwards self.y += self.speed; self.rotation += 0.01; // Add small rotation to the obstacle if (self.y < 0) { self.y = 2732; } // Check if the obstacle is colliding with another obstacle for (var i = 0; i < obstacles.length; i++) { var otherObstacle = obstacles[i]; if (self !== otherObstacle && self.intersects(otherObstacle)) { // Push the obstacle to the right if the other obstacle is on its left if (self.x < otherObstacle.x) { self.x -= 2.5; if (self.intersects(otherObstacle)) { self.x -= 2.5; } } else if (self.x > otherObstacle.x) { self.x += 2.5; if (self.intersects(otherObstacle)) { self.x += 2.5; } } } } }; }); // Shield class var Shield = Container.expand(function () { var self = Container.call(this); var shieldGraphics = self.attachAsset('shield', { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { dragNode = self; }; }); /**** * Initialize Game ****/ // Create a diver instance //<Assets used in the game will automatically appear here> var game = new LK.Game({ backgroundColor: 0xADD8E6 //Init game with light blue background }); /**** * Game Code ****/ // Create a shield instance var shield = game.addChild(new Shield()); // Position the shield at the center of the screen shield.x = 2048 / 2; shield.y = 2732 / 2; // Create a diver instance var dragNode = null; var diver = new Diver(); diver.depth = 2; // Position the diver at the top center of the screen, 200 pixels down from the top diver.x = 2048 / 2; diver.y = 500; // Position the flippers relative to the diver diver.children[0].y = diver.height / 2 - 20; // Left flipper diver.children[0].y = diver.children[0].y; // Right flipper // Set diver to a higher depth than flippers diver.depth = 2; // Create an obstacle1 instance game.move = function (x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } }; var obstacles = []; var obstacle1 = new Obstacle1(); var background1 = game.addChild(new Background()); background1.x = 2048 / 2; background1.y = 2732 / 2; var background2 = game.addChild(new Background()); background2.x = 2048 / 2; background2.y = 2732 / 2 + 2732; game.addChild(diver); game.setChildIndex(diver, game.children.length - 1); game.addChild(obstacle1); // Position the obstacle1 at the bottom center of the screen obstacle1.x = 2048 / 2 - 100; obstacle1.y = 2732; obstacles.push(obstacle1); var obstacle2 = game.addChild(new Obstacle1()); // Position the obstacle2 next to obstacle1 obstacle2.x = 2048 / 2 + 100; obstacle2.y = 2732; obstacles.push(obstacle2); ; game.up = function (x, y, obj) { dragNode = null; };
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,26 @@
/****
* Classes
****/
+// Background class
+var Background = Container.expand(function () {
+ var self = Container.call(this);
+ var backgroundGraphics = self.attachAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Set background speed
+ self.speed = -2;
+ // This is automatically called every game tick, if the background is attached!
+ self.update = function () {
+ // Move the background downwards
+ self.y += self.speed;
+ // Reset the position of the background when it reaches the end
+ if (self.y <= -2732) {
+ self.y = 2732;
+ }
+ };
+});
// Diver class
var Diver = Container.expand(function () {
var self = Container.call(this);
var diverGraphics = self.attachAsset('diver', {
@@ -54,22 +73,24 @@
anchorY: 0.5
});
// Set obstacle1 speed
self.speed = -5;
- self.speedX = 0;
// This is automatically called every game tick, if the obstacle1 is attached!
self.update = function () {
// Check if the obstacle is colliding with the shield
if (self.intersects(shield)) {
// Push the obstacle to the right if the shield is on its left
if (self.x < shield.x) {
self.x -= 2.5;
- self.speedX = -2.5;
+ if (self.intersects(shield)) {
+ self.x -= 2.5;
+ }
} else if (self.x > shield.x) {
self.x += 2.5;
- self.speedX = 2.5;
+ if (self.intersects(shield)) {
+ self.x += 2.5;
+ }
}
- self.x += self.speedX;
}
// Check for collision with diver
if (self.intersects(diver)) {
// Flash screen red for 1 second (1000ms) to show game over
@@ -89,14 +110,17 @@
if (self !== otherObstacle && self.intersects(otherObstacle)) {
// Push the obstacle to the right if the other obstacle is on its left
if (self.x < otherObstacle.x) {
self.x -= 2.5;
- self.speedX = -2.5;
+ if (self.intersects(otherObstacle)) {
+ self.x -= 2.5;
+ }
} else if (self.x > otherObstacle.x) {
self.x += 2.5;
- self.speedX = 2.5;
+ if (self.intersects(otherObstacle)) {
+ self.x += 2.5;
+ }
}
- self.x += self.speedX;
}
}
};
});
@@ -149,8 +173,14 @@
}
};
var obstacles = [];
var obstacle1 = new Obstacle1();
+var background1 = game.addChild(new Background());
+background1.x = 2048 / 2;
+background1.y = 2732 / 2;
+var background2 = game.addChild(new Background());
+background2.x = 2048 / 2;
+background2.y = 2732 / 2 + 2732;
game.addChild(diver);
game.setChildIndex(diver, game.children.length - 1);
game.addChild(obstacle1);
// Position the obstacle1 at the bottom center of the screen
8bit. cartoon. jellyfish.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
empty 8 bit cartoon white circle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon. 8-bit. octopus. colorful.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon. 8-bit. sea urchin. colorful. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon 8bit stingray. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.