User prompt
add score to game. score will be a depth meters counter. it will increase on tick
Code edit (1 edits merged)
Please save this source code
User prompt
make obstacles increase and decrease their size constantly
User prompt
do not allow shield to overlap with obstacles, if more surface of shield should be over obstacle push it harder
User prompt
improve physiscs when shield moves obstacles and also make obstacles move each other
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < layoutPositions.length; i++) {' Line Number: 280
User prompt
use a simpler layout system to define the shapes of the waves
User prompt
instead of the ouline of a star, wave 3 should have a circular shape
User prompt
star shaped wave should haave only the outline of the star, no the inside of it
User prompt
star shaped for wave 3 shoudl have more vertical space between obstacles
User prompt
third wave should have 10 obstacles and the shape of a star
User prompt
second wave should have a triangular shape
User prompt
second wave should have the shape of a star
User prompt
spawn obsctales offscren in the bottom
User prompt
obstacles waves shoudl also spawn centered in the the bottom of the screen
User prompt
obstacles should spawn from the bottom of the screen
User prompt
first wave should have 4 obstacles in the shape of a square
User prompt
obstacle layout can be done in a 10 by 10 50 pixel grid.
User prompt
shield should not reposition to the touch position, it should only be draged from the current position in the direction it is being draged on down
User prompt
allow shiedl to be moved when the player drags from anywhere in the screen
Code edit (1 edits merged)
Please save this source code
User prompt
for obstacles layouts also allow obstacles to be spaned in different y positions
User prompt
update obstacle layout to have columns and rows. using # for where there is a star and . for an empty space
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
/****
* 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.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)) {
// 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.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) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
};
var obstacles = [];
var background1 = game.addChildAt(new Background(), 0);
background1.x = 2048 / 2;
background1.y = 2732 / 2;
var background2 = game.addChildAt(new Background(), 0);
background2.x = 2048 / 2;
background2.y = 2732 / 2 + 2732;
game.addChild(diver);
game.setChildIndex(diver, game.children.length - 1);
// Spawn the first wave of obstacles
spawnWave();
;
game.up = function (x, y, obj) {
dragNode = null;
};
// Define the number of obstacles in each wave
var obstaclesPerWave = [2, 3, 4, 5, 6];
var currentWave = 0;
// Spawn wave function
function spawnWave() {
// Check if the previous wave is destroyed
if (obstacles && obstacles.length === 0) {
// Define the layout of the obstacles for each wave
var obstacleLayouts = [[0.5, 0.5],
// First wave: two obstacles at 20% and 80% of the screen width
[0.1, 0.5, 0.9],
// Second wave: three obstacles at 10%, 50%, and 90% of the screen width
[0.2, 0.4, 0.6, 0.8],
// Third wave: four obstacles evenly spaced
[0.1, 0.3, 0.5, 0.7, 0.9],
// Fourth wave: five obstacles evenly spaced
[0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8] // Fifth wave: seven obstacles evenly spaced
];
// Get the layout for the current wave
var layout = obstacleLayouts[currentWave];
for (var i = 0; i < (layout ? layout.length : 0); i++) {
var obstacle = game.addChild(new Obstacle1());
// Position the obstacles according to the layout, at the bottom of the screen
obstacle.x = layout[i] * 2048;
obstacle.y = 2732;
obstacles.push(obstacle);
}
currentWave++;
if (obstaclesPerWave && currentWave >= obstaclesPerWave.length) {
currentWave = 0;
}
}
}
// Call the spawn wave function every 2 seconds
var spawnWaveInterval = LK.setInterval(spawnWave, 2000);
;
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.