/****
* Classes
****/
var EnemyFish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('enemyFish', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 3 + 2;
self.size = (Math.random() * 1.0 + 1.0) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
// Class for the first obstacle
var Obstacle1 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle1', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 3 + 2;
self.size = (Math.random() * 4.5 + 4.0) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
var Obstacle2 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle2', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 3 + 2;
self.size = (Math.random() * 4.5 + 4.0) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
var Obstacle3 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle3', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 3 + 2;
self.size = (Math.random() * 4.5 + 4.0) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
// Class for the fifth obstacle
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the player's fish
var PlayerFish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('playerFish', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = 5;
self.size = 2.0 * 1.2;
self.update = function () {
// Move the player fish automatically to the right
// Removed automatic movement of player fish
};
self.grow = function () {
// Function intentionally left empty to keep player fish size constant
};
});
var RewardFish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('rewardFish', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI
});
self.speed = Math.random() * 2 + 1;
self.size = (Math.random() * 0.6 + 0.4) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
// Class for smaller fish
var SmallFish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('smallFish', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 2 + 1;
self.size = (Math.random() * 0.6 + 0.4) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0000ff // Init game with blue background to represent the ocean
});
/****
* Game Code
****/
//<Write imports for supported plugins here>
var oceanBackground = LK.getAsset('oceanBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(oceanBackground);
// Play background music continuously
LK.playMusic('games');
var lives = 4;
// Create heart shapes to represent lives
var heartShapes = [];
for (var i = 0; i < lives; i++) {
var heart = LK.getAsset('heartShape', {
anchorX: 0.5,
anchorY: 0.5,
x: 50 + i * 110,
// Position hearts with some spacing
y: 50
});
LK.gui.topLeft.addChild(heart);
heartShapes.push(heart);
}
// Function to update the life display
function updateLifeDisplay(lives) {
for (var i = 0; i < 4; i++) {
heartShapes[i].visible = i < lives; // Show or hide hearts based on remaining lives
}
}
// Create a score text object
var scoreText = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
// Set the anchor point to the top-right corner
scoreText.anchor.set(1, 0);
// Position the score text at the top-right corner of the screen
LK.gui.topRight.addChild(scoreText);
// Function to update the score display
function updateScoreDisplay(score) {
scoreText.setText('Score: ' + score);
}
// Initialize score
var score = 0;
// Example of updating the score
function increaseScore(amount) {
score += amount;
updateScoreDisplay(score);
}
var playerFish = game.addChild(new PlayerFish());
playerFish.x = 1024;
playerFish.y = 1366;
var enemyFishes = [];
for (var i = 0; i < 5; i++) {
var enemyFish = new EnemyFish();
enemyFish.x = Math.random() * 2048;
enemyFish.y = Math.random() * 2732;
enemyFishes.push(enemyFish);
game.addChild(enemyFish);
}
var smallFishes = [];
LK.setInterval(function () {
var smallFish = new SmallFish();
smallFish.x = Math.random() * 2048;
smallFish.y = -100; // Start above the screen
smallFishes.push(smallFish);
game.addChild(smallFish);
}, 3000); // Spawn a new small fish every 3 seconds
game.move = function (x, y, obj) {
// Ensure the player fish does not move directly under the cursor
playerFish.x = x;
playerFish.y = y - 189; // Adjust y position to be 5 cm above the cursor, assuming 1 cm is approximately 37.8 pixels on a standard screen
};
var obstacles = [];
for (var i = 0; i < 3; i++) {
var obstacle = new Obstacle1();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
for (var i = 0; i < 3; i++) {
var obstacle = new Obstacle2();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
for (var i = 0; i < 3; i++) {
var obstacle = new Obstacle3();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
var rewardFishes = [];
LK.setInterval(function () {
var rewardFish = new RewardFish();
rewardFish.x = Math.random() * 2048;
rewardFish.y = -100; // Start above the screen
rewardFishes.push(rewardFish);
game.addChild(rewardFish);
}, 2000); // Spawn a new reward fish every 2 seconds
var invincible = true;
LK.setTimeout(function () {
invincible = false;
}, 3000);
game.update = function () {
for (var i = 0; i < rewardFishes.length; i++) {
rewardFishes[i].update();
if (playerFish.intersects(rewardFishes[i])) {
rewardFishes[i].destroy();
rewardFishes.splice(i, 1);
i--;
increaseScore(2); // Increase score by 2 when intersecting reward fish
if (score % 30 === 0 && score !== 0 && lives < 4) {
// Check if score is a multiple of 30 and lives are less than 4
lives++; // Increase lives by 1
updateLifeDisplay(lives); // Update the life display
}
LK.getSound('collect').play(); // Play sound effect when collecting reward fish
}
}
for (var i = 0; i < enemyFishes.length; i++) {
enemyFishes[i].update();
if (playerFish.intersects(enemyFishes[i]) && !invincible) {
LK.getSound('obstacle').play(); // Play sound effect when colliding with a large enemy fish
lives--;
updateLifeDisplay(lives);
if (lives <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
console.log("Game Over! Your Score: " + score);
} else {
// Make player fish temporarily invincible after losing a life
invincible = true;
LK.setTimeout(function () {
invincible = false;
}, 1000); // 1 second of invincibility
}
}
}
for (var i = 0; i < smallFishes.length; i++) {
smallFishes[i].update();
if (playerFish.intersects(smallFishes[i])) {
playerFish.grow();
smallFishes[i].destroy();
smallFishes.splice(i, 1);
i--;
increaseScore(1); // Increase score by 1 when intersecting small fish
LK.getSound('collect').play(); // Play sound effect when collecting small fish
}
}
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].update();
if (playerFish.intersects(obstacles[i]) && !invincible) {
LK.getSound('obstacle').play(); // Play sound effect when colliding with an obstacle
lives--;
updateLifeDisplay(lives);
if (lives <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else {
// Make player fish temporarily invincible after losing a life
invincible = true;
LK.setTimeout(function () {
invincible = false;
}, 1000); // 1 second of invincibility
}
}
}
}; /****
* Classes
****/
var EnemyFish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('enemyFish', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 3 + 2;
self.size = (Math.random() * 1.0 + 1.0) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
// Class for the first obstacle
var Obstacle1 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle1', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 3 + 2;
self.size = (Math.random() * 4.5 + 4.0) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
var Obstacle2 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle2', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 3 + 2;
self.size = (Math.random() * 4.5 + 4.0) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
var Obstacle3 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle3', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 3 + 2;
self.size = (Math.random() * 4.5 + 4.0) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
// Class for the fifth obstacle
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the player's fish
var PlayerFish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('playerFish', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = 5;
self.size = 2.0 * 1.2;
self.update = function () {
// Move the player fish automatically to the right
// Removed automatic movement of player fish
};
self.grow = function () {
// Function intentionally left empty to keep player fish size constant
};
});
var RewardFish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('rewardFish', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI
});
self.speed = Math.random() * 2 + 1;
self.size = (Math.random() * 0.6 + 0.4) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
// Class for smaller fish
var SmallFish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('smallFish', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * 2 * Math.PI // Add random rotation
});
self.speed = Math.random() * 2 + 1;
self.size = (Math.random() * 0.6 + 0.4) * 1.2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0000ff // Init game with blue background to represent the ocean
});
/****
* Game Code
****/
//<Write imports for supported plugins here>
var oceanBackground = LK.getAsset('oceanBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(oceanBackground);
// Play background music continuously
LK.playMusic('games');
var lives = 4;
// Create heart shapes to represent lives
var heartShapes = [];
for (var i = 0; i < lives; i++) {
var heart = LK.getAsset('heartShape', {
anchorX: 0.5,
anchorY: 0.5,
x: 50 + i * 110,
// Position hearts with some spacing
y: 50
});
LK.gui.topLeft.addChild(heart);
heartShapes.push(heart);
}
// Function to update the life display
function updateLifeDisplay(lives) {
for (var i = 0; i < 4; i++) {
heartShapes[i].visible = i < lives; // Show or hide hearts based on remaining lives
}
}
// Create a score text object
var scoreText = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
// Set the anchor point to the top-right corner
scoreText.anchor.set(1, 0);
// Position the score text at the top-right corner of the screen
LK.gui.topRight.addChild(scoreText);
// Function to update the score display
function updateScoreDisplay(score) {
scoreText.setText('Score: ' + score);
}
// Initialize score
var score = 0;
// Example of updating the score
function increaseScore(amount) {
score += amount;
updateScoreDisplay(score);
}
var playerFish = game.addChild(new PlayerFish());
playerFish.x = 1024;
playerFish.y = 1366;
var enemyFishes = [];
for (var i = 0; i < 5; i++) {
var enemyFish = new EnemyFish();
enemyFish.x = Math.random() * 2048;
enemyFish.y = Math.random() * 2732;
enemyFishes.push(enemyFish);
game.addChild(enemyFish);
}
var smallFishes = [];
LK.setInterval(function () {
var smallFish = new SmallFish();
smallFish.x = Math.random() * 2048;
smallFish.y = -100; // Start above the screen
smallFishes.push(smallFish);
game.addChild(smallFish);
}, 3000); // Spawn a new small fish every 3 seconds
game.move = function (x, y, obj) {
// Ensure the player fish does not move directly under the cursor
playerFish.x = x;
playerFish.y = y - 189; // Adjust y position to be 5 cm above the cursor, assuming 1 cm is approximately 37.8 pixels on a standard screen
};
var obstacles = [];
for (var i = 0; i < 3; i++) {
var obstacle = new Obstacle1();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
for (var i = 0; i < 3; i++) {
var obstacle = new Obstacle2();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
for (var i = 0; i < 3; i++) {
var obstacle = new Obstacle3();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
var rewardFishes = [];
LK.setInterval(function () {
var rewardFish = new RewardFish();
rewardFish.x = Math.random() * 2048;
rewardFish.y = -100; // Start above the screen
rewardFishes.push(rewardFish);
game.addChild(rewardFish);
}, 2000); // Spawn a new reward fish every 2 seconds
var invincible = true;
LK.setTimeout(function () {
invincible = false;
}, 3000);
game.update = function () {
for (var i = 0; i < rewardFishes.length; i++) {
rewardFishes[i].update();
if (playerFish.intersects(rewardFishes[i])) {
rewardFishes[i].destroy();
rewardFishes.splice(i, 1);
i--;
increaseScore(2); // Increase score by 2 when intersecting reward fish
if (score % 30 === 0 && score !== 0 && lives < 4) {
// Check if score is a multiple of 30 and lives are less than 4
lives++; // Increase lives by 1
updateLifeDisplay(lives); // Update the life display
}
LK.getSound('collect').play(); // Play sound effect when collecting reward fish
}
}
for (var i = 0; i < enemyFishes.length; i++) {
enemyFishes[i].update();
if (playerFish.intersects(enemyFishes[i]) && !invincible) {
LK.getSound('obstacle').play(); // Play sound effect when colliding with a large enemy fish
lives--;
updateLifeDisplay(lives);
if (lives <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
console.log("Game Over! Your Score: " + score);
} else {
// Make player fish temporarily invincible after losing a life
invincible = true;
LK.setTimeout(function () {
invincible = false;
}, 1000); // 1 second of invincibility
}
}
}
for (var i = 0; i < smallFishes.length; i++) {
smallFishes[i].update();
if (playerFish.intersects(smallFishes[i])) {
playerFish.grow();
smallFishes[i].destroy();
smallFishes.splice(i, 1);
i--;
increaseScore(1); // Increase score by 1 when intersecting small fish
LK.getSound('collect').play(); // Play sound effect when collecting small fish
}
}
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].update();
if (playerFish.intersects(obstacles[i]) && !invincible) {
LK.getSound('obstacle').play(); // Play sound effect when colliding with an obstacle
lives--;
updateLifeDisplay(lives);
if (lives <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else {
// Make player fish temporarily invincible after losing a life
invincible = true;
LK.setTimeout(function () {
invincible = false;
}, 1000); // 1 second of invincibility
}
}
}
};
korkuç köpekbalığ 2d Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
korkunç denizanası. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sevimli solucan. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
kalp. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
okyanus içi. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
kötü balık. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
daha gösterişli altın para
kötü yengeç. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
güzel ve sevimli bir kırmızı balık. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows