User prompt
engeller daha fazla ve daha büyük olsun. tavana değdiğimizde ölelim. ve bazı bölgelere skor yapmak için coin yerleştir.
Code edit (1 edits merged)
Please save this source code
User prompt
Ocean Dive - Fish Swimming Adventure
Initial prompt
Create a 2D endless runner game inspired by Flappy Bird mechanics. The player controls a cute fish character that swims forward automatically. Instead of pipes, the obstacles are various sea creatures, such as sharks, that move horizontally from right to left trying to collide with the fish. The background must depict an underwater ocean floor scene with suitable visuals. Game requirements: - The fish responds to user input (tap/click) by swimming upwards with a smooth animation, otherwise it gradually sinks due to gravity. - Obstacles spawn at regular but tight intervals with varying vertical positions to increase difficulty. - Implement collision detection between the fish and obstacles, resulting in game over. - A real-time scoreboard is displayed, showing the player's current score based on how long they survive or how many obstacles they pass. - The game must be mobile-friendly and use full screen with responsive canvas. - Use simple, clean 2D sprite graphics for the fish and sea creatures. - Background should be static but visually represent the ocean floor underwater environment.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.8;
self.swimForce = -12;
self.swim = function () {
self.velocityY = self.swimForce;
LK.getSound('swim').play();
// Animate swim effect
tween(fishGraphics, {
rotation: -0.3
}, {
duration: 150,
easing: tween.easeOut
});
tween(fishGraphics, {
rotation: 0
}, {
duration: 300,
easing: tween.easeIn
});
};
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
self.y += self.velocityY;
// Rotate fish based on velocity
fishGraphics.rotation = Math.max(-0.5, Math.min(0.5, self.velocityY * 0.05));
// Keep fish within screen bounds
if (self.y < 50) {
self.y = 50;
self.velocityY = 0;
}
if (self.y > 2400) {
self.y = 2400;
self.velocityY = 0;
}
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('shark', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -4;
self.passed = false;
self.update = function () {
self.x += self.speed;
};
return self;
});
var SeaDecoration = Container.expand(function (type) {
var self = Container.call(this);
var decorationGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = -1;
self.update = function () {
self.x += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x006994
});
/****
* Game Code
****/
// Game variables
var fish;
var obstacles = [];
var decorations = [];
var spawnTimer = 0;
var decorationTimer = 0;
var gameSpeed = 1;
var lastObstacleY = 0;
// Create ocean floor
var oceanFloor = game.addChild(LK.getAsset('oceanFloor', {
anchorX: 0,
anchorY: 1.0,
x: 0,
y: 2732
}));
// Create fish
fish = game.addChild(new Fish());
fish.x = 300;
fish.y = 1366;
// Create score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
scoreTxt.x = -150; // Offset from right edge
// Spawn obstacle function
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = 2200;
// Random Y position, but not too close to last obstacle
var minY = 200;
var maxY = 2200;
var targetY;
do {
targetY = minY + Math.random() * (maxY - minY);
} while (Math.abs(targetY - lastObstacleY) < 300);
obstacle.y = targetY;
lastObstacleY = targetY;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Spawn decoration function
function spawnDecoration() {
var decorationType = Math.random() > 0.5 ? 'seaweed' : 'coral';
var decoration = new SeaDecoration(decorationType);
decoration.x = 2200;
decoration.y = 2732 - 150; // Near ocean floor
decorations.push(decoration);
game.addChild(decoration);
}
// Game input handling
game.down = function (x, y, obj) {
fish.swim();
};
// Main game update loop
game.update = function () {
// Update spawn timers
spawnTimer++;
decorationTimer++;
// Spawn obstacles
var spawnRate = Math.max(60, 120 - Math.floor(LK.ticks / 1800)); // Increase difficulty over time
if (spawnTimer >= spawnRate) {
spawnObstacle();
spawnTimer = 0;
}
// Spawn decorations less frequently
if (decorationTimer >= 180) {
spawnDecoration();
decorationTimer = 0;
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
// Check if obstacle passed fish (for scoring)
if (!obstacle.passed && obstacle.x < fish.x) {
obstacle.passed = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
}
// Remove obstacles that are off screen
if (obstacle.x < -150) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Collision detection
if (fish.intersects(obstacle)) {
LK.getSound('collision').play();
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
return;
}
}
// Update decorations
for (var j = decorations.length - 1; j >= 0; j--) {
var decoration = decorations[j];
// Remove decorations that are off screen
if (decoration.x < -100) {
decoration.destroy();
decorations.splice(j, 1);
}
}
// Check if fish hit ocean floor
if (fish.y >= 2600) {
LK.getSound('collision').play();
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
// Increase game speed gradually
if (LK.ticks % 600 == 0) {
gameSpeed += 0.1;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,203 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Fish = Container.expand(function () {
+ var self = Container.call(this);
+ var fishGraphics = self.attachAsset('fish', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocityY = 0;
+ self.gravity = 0.8;
+ self.swimForce = -12;
+ self.swim = function () {
+ self.velocityY = self.swimForce;
+ LK.getSound('swim').play();
+ // Animate swim effect
+ tween(fishGraphics, {
+ rotation: -0.3
+ }, {
+ duration: 150,
+ easing: tween.easeOut
+ });
+ tween(fishGraphics, {
+ rotation: 0
+ }, {
+ duration: 300,
+ easing: tween.easeIn
+ });
+ };
+ self.update = function () {
+ // Apply gravity
+ self.velocityY += self.gravity;
+ self.y += self.velocityY;
+ // Rotate fish based on velocity
+ fishGraphics.rotation = Math.max(-0.5, Math.min(0.5, self.velocityY * 0.05));
+ // Keep fish within screen bounds
+ if (self.y < 50) {
+ self.y = 50;
+ self.velocityY = 0;
+ }
+ if (self.y > 2400) {
+ self.y = 2400;
+ self.velocityY = 0;
+ }
+ };
+ return self;
+});
+var Obstacle = Container.expand(function () {
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('shark', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -4;
+ self.passed = false;
+ self.update = function () {
+ self.x += self.speed;
+ };
+ return self;
+});
+var SeaDecoration = Container.expand(function (type) {
+ var self = Container.call(this);
+ var decorationGraphics = self.attachAsset(type, {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.speed = -1;
+ self.update = function () {
+ self.x += self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x006994
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var fish;
+var obstacles = [];
+var decorations = [];
+var spawnTimer = 0;
+var decorationTimer = 0;
+var gameSpeed = 1;
+var lastObstacleY = 0;
+// Create ocean floor
+var oceanFloor = game.addChild(LK.getAsset('oceanFloor', {
+ anchorX: 0,
+ anchorY: 1.0,
+ x: 0,
+ y: 2732
+}));
+// Create fish
+fish = game.addChild(new Fish());
+fish.x = 300;
+fish.y = 1366;
+// Create score display
+var scoreTxt = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0, 0);
+LK.gui.topRight.addChild(scoreTxt);
+scoreTxt.x = -150; // Offset from right edge
+// Spawn obstacle function
+function spawnObstacle() {
+ var obstacle = new Obstacle();
+ obstacle.x = 2200;
+ // Random Y position, but not too close to last obstacle
+ var minY = 200;
+ var maxY = 2200;
+ var targetY;
+ do {
+ targetY = minY + Math.random() * (maxY - minY);
+ } while (Math.abs(targetY - lastObstacleY) < 300);
+ obstacle.y = targetY;
+ lastObstacleY = targetY;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
+}
+// Spawn decoration function
+function spawnDecoration() {
+ var decorationType = Math.random() > 0.5 ? 'seaweed' : 'coral';
+ var decoration = new SeaDecoration(decorationType);
+ decoration.x = 2200;
+ decoration.y = 2732 - 150; // Near ocean floor
+ decorations.push(decoration);
+ game.addChild(decoration);
+}
+// Game input handling
+game.down = function (x, y, obj) {
+ fish.swim();
+};
+// Main game update loop
+game.update = function () {
+ // Update spawn timers
+ spawnTimer++;
+ decorationTimer++;
+ // Spawn obstacles
+ var spawnRate = Math.max(60, 120 - Math.floor(LK.ticks / 1800)); // Increase difficulty over time
+ if (spawnTimer >= spawnRate) {
+ spawnObstacle();
+ spawnTimer = 0;
+ }
+ // Spawn decorations less frequently
+ if (decorationTimer >= 180) {
+ spawnDecoration();
+ decorationTimer = 0;
+ }
+ // Update obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ var obstacle = obstacles[i];
+ // Check if obstacle passed fish (for scoring)
+ if (!obstacle.passed && obstacle.x < fish.x) {
+ obstacle.passed = true;
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ }
+ // Remove obstacles that are off screen
+ if (obstacle.x < -150) {
+ obstacle.destroy();
+ obstacles.splice(i, 1);
+ continue;
+ }
+ // Collision detection
+ if (fish.intersects(obstacle)) {
+ LK.getSound('collision').play();
+ LK.effects.flashScreen(0xFF0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Update decorations
+ for (var j = decorations.length - 1; j >= 0; j--) {
+ var decoration = decorations[j];
+ // Remove decorations that are off screen
+ if (decoration.x < -100) {
+ decoration.destroy();
+ decorations.splice(j, 1);
+ }
+ }
+ // Check if fish hit ocean floor
+ if (fish.y >= 2600) {
+ LK.getSound('collision').play();
+ LK.effects.flashScreen(0xFF0000, 1000);
+ LK.showGameOver();
+ }
+ // Increase game speed gradually
+ if (LK.ticks % 600 == 0) {
+ gameSpeed += 0.1;
+ }
+};
\ No newline at end of file