/**** * Classes ****/ // Define a class for the air bubbles var AirBubble = Container.expand(function () { var self = Container.call(this); var airBubbleGraphics = self.attachAsset('airBubble', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } }; }); //<Write imports for supported plugins here> // Define a class for the bubble var Bubble = Container.expand(function () { var self = Container.call(this); var bubbleGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Update logic for bubble }; }); var Jellyfish = Container.expand(function () { var self = Container.call(this); var jellyfishGraphics = self.attachAsset('jellyfish', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } }; }); // Define a class for the octopus var Octopus = Container.expand(function () { var self = Container.call(this); var octopusGraphics = self.attachAsset('octopus', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } }; }); // Define a class for rocks var Rock = Container.expand(function () { var self = Container.call(this); var rockGraphics = self.attachAsset('rock', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } }; }); // Define a class for the whale var Whale = Container.expand(function () { var self = Container.call(this); var whaleGraphics = self.attachAsset('whale', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000, //Init game with black background name: "Deep Sea Feast" }); /**** * Game Code ****/ LK.playMusic('backgroundMusic'); // Attach the background image to the game var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(background); var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); // Center the score text horizontally LK.gui.top.addChild(scoreTxt); // Add the score text to the GUI overlay var bubble = game.addChild(new Bubble()); bubble.x = 1024; bubble.y = 2500; // Initialize octopuses var octopuses = []; function spawnOctopus() { var octopus = new Octopus(); octopus.x = Math.random() * 2048; octopus.y = 0; // Start from the top octopuses.push(octopus); game.addChild(octopus); } LK.setInterval(spawnOctopus, 2000); // Spawn an octopus every 2 seconds // Initialize jellyfish var jellyfishes = []; function spawnJellyfish() { var jellyfish = new Jellyfish(); jellyfish.x = Math.random() * 2048; jellyfish.y = 0; // Start from the top jellyfishes.push(jellyfish); game.addChild(jellyfish); } LK.setInterval(spawnJellyfish, 3000); // Spawn a jellyfish every 3 seconds // Initialize whales var whales = []; function spawnWhale() { var whale = new Whale(); whale.x = Math.random() * 2048; whale.y = 0; // Start from the top whales.push(whale); game.addChild(whale); } LK.setInterval(spawnWhale, 5000); // Spawn a whale every 5 seconds // Initialize air bubbles var airBubbles = []; function spawnAirBubble() { var airBubble = new AirBubble(); airBubble.x = Math.random() * 2048; airBubble.y = 0; // Start from the top airBubbles.push(airBubble); game.addChild(airBubble); } LK.setInterval(spawnAirBubble, 1000); // Spawn an air bubble every second // Handle player movement game.move = function (x, y, obj) { bubble.x = x; bubble.y = y; }; // Remove shooting functionality game.down = function (x, y, obj) {}; // Update game state game.update = function () { // Update octopuses for (var i = 0; i < octopuses.length; i++) { octopuses[i].update(); // Check for collisions between bubble and octopuses if (bubble.intersects(octopuses[i])) { // Simulate octopus holding the player with its legs octopuses[i].scaleX = 1.2; octopuses[i].scaleY = 1.2; octopuses[i].rotation = Math.PI / 4; // Rotate to simulate holding LK.setTimeout(function () { octopuses[i].scaleX = 1.0; octopuses[i].scaleY = 1.0; octopuses[i].rotation = 0; // Reset rotation }, 500); // Reset after 500ms // Game over if bubble collides with an octopus LK.showGameOver(); } } // Update jellyfish for (var i = 0; i < jellyfishes.length; i++) { jellyfishes[i].update(); // Check for collisions between bubble and jellyfish if (bubble.intersects(jellyfishes[i])) { // Game over if bubble collides with a jellyfish LK.showGameOver(); } } // Update whales for (var i = 0; i < whales.length; i++) { whales[i].update(); // Check for collisions between bubble and whales if (bubble.intersects(whales[i])) { // Simulate whale opening mouth and eating the player whales[i].scaleX = 1.5; whales[i].scaleY = 1.5; whales[i].rotation = Math.PI / 8; // Slight rotation to simulate mouth opening LK.setTimeout(function () { whales[i].scaleX = 1.0; whales[i].scaleY = 1.0; whales[i].rotation = 0; // Reset rotation }, 500); // Reset after 500ms // Game over if bubble collides with a whale LK.showGameOver(); } } // Update air bubbles for (var i = 0; i < airBubbles.length; i++) { airBubbles[i].update(); // Check for collisions between bubble and air bubbles if (bubble.intersects(airBubbles[i])) { // Play bubble sound effect LK.getSound('bubbleSound').play(); // Simulate eating animation by scaling the player fish bubble.scaleX = 1.2; bubble.scaleY = 1.2; LK.setTimeout(function () { bubble.scaleX = 1.0; bubble.scaleY = 1.0; }, 200); // Reset scale after 200ms // Increase score by 2 points if bubble collides with an air bubble LK.setScore(LK.getScore() + 2); scoreTxt.setText(LK.getScore()); // Update the score text airBubbles[i].destroy(); airBubbles.splice(i, 1); } } };
/****
* Classes
****/
// Define a class for the air bubbles
var AirBubble = Container.expand(function () {
var self = Container.call(this);
var airBubbleGraphics = self.attachAsset('airBubble', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
});
//<Write imports for supported plugins here>
// Define a class for the bubble
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Update logic for bubble
};
});
var Jellyfish = Container.expand(function () {
var self = Container.call(this);
var jellyfishGraphics = self.attachAsset('jellyfish', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
});
// Define a class for the octopus
var Octopus = Container.expand(function () {
var self = Container.call(this);
var octopusGraphics = self.attachAsset('octopus', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
});
// Define a class for rocks
var Rock = Container.expand(function () {
var self = Container.call(this);
var rockGraphics = self.attachAsset('rock', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
});
// Define a class for the whale
var Whale = Container.expand(function () {
var self = Container.call(this);
var whaleGraphics = self.attachAsset('whale', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000,
//Init game with black background
name: "Deep Sea Feast"
});
/****
* Game Code
****/
LK.playMusic('backgroundMusic');
// Attach the background image to the game
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0); // Center the score text horizontally
LK.gui.top.addChild(scoreTxt); // Add the score text to the GUI overlay
var bubble = game.addChild(new Bubble());
bubble.x = 1024;
bubble.y = 2500;
// Initialize octopuses
var octopuses = [];
function spawnOctopus() {
var octopus = new Octopus();
octopus.x = Math.random() * 2048;
octopus.y = 0; // Start from the top
octopuses.push(octopus);
game.addChild(octopus);
}
LK.setInterval(spawnOctopus, 2000); // Spawn an octopus every 2 seconds
// Initialize jellyfish
var jellyfishes = [];
function spawnJellyfish() {
var jellyfish = new Jellyfish();
jellyfish.x = Math.random() * 2048;
jellyfish.y = 0; // Start from the top
jellyfishes.push(jellyfish);
game.addChild(jellyfish);
}
LK.setInterval(spawnJellyfish, 3000); // Spawn a jellyfish every 3 seconds
// Initialize whales
var whales = [];
function spawnWhale() {
var whale = new Whale();
whale.x = Math.random() * 2048;
whale.y = 0; // Start from the top
whales.push(whale);
game.addChild(whale);
}
LK.setInterval(spawnWhale, 5000); // Spawn a whale every 5 seconds
// Initialize air bubbles
var airBubbles = [];
function spawnAirBubble() {
var airBubble = new AirBubble();
airBubble.x = Math.random() * 2048;
airBubble.y = 0; // Start from the top
airBubbles.push(airBubble);
game.addChild(airBubble);
}
LK.setInterval(spawnAirBubble, 1000); // Spawn an air bubble every second
// Handle player movement
game.move = function (x, y, obj) {
bubble.x = x;
bubble.y = y;
};
// Remove shooting functionality
game.down = function (x, y, obj) {};
// Update game state
game.update = function () {
// Update octopuses
for (var i = 0; i < octopuses.length; i++) {
octopuses[i].update();
// Check for collisions between bubble and octopuses
if (bubble.intersects(octopuses[i])) {
// Simulate octopus holding the player with its legs
octopuses[i].scaleX = 1.2;
octopuses[i].scaleY = 1.2;
octopuses[i].rotation = Math.PI / 4; // Rotate to simulate holding
LK.setTimeout(function () {
octopuses[i].scaleX = 1.0;
octopuses[i].scaleY = 1.0;
octopuses[i].rotation = 0; // Reset rotation
}, 500); // Reset after 500ms
// Game over if bubble collides with an octopus
LK.showGameOver();
}
}
// Update jellyfish
for (var i = 0; i < jellyfishes.length; i++) {
jellyfishes[i].update();
// Check for collisions between bubble and jellyfish
if (bubble.intersects(jellyfishes[i])) {
// Game over if bubble collides with a jellyfish
LK.showGameOver();
}
}
// Update whales
for (var i = 0; i < whales.length; i++) {
whales[i].update();
// Check for collisions between bubble and whales
if (bubble.intersects(whales[i])) {
// Simulate whale opening mouth and eating the player
whales[i].scaleX = 1.5;
whales[i].scaleY = 1.5;
whales[i].rotation = Math.PI / 8; // Slight rotation to simulate mouth opening
LK.setTimeout(function () {
whales[i].scaleX = 1.0;
whales[i].scaleY = 1.0;
whales[i].rotation = 0; // Reset rotation
}, 500); // Reset after 500ms
// Game over if bubble collides with a whale
LK.showGameOver();
}
}
// Update air bubbles
for (var i = 0; i < airBubbles.length; i++) {
airBubbles[i].update();
// Check for collisions between bubble and air bubbles
if (bubble.intersects(airBubbles[i])) {
// Play bubble sound effect
LK.getSound('bubbleSound').play();
// Simulate eating animation by scaling the player fish
bubble.scaleX = 1.2;
bubble.scaleY = 1.2;
LK.setTimeout(function () {
bubble.scaleX = 1.0;
bubble.scaleY = 1.0;
}, 200); // Reset scale after 200ms
// Increase score by 2 points if bubble collides with an air bubble
LK.setScore(LK.getScore() + 2);
scoreTxt.setText(LK.getScore()); // Update the score text
airBubbles[i].destroy();
airBubbles.splice(i, 1);
}
}
};
fish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
whale. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
small gold ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
octopus. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
under water background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows