Code edit (9 edits merged)
Please save this source code
User prompt
add a dark blue transparent overlay on top of the backgounrd
User prompt
reef should be one next to the other
User prompt
mirror reef image on right side
User prompt
reef can have differen widths
User prompt
randomly add on the either side of the screen a reef asset
User prompt
add green algae to the background. similar to bubbles but at another speed
User prompt
player bubbles should be releaased in sets of 3 or 5
User prompt
player bubble sould spawn on random time, and also should spawn between 3 and 6 ever ytime
User prompt
player bubbles should spawn from the bottom right of the player
User prompt
bubble release from player should have a different bubble asset
User prompt
every 5 sesconds player will release a bubble that goes upwrds
Code edit (1 edits merged)
Please save this source code
User prompt
remove obstacles per wave. obstacles will be defined by the layout itself
Code edit (1 edits merged)
Please save this source code
User prompt
obstacles layot has to be 5 by 5
Code edit (4 edits merged)
Please save this source code
User prompt
instead of using coordinas for layours, can we use a grid with # and . tod display where obstacles would be
User prompt
create a layout with the letter f
Code edit (1 edits merged)
Please save this source code
User prompt
refactor how obstaclelayours are defined. make it something easier to configure
User prompt
waves order can be random
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'shield.lastX = shield.x;' Line Number: 329
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'shield.lastX = shield.x;' Line Number: 328
/****
* Classes
****/
// Background class
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: 2048,
height: 2732
});
backgroundGraphics.anchor.set(0, 0);
});
// Bubble class
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphics = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
var scale = Math.random() * 0.5 + 0.5;
bubbleGraphics.scale.set(scale, scale);
// Set bubble speed
self.speed = -2;
// This is automatically called every game tick, if the bubble is attached!
self.update = function () {
// Move the bubble upwards and sideways
self.y += self.speed;
self.x += Math.sin(LK.ticks / 10) * 0.1;
// Reset the position of the bubble when it reaches the top
if (self.y <= 0) {
self.y = 2732;
}
// Check if the bubble is colliding with an obstacle
for (var i = 0; i < obstacles.length; i++) {
if (self.intersects(obstacles[i])) {
// Bring the bubble to the top of the z axis
game.setChildIndex(self, game.children.length - 1);
}
}
};
});
// Diver class
var Diver = Container.expand(function () {
var self = Container.call(this);
var diverGraphics = self.attachAsset('diver', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
// 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 = 60;
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,
scaleX: 0.7,
scaleY: 0.7
});
// 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,
scaleX: 0.7,
scaleY: 0.7
});
// 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)) {
// Calculate the direction vector between the shield and the obstacle
var dx = self.x - shield.x;
var dy = self.y - shield.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction vector
dx /= distance;
dy /= distance;
// Push the obstacle away from the shield
self.x += dx * 5;
self.y += dy * 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
// Add size change to the obstacle
self.scale.x = 1 + Math.sin(LK.ticks / 10) * 0.02;
self.scale.y = 1 + Math.sin(LK.ticks / 10) * 0.02;
if (self.y < 0) {
self.destroy();
var index = obstacles.indexOf(self);
if (index > -1) {
obstacles.splice(index, 1);
}
}
// 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)) {
// Calculate the direction vector between the two obstacles
var dx = self.x - otherObstacle.x;
var dy = self.y - otherObstacle.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction vector
dx /= distance;
dy /= distance;
// Increase the repulsion force and always push the obstacle to the outside
self.x += dx * 10;
self.y += dy * 10;
}
}
};
});
// Obstacle2 class
var Obstacle2 = Container.expand(function () {
var self = Container.call(this);
var obstacle2Graphics = self.attachAsset('obstacle2', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
// Set obstacle2 speed
self.speed = -5;
// This is automatically called every game tick, if the obstacle2 is attached!
self.update = function () {
// Check if the obstacle is colliding with the shield
if (self.intersects(shield)) {
// Calculate the direction vector between the shield and the obstacle
var dx = self.x - shield.x;
var dy = self.y - shield.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction vector
dx /= distance;
dy /= distance;
// Push the obstacle away from the shield
self.x += dx * 5;
self.y += dy * 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;
// Add wiggly movement to the obstacle
self.x += Math.sin(LK.ticks / 10) * 2;
// Add size change to the obstacle
self.scale.x = 1 + Math.sin(LK.ticks / 10) * 0.02;
self.scale.y = 1 + Math.sin(LK.ticks / 10) * 0.02;
if (self.y < 0) {
self.destroy();
var index = obstacles.indexOf(self);
if (index > -1) {
obstacles.splice(index, 1);
}
}
// 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)) {
// Calculate the direction vector between the two obstacles
var dx = self.x - otherObstacle.x;
var dy = self.y - otherObstacle.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction vector
dx /= distance;
dy /= distance;
// Increase the repulsion force and always push the obstacle to the outside
self.x += dx * 10;
self.y += dy * 10;
}
}
};
});
// Obstacle3 class
var Obstacle3 = Container.expand(function () {
var self = Container.call(this);
var obstacle3Graphics = self.attachAsset('obstacle3', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
// Set obstacle3 speed
self.speed = -5;
// This is automatically called every game tick, if the obstacle3 is attached!
self.update = function () {
// Check if the obstacle is colliding with the shield
if (self.intersects(shield)) {
// Calculate the direction vector between the shield and the obstacle
var dx = self.x - shield.x;
var dy = self.y - shield.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction vector
dx /= distance;
dy /= distance;
// Push the obstacle away from the shield
self.x += dx * 5;
self.y += dy * 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;
// Add unique behavior to obstacle3
self.rotation += 0.05; // Rotate faster than obstacle1
self.scale.x = 1 + Math.sin(LK.ticks / 5) * 0.05; // Larger size change
self.scale.y = 1 + Math.sin(LK.ticks / 5) * 0.05;
if (self.y < 0) {
self.destroy();
var index = obstacles.indexOf(self);
if (index > -1) {
obstacles.splice(index, 1);
}
}
// 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)) {
// Calculate the direction vector between the two obstacles
var dx = self.x - otherObstacle.x;
var dy = self.y - otherObstacle.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction vector
dx /= distance;
dy /= distance;
// Increase the repulsion force and always push the obstacle to the outside
self.x += dx * 10;
self.y += dy * 10;
}
}
};
});
// 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) {
// No need to assign dragNode
};
});
/****
* 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 a softer blue background
});
/****
* Game Code
****/
// Shield instance already created and initialized
// Initialize shield properties
shield.lastX = shield.x;
shield.lastY = shield.y;
// Create and add background instances
var background1 = game.addChild(new Background());
background1.y = 0;
// Create a shield instance
var shield = game.addChildAt(new Shield(), game.children.length);
// 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) {
var dx = x - shield.lastX;
var dy = y - shield.lastY;
shield.x += dx * 0.1; // Adjust the multiplier to control the speed of the shield movement
shield.y += dy * 0.1; // Adjust the multiplier to control the speed of the shield movement
shield.lastX = x;
shield.lastY = y;
};
var obstacles = [];
game.addChild(diver);
game.setChildIndex(diver, game.children.length - 1);
// Create bubbles after obstacles
var bubbles = [];
for (var i = 0; i < 20; i++) {
var bubble = new Bubble();
bubble.x = Math.random() * 2048;
bubble.y = Math.random() * 2732;
bubbles.push(bubble);
game.addChildAt(bubble, game.children.length);
}
// Spawn the first wave of obstacles
spawnWave();
;
// Initialize score
var score = 0;
// Create score text
var depthScoreText = new Text2('Depth:0m', {
size: 90,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 6,
font: "monospace" // Change font to be more square
});
depthScoreText.anchor.set(0.5, 0.5);
depthScoreText.x = 400;
depthScoreText.y = 100;
LK.gui.top.addChild(depthScoreText);
// Initialize a timer to update the score every second
var scoreUpdateInterval = LK.setInterval(function () {
score += 1;
if (depthScoreText) {
depthScoreText.setText('Depth:' + score + 'm');
}
}, 2000);
game.up = function (x, y, obj) {
dragNode = null;
};
// Update bubbles
for (var i = 0; i < bubbles.length; i++) {
bubbles[i].update();
}
// Define the number of obstacles in each wave
var obstaclesPerWave = [2, 3, 4, 5, 6];
var currentWave = 0;
// Spawn wave function
function spawnWave() {
// Define the layout of the obstacles for each wave
var obstacleLayouts = [
// Previous wave: two obstacles forming a line
'line',
// First wave: four obstacles forming a square
'square',
// Second wave: three obstacles forming a triangle
'triangle',
// Third wave: ten obstacles forming a circle
'circle',
// Fourth wave: five obstacles forming a cross
'cross',
// Fifth wave: six obstacles forming a hexagon
'hexagon',
// Sixth wave: seven obstacles forming a heptagon
'heptagon',
// Seventh wave: eight obstacles forming an octagon
'octagon',
// Eighth wave: nine obstacles forming a nonagon
'nonagon',
// Ninth wave: ten obstacles forming a decagon
'decagon'];
// Get the layout for the current wave
var layout = obstacleLayouts[currentWave];
// Define the positions for each layout
var positions = {
'line': [{
x: 4,
y: 2
}, {
x: 6,
y: 2
}],
'square': [{
x: 2,
y: 2
}, {
x: 2,
y: 7
}, {
x: 7,
y: 2
}, {
x: 7,
y: 7
}],
'triangle': [{
x: 5,
y: 2
}, {
x: 2,
y: 7
}, {
x: 8,
y: 7
}],
'circle': [{
x: 5,
y: 2
}, {
x: 6,
y: 3
}, {
x: 7,
y: 4
}, {
x: 7,
y: 5
}, {
x: 6,
y: 6
}],
'cross': [{
x: 5,
y: 2
}, {
x: 5,
y: 3
}, {
x: 5,
y: 4
}, {
x: 4,
y: 3
}, {
x: 6,
y: 3
}],
'hexagon': [{
x: 5,
y: 2
}, {
x: 6,
y: 2.5
}, {
x: 7,
y: 3.5
}, {
x: 6,
y: 4.5
}, {
x: 4,
y: 4.5
}, {
x: 3,
y: 3.5
}, {
x: 4,
y: 2.5
}],
'heptagon': [{
x: 5,
y: 2
}, {
x: 6,
y: 2.5
}, {
x: 6,
y: 3.5
}, {
x: 5,
y: 4
}, {
x: 4,
y: 3.5
}, {
x: 4,
y: 2.5
}, {
x: 5,
y: 3
}],
'octagon': [{
x: 5,
y: 2
}, {
x: 6,
y: 2.5
}, {
x: 6,
y: 3.5
}, {
x: 5,
y: 4
}, {
x: 4,
y: 3.5
}, {
x: 4,
y: 2.5
}, {
x: 5,
y: 3
}, {
x: 5,
y: 3.5
}],
'nonagon': [{
x: 5,
y: 2
}, {
x: 6,
y: 2.5
}, {
x: 6,
y: 3.5
}, {
x: 5,
y: 4
}, {
x: 4,
y: 3.5
}, {
x: 4,
y: 2.5
}, {
x: 5,
y: 3
}, {
x: 5,
y: 3.5
}, {
x: 5,
y: 2.5
}],
'decagon': [{
x: 5,
y: 2
}, {
x: 6,
y: 2.5
}, {
x: 6,
y: 3.5
}, {
x: 5,
y: 4
}, {
x: 4,
y: 3.5
}, {
x: 4,
y: 2.5
}, {
x: 5,
y: 3
}, {
x: 5,
y: 3.5
}, {
x: 5,
y: 2.5
}, {
x: 5,
y: 4.5
}]
};
// Get the positions for the current layout
var layoutPositions = positions[layout];
if (!layoutPositions) {
console.error('Error: layoutPositions is undefined. Check the layout variable and the positions object.');
return;
}
// Randomly choose an obstacle type for the entire wave
var obstacleTypes = [Obstacle1, Obstacle2, Obstacle3];
var obstacleType = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)];
for (var i = 0; i < layoutPositions.length; i++) {
var obstacle = game.addChild(new obstacleType());
// Position the obstacles according to the layout, using the grid for positioning
obstacle.x = 2048 / 2 + (layoutPositions[i].x - gridSize / 2) * cellSize;
obstacle.y = 2732 + layoutPositions[i].y * cellSize; // Spawn obstacles offscreen at the bottom
obstacles.push(obstacle);
}
currentWave++;
if (obstaclesPerWave && currentWave >= obstaclesPerWave.length) {
currentWave = 0;
}
// Add interval of wait between waves
LK.setTimeout(function () {
spawnWave();
}, 5000); // 5 seconds wait between waves
}
// Define the grid size and the size of each cell in the grid
var gridSize = 10;
var cellSize = 50;
// Call the spawn wave function every 1 second
// Initial call to spawn the first wave
spawnWave();
;
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.