User prompt
add up and down movement to obstacle 4
User prompt
reduce side movemet of obstacle 6
User prompt
obsctacle 1 should rotate on its axis
User prompt
reduce side to side speed for obtacle 6
User prompt
reduce side to side speed for obstcalte 6
User prompt
obscatle 6 shoudl flicker and have side to side fast movement
User prompt
obstacles should randomly use their mirror image
User prompt
obtacles should only change directions when touched by the shield or colide with other obstacle, but not by themselves
User prompt
obstacle 4 shoudl have some slight up and down movement as well
User prompt
obstacle 5 shoudl increase and decrease its size
User prompt
obstacle 5 should nto rotate on its axis
User prompt
obstacle4 shoudlnot rotate on its axis
User prompt
can we merge all obstacles classes into one that they will use a different asset and will be random
User prompt
add 3 more obstacles
Code edit (6 edits merged)
Please save this source code
User prompt
add a little more incline to waves starting from the right
Code edit (1 edits merged)
Please save this source code
User prompt
onbtacles should not change direction when they are closer to the diver
Code edit (1 edits merged)
Please save this source code
User prompt
increase diverr hitbos in the y axis by 30%
User prompt
decrease diver hitbox size, but do not change the size of the diver.
User prompt
decrease diver hitbox size
Code edit (1 edits merged)
Please save this source code
User prompt
if wave start position is left, then add +1 x speed
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -289,9 +289,9 @@
// Continue moving upwards
if (wavePositionLabel === 'right') {
self.x -= 1.5;
} else if (wavePositionLabel === 'left') {
- self.x += 1;
+ self.x += 1.5;
}
self.y += self.speed * speedMultiplier;
// Add wiggly movement to the obstacle
self.x += Math.sin(LK.ticks / 10) * 2;
@@ -421,8 +421,305 @@
}
}
};
});
+// Obstacle4 class
+var Obstacle4 = Container.expand(function () {
+ var self = Container.call(this);
+ var obstacle4Graphics = self.attachAsset('obstacle4', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.7,
+ scaleY: 0.7
+ });
+ // Set obstacle4 speed
+ self.speed = -5;
+ // This is automatically called every game tick, if the obstacle4 is attached!
+ self.update = function () {
+ // Check if the obstacle is colliding with the shield
+ if (self.intersects(shield, {
+ tolerance: 10
+ })) {
+ // Play bubble sound if at least 1 second has passed since the last play
+ if (LK.ticks - lastBubbleSoundTime > 20) {
+ LK.getSound('bubble').play();
+ lastBubbleSoundTime = LK.ticks;
+ }
+ // 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.children.find(function (child) {
+ return child.alpha === 0;
+ }), {
+ tolerance: 10
+ })) {
+ // 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();
+ }
+ // Update spatial hash
+ var oldHashX = Math.floor((self.x - self.speed * speedMultiplier) / cellSize);
+ var oldHashY = Math.floor((self.y - self.speed * speedMultiplier) / cellSize);
+ var newHashX = Math.floor(self.x / cellSize);
+ var newHashY = Math.floor(self.y / cellSize);
+ var oldHashKey = oldHashX + ',' + oldHashY;
+ var newHashKey = newHashX + ',' + newHashY;
+ if (oldHashKey !== newHashKey) {
+ if (spatialHash[oldHashKey]) {
+ var index = spatialHash[oldHashKey].indexOf(self);
+ if (index > -1) {
+ spatialHash[oldHashKey].splice(index, 1);
+ }
+ }
+ if (!spatialHash[newHashKey]) {
+ spatialHash[newHashKey] = [];
+ }
+ spatialHash[newHashKey].push(self);
+ }
+ // Continue moving upwards
+ if (wavePositionLabel === 'right') {
+ self.x -= 1.5;
+ } else if (wavePositionLabel === 'left') {
+ self.x += 1.5;
+ }
+ self.y += self.speed * speedMultiplier;
+ // Add unique behavior to obstacle4
+ self.rotation += 0.03; // Rotate at a different speed
+ self.scale.x = 1 + Math.sin(LK.ticks / 15) * 0.03; // Different size change
+ self.scale.y = 1 + Math.sin(LK.ticks / 15) * 0.03;
+ 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;
+ }
+ }
+ };
+});
+// Obstacle5 class
+var Obstacle5 = Container.expand(function () {
+ var self = Container.call(this);
+ var obstacle5Graphics = self.attachAsset('obstacle5', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.7,
+ scaleY: 0.7
+ });
+ // Set obstacle5 speed
+ self.speed = -5;
+ // This is automatically called every game tick, if the obstacle5 is attached!
+ self.update = function () {
+ // Check if the obstacle is colliding with the shield
+ if (self.intersects(shield, {
+ tolerance: 10
+ })) {
+ // Play bubble sound if at least 1 second has passed since the last play
+ if (LK.ticks - lastBubbleSoundTime > 20) {
+ LK.getSound('bubble').play();
+ lastBubbleSoundTime = LK.ticks;
+ }
+ // 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.children.find(function (child) {
+ return child.alpha === 0;
+ }), {
+ tolerance: 10
+ })) {
+ // 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();
+ }
+ // Update spatial hash
+ var oldHashX = Math.floor((self.x - self.speed * speedMultiplier) / cellSize);
+ var oldHashY = Math.floor((self.y - self.speed * speedMultiplier) / cellSize);
+ var newHashX = Math.floor(self.x / cellSize);
+ var newHashY = Math.floor(self.y / cellSize);
+ var oldHashKey = oldHashX + ',' + oldHashY;
+ var newHashKey = newHashX + ',' + newHashY;
+ if (oldHashKey !== newHashKey) {
+ if (spatialHash[oldHashKey]) {
+ var index = spatialHash[oldHashKey].indexOf(self);
+ if (index > -1) {
+ spatialHash[oldHashKey].splice(index, 1);
+ }
+ }
+ if (!spatialHash[newHashKey]) {
+ spatialHash[newHashKey] = [];
+ }
+ spatialHash[newHashKey].push(self);
+ }
+ // Continue moving upwards
+ if (wavePositionLabel === 'right') {
+ self.x -= 1.5;
+ } else if (wavePositionLabel === 'left') {
+ self.x += 1.5;
+ }
+ self.y += self.speed * speedMultiplier;
+ // Add unique behavior to obstacle5
+ self.rotation += 0.02; // Rotate at a different speed
+ self.scale.x = 1 + Math.sin(LK.ticks / 20) * 0.04; // Different size change
+ self.scale.y = 1 + Math.sin(LK.ticks / 20) * 0.04;
+ 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;
+ }
+ }
+ };
+});
+// Obstacle6 class
+var Obstacle6 = Container.expand(function () {
+ var self = Container.call(this);
+ var obstacle6Graphics = self.attachAsset('obstacle6', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.7,
+ scaleY: 0.7
+ });
+ // Set obstacle6 speed
+ self.speed = -5;
+ // This is automatically called every game tick, if the obstacle6 is attached!
+ self.update = function () {
+ // Check if the obstacle is colliding with the shield
+ if (self.intersects(shield, {
+ tolerance: 10
+ })) {
+ // Play bubble sound if at least 1 second has passed since the last play
+ if (LK.ticks - lastBubbleSoundTime > 20) {
+ LK.getSound('bubble').play();
+ lastBubbleSoundTime = LK.ticks;
+ }
+ // 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.children.find(function (child) {
+ return child.alpha === 0;
+ }), {
+ tolerance: 10
+ })) {
+ // 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();
+ }
+ // Update spatial hash
+ var oldHashX = Math.floor((self.x - self.speed * speedMultiplier) / cellSize);
+ var oldHashY = Math.floor((self.y - self.speed * speedMultiplier) / cellSize);
+ var newHashX = Math.floor(self.x / cellSize);
+ var newHashY = Math.floor(self.y / cellSize);
+ var oldHashKey = oldHashX + ',' + oldHashY;
+ var newHashKey = newHashX + ',' + newHashY;
+ if (oldHashKey !== newHashKey) {
+ if (spatialHash[oldHashKey]) {
+ var index = spatialHash[oldHashKey].indexOf(self);
+ if (index > -1) {
+ spatialHash[oldHashKey].splice(index, 1);
+ }
+ }
+ if (!spatialHash[newHashKey]) {
+ spatialHash[newHashKey] = [];
+ }
+ spatialHash[newHashKey].push(self);
+ }
+ // Continue moving upwards
+ if (wavePositionLabel === 'right') {
+ self.x -= 1.5;
+ } else if (wavePositionLabel === 'left') {
+ self.x += 1.5;
+ }
+ self.y += self.speed * speedMultiplier;
+ // Add unique behavior to obstacle6
+ self.rotation += 0.04; // Rotate at a different speed
+ self.scale.x = 1 + Math.sin(LK.ticks / 25) * 0.05; // Different size change
+ self.scale.y = 1 + Math.sin(LK.ticks / 25) * 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;
+ }
+ }
+ };
+});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
@@ -681,9 +978,9 @@
}
});
});
// Randomly choose an obstacle type for the entire wave
- var obstacleTypes = [Obstacle1, Obstacle2, Obstacle3];
+ var obstacleTypes = [Obstacle1, Obstacle2, Obstacle3, Obstacle4, Obstacle5, Obstacle6];
var obstacleType = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)];
// Randomly choose one of the three starting x positions for the entire wave
var startXPositions = [{
position: 2048 / 4.5,
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.