/**** * Classes ****/ var BubbleSpawner = Container.expand(function () { var self = Container.call(this); return self; }); var Fish = Container.expand(function () { var self = Container.call(this); Fish.prototype.pushAway = function (urchin) { this.pushed = true; this.pushDirection = { x: this.x - urchin.x, y: this.y - urchin.y }; var pushMagnitude = Math.sqrt(this.pushDirection.x * this.pushDirection.x + this.pushDirection.y * this.pushDirection.y); this.pushDirection.x /= pushMagnitude; this.pushDirection.y /= pushMagnitude; }; var fishGraphics = self.attachAsset('fish', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.move = function (urchinX, urchinY) { var dx = urchinX - this.x; var dy = urchinY - this.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 340) { var directionX = dx > 0 ? 1 : -1; var directionY = dy > 0 ? 1 : -1; this.x -= this.speed * directionX; this.y -= this.speed * directionY; fishGraphics.scale.x = -directionX; } }; }); var Food = Container.expand(function () { var self = Container.call(this); var foodGraphics = self.attachAsset('food', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; self.move = function () { this.y += this.speed; }; }); var StartButton = Container.expand(function () { var self = Container.call(this); var startButtonGraphics = self.attachAsset('startButton', { anchorX: 0.5, anchorY: 0.5 }); }); var Urchin = Container.expand(function () { var self = Container.call(this); var urchinGraphics = self.attachAsset('urchinWithSpikes', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.move = function (deltaX, deltaY) { var inertia = 0.95; var maxSpeed = 5; this.vx = (this.vx || 0) * inertia + deltaX * 0.05; this.vy = (this.vy || 0) * inertia + deltaY * 0.05; this.vx = Math.sign(this.vx) * Math.min(Math.abs(this.vx), maxSpeed); this.vy = Math.sign(this.vy) * Math.min(Math.abs(this.vy), maxSpeed); if (!this.stunned) { this.x += this.vx; this.y += this.vy; } else if (this.stunDuration > 0) { this.rotation += this.rotationSpeed; this.stunDuration--; if (this.stunDuration <= 0) { this.stunned = false; this.rotation = 0; this.vx = 0; this.vy = 0; if (this.scale.x > 1) { this.scale.set(1); } } } }; self.pushCooldown = 0; self.stunDuration = 0; self.stunned = false; self.hasPushed = false; self.push = function () { if (!this.stunned) { this.hasPushed = true; this.scale.set(2); } }; self.stun = function () { if (this.scale.x <= 1) { this.stunDuration = 60; this.stunned = true; this.rotationSpeed = 2 * Math.PI / this.stunDuration; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var bubbleSpawner = game.addChild(new BubbleSpawner()); var background = game.attachAsset('background', { anchorX: 0.5, anchorY: 0.5 }); background.alpha = 0.5; background.x = 2048 / 2; background.y = 2732 / 2; game.addChildAt(background, 0); game.setBackgroundColor(0x000000); var urchin = game.addChild(new Urchin()); var startButton = game.addChild(new StartButton()); startButton.x = 2048 / 2; startButton.y = 2732 / 2; var fishes = []; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); LK.gui.top.addChild(scoreTxt); urchin.x = 2048 / 2; urchin.y = 2732 / 2; var dragNode = null; startButton.on('down', function (obj) { startButton.destroy(); game.on('down', function (obj) { var event = obj.event; var pos = event.getLocalPosition(game); var distance = Math.sqrt(Math.pow(pos.x - urchin.x, 2) + Math.pow(pos.y - urchin.y, 2)); if (distance <= urchin.width / 2) { dragNode = urchin; } else { urchin.push(); } }); function handleMove(obj) { var event = obj.event; var pos = event.getLocalPosition(game); if (dragNode) { dragNode.x = pos.x; dragNode.y = pos.y; } } game.on('move', handleMove); }); game.on('up', function (obj) { dragNode = null; urchin.scale.set(1); }); LK.on('tick', function () { urchin.move(); if (urchin.pushCooldown > 0) { urchin.pushCooldown--; if (urchin.scale.x > 1) { urchin.scale.set(urchin.scale.x - 0.02); } } for (var i = game.children.length - 1; i >= 0; i--) { var child = game.children[i]; if (child instanceof Food) { child.move(); if (child.y > 2732) { child.destroy(); } else if (urchin.intersects(child)) { child.destroy(); LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore().toString()); // Check if score is a multiple of 10 and show congrats graphic if (LK.getScore() % 10 === 0) { var congratsGraphic = LK.getAsset('congrats', { anchorX: 0.5, anchorY: 0.5 }); // Store original state before any transformations for congratsGraphic congratsGraphic.originalState = { x: congratsGraphic.x, y: congratsGraphic.y, scaleX: congratsGraphic.scaleX, scaleY: congratsGraphic.scaleY, rotation: congratsGraphic.rotation }; congratsGraphic.x = 2048 - 700 / 2; congratsGraphic.y = 2732 - 790 / 2; game.addChild(congratsGraphic); // Initialize and display wowGraphic left of the congrats graphic var wowGraphic = LK.getAsset('wowGraphic', { anchorX: 0.5, anchorY: 0.5 }); // Store original state before any transformations for wowGraphic wowGraphic.originalState = { x: wowGraphic.x, y: wowGraphic.y, scaleX: wowGraphic.scaleX, scaleY: wowGraphic.scaleY, rotation: wowGraphic.rotation }; // Move wowGraphic closer right to the congrats graphic wowGraphic.x = congratsGraphic.x - congratsGraphic.width / 2 - wowGraphic.width / 2 - 10; // Reduced padding to 10 pixels wowGraphic.y = congratsGraphic.y - congratsGraphic.height / 2 + wowGraphic.height / 2; game.addChild(wowGraphic); // Destroy congrats and wow graphics after 3 seconds and reset to original state LK.setTimeout(function () { congratsGraphic.x = congratsGraphic.originalState.x; congratsGraphic.y = congratsGraphic.originalState.y; congratsGraphic.scaleX = congratsGraphic.originalState.scaleX; congratsGraphic.scaleY = congratsGraphic.originalState.scaleY; congratsGraphic.rotation = congratsGraphic.originalState.rotation; congratsGraphic.destroy(); wowGraphic.x = wowGraphic.originalState.x; wowGraphic.y = wowGraphic.originalState.y; wowGraphic.scaleX = wowGraphic.originalState.scaleX; wowGraphic.scaleY = wowGraphic.originalState.scaleY; wowGraphic.rotation = wowGraphic.originalState.rotation; wowGraphic.destroy(); }, 3000); } } } } for (var i = 0; i < fishes.length; i++) { fishes[i].move(urchin.x, urchin.y); if (urchin.intersects(fishes[i])) { if (!urchin.stunned) { if (urchin.hasPushed && !fishes[i].pushed) { fishes[i].pushAway(urchin); scoreTxt.text = (Number(scoreTxt.text) + 1).toString(); urchin.hasPushed = false; } else if (!urchin.hasPushed) { urchin.stun(); } } } } var foodCount = game.children.filter(function (child) { return child instanceof Food; }).length; if (Math.random() < 0.01 && foodCount < 20) { var newFood = new Food(); newFood.x = Math.random() * 2048; newFood.y = 0; game.addChild(newFood); } if (fishes.length < 20) { var newFish = new Fish(); var side = Math.floor(Math.random() * 4); var targetX, targetY; switch (side) { case 0: newFish.x = -100; newFish.y = Math.random() * 2732; targetX = 2048 + 100; targetY = newFish.y; break; case 1: newFish.x = Math.random() * 2048; newFish.y = -100; targetX = newFish.x; targetY = 2732 + 100; break; case 2: newFish.x = 2048 + 100; newFish.y = Math.random() * 2732; targetX = -100; targetY = newFish.y; break; case 3: newFish.x = Math.random() * 2048; newFish.y = 2732 + 100; targetX = newFish.x; targetY = -100; break; } newFish.move = function () { if (this.pushed) { this.x += this.pushDirection.x * 20; this.y += this.pushDirection.y * 20; if (this.x < -100 || this.x > 2148 || this.y < -100 || this.y > 2832) { this.destroy(); } } else { // Dynamically update target position if fish reaches current target if (Math.abs(this.x - targetX) < 10 && Math.abs(this.y - targetY) < 10) { // Choose new target position within game boundaries targetX = Math.random() * 2048; targetY = Math.random() * 2732; } var dx = targetX - this.x; var dy = targetY - this.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { var angle = Math.atan2(dy, dx); this.x += Math.cos(angle) * this.speed; this.y += Math.sin(angle) * this.speed; } } }; fishes.push(newFish); game.addChild(newFish); } });
/****
* Classes
****/
var BubbleSpawner = Container.expand(function () {
var self = Container.call(this);
return self;
});
var Fish = Container.expand(function () {
var self = Container.call(this);
Fish.prototype.pushAway = function (urchin) {
this.pushed = true;
this.pushDirection = {
x: this.x - urchin.x,
y: this.y - urchin.y
};
var pushMagnitude = Math.sqrt(this.pushDirection.x * this.pushDirection.x + this.pushDirection.y * this.pushDirection.y);
this.pushDirection.x /= pushMagnitude;
this.pushDirection.y /= pushMagnitude;
};
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.move = function (urchinX, urchinY) {
var dx = urchinX - this.x;
var dy = urchinY - this.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 340) {
var directionX = dx > 0 ? 1 : -1;
var directionY = dy > 0 ? 1 : -1;
this.x -= this.speed * directionX;
this.y -= this.speed * directionY;
fishGraphics.scale.x = -directionX;
}
};
});
var Food = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.attachAsset('food', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
self.move = function () {
this.y += this.speed;
};
});
var StartButton = Container.expand(function () {
var self = Container.call(this);
var startButtonGraphics = self.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5
});
});
var Urchin = Container.expand(function () {
var self = Container.call(this);
var urchinGraphics = self.attachAsset('urchinWithSpikes', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.move = function (deltaX, deltaY) {
var inertia = 0.95;
var maxSpeed = 5;
this.vx = (this.vx || 0) * inertia + deltaX * 0.05;
this.vy = (this.vy || 0) * inertia + deltaY * 0.05;
this.vx = Math.sign(this.vx) * Math.min(Math.abs(this.vx), maxSpeed);
this.vy = Math.sign(this.vy) * Math.min(Math.abs(this.vy), maxSpeed);
if (!this.stunned) {
this.x += this.vx;
this.y += this.vy;
} else if (this.stunDuration > 0) {
this.rotation += this.rotationSpeed;
this.stunDuration--;
if (this.stunDuration <= 0) {
this.stunned = false;
this.rotation = 0;
this.vx = 0;
this.vy = 0;
if (this.scale.x > 1) {
this.scale.set(1);
}
}
}
};
self.pushCooldown = 0;
self.stunDuration = 0;
self.stunned = false;
self.hasPushed = false;
self.push = function () {
if (!this.stunned) {
this.hasPushed = true;
this.scale.set(2);
}
};
self.stun = function () {
if (this.scale.x <= 1) {
this.stunDuration = 60;
this.stunned = true;
this.rotationSpeed = 2 * Math.PI / this.stunDuration;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var bubbleSpawner = game.addChild(new BubbleSpawner());
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
background.alpha = 0.5;
background.x = 2048 / 2;
background.y = 2732 / 2;
game.addChildAt(background, 0);
game.setBackgroundColor(0x000000);
var urchin = game.addChild(new Urchin());
var startButton = game.addChild(new StartButton());
startButton.x = 2048 / 2;
startButton.y = 2732 / 2;
var fishes = [];
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
urchin.x = 2048 / 2;
urchin.y = 2732 / 2;
var dragNode = null;
startButton.on('down', function (obj) {
startButton.destroy();
game.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
var distance = Math.sqrt(Math.pow(pos.x - urchin.x, 2) + Math.pow(pos.y - urchin.y, 2));
if (distance <= urchin.width / 2) {
dragNode = urchin;
} else {
urchin.push();
}
});
function handleMove(obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
if (dragNode) {
dragNode.x = pos.x;
dragNode.y = pos.y;
}
}
game.on('move', handleMove);
});
game.on('up', function (obj) {
dragNode = null;
urchin.scale.set(1);
});
LK.on('tick', function () {
urchin.move();
if (urchin.pushCooldown > 0) {
urchin.pushCooldown--;
if (urchin.scale.x > 1) {
urchin.scale.set(urchin.scale.x - 0.02);
}
}
for (var i = game.children.length - 1; i >= 0; i--) {
var child = game.children[i];
if (child instanceof Food) {
child.move();
if (child.y > 2732) {
child.destroy();
} else if (urchin.intersects(child)) {
child.destroy();
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore().toString());
// Check if score is a multiple of 10 and show congrats graphic
if (LK.getScore() % 10 === 0) {
var congratsGraphic = LK.getAsset('congrats', {
anchorX: 0.5,
anchorY: 0.5
});
// Store original state before any transformations for congratsGraphic
congratsGraphic.originalState = {
x: congratsGraphic.x,
y: congratsGraphic.y,
scaleX: congratsGraphic.scaleX,
scaleY: congratsGraphic.scaleY,
rotation: congratsGraphic.rotation
};
congratsGraphic.x = 2048 - 700 / 2;
congratsGraphic.y = 2732 - 790 / 2;
game.addChild(congratsGraphic);
// Initialize and display wowGraphic left of the congrats graphic
var wowGraphic = LK.getAsset('wowGraphic', {
anchorX: 0.5,
anchorY: 0.5
});
// Store original state before any transformations for wowGraphic
wowGraphic.originalState = {
x: wowGraphic.x,
y: wowGraphic.y,
scaleX: wowGraphic.scaleX,
scaleY: wowGraphic.scaleY,
rotation: wowGraphic.rotation
};
// Move wowGraphic closer right to the congrats graphic
wowGraphic.x = congratsGraphic.x - congratsGraphic.width / 2 - wowGraphic.width / 2 - 10; // Reduced padding to 10 pixels
wowGraphic.y = congratsGraphic.y - congratsGraphic.height / 2 + wowGraphic.height / 2;
game.addChild(wowGraphic);
// Destroy congrats and wow graphics after 3 seconds and reset to original state
LK.setTimeout(function () {
congratsGraphic.x = congratsGraphic.originalState.x;
congratsGraphic.y = congratsGraphic.originalState.y;
congratsGraphic.scaleX = congratsGraphic.originalState.scaleX;
congratsGraphic.scaleY = congratsGraphic.originalState.scaleY;
congratsGraphic.rotation = congratsGraphic.originalState.rotation;
congratsGraphic.destroy();
wowGraphic.x = wowGraphic.originalState.x;
wowGraphic.y = wowGraphic.originalState.y;
wowGraphic.scaleX = wowGraphic.originalState.scaleX;
wowGraphic.scaleY = wowGraphic.originalState.scaleY;
wowGraphic.rotation = wowGraphic.originalState.rotation;
wowGraphic.destroy();
}, 3000);
}
}
}
}
for (var i = 0; i < fishes.length; i++) {
fishes[i].move(urchin.x, urchin.y);
if (urchin.intersects(fishes[i])) {
if (!urchin.stunned) {
if (urchin.hasPushed && !fishes[i].pushed) {
fishes[i].pushAway(urchin);
scoreTxt.text = (Number(scoreTxt.text) + 1).toString();
urchin.hasPushed = false;
} else if (!urchin.hasPushed) {
urchin.stun();
}
}
}
}
var foodCount = game.children.filter(function (child) {
return child instanceof Food;
}).length;
if (Math.random() < 0.01 && foodCount < 20) {
var newFood = new Food();
newFood.x = Math.random() * 2048;
newFood.y = 0;
game.addChild(newFood);
}
if (fishes.length < 20) {
var newFish = new Fish();
var side = Math.floor(Math.random() * 4);
var targetX, targetY;
switch (side) {
case 0:
newFish.x = -100;
newFish.y = Math.random() * 2732;
targetX = 2048 + 100;
targetY = newFish.y;
break;
case 1:
newFish.x = Math.random() * 2048;
newFish.y = -100;
targetX = newFish.x;
targetY = 2732 + 100;
break;
case 2:
newFish.x = 2048 + 100;
newFish.y = Math.random() * 2732;
targetX = -100;
targetY = newFish.y;
break;
case 3:
newFish.x = Math.random() * 2048;
newFish.y = 2732 + 100;
targetX = newFish.x;
targetY = -100;
break;
}
newFish.move = function () {
if (this.pushed) {
this.x += this.pushDirection.x * 20;
this.y += this.pushDirection.y * 20;
if (this.x < -100 || this.x > 2148 || this.y < -100 || this.y > 2832) {
this.destroy();
}
} else {
// Dynamically update target position if fish reaches current target
if (Math.abs(this.x - targetX) < 10 && Math.abs(this.y - targetY) < 10) {
// Choose new target position within game boundaries
targetX = Math.random() * 2048;
targetY = Math.random() * 2732;
}
var dx = targetX - this.x;
var dy = targetY - this.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
var angle = Math.atan2(dy, dx);
this.x += Math.cos(angle) * this.speed;
this.y += Math.sin(angle) * this.speed;
}
}
};
fishes.push(newFish);
game.addChild(newFish);
}
});
Sea urchin, cartoon, spiny, long spines, grumpy face, no shadow Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Fish, cartoon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
underwater, ocean, anime landscape Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Bubble, opaque, cartoon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A tender morsel of delicious plankton. cartoon, shiny, no background. bright orange and yellow shrimp. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Game start sign. cartoon, shiny, underwater theme. "START GAME". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
game success graphic, surprised cartoon shiny words, "WOW!". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.