/**** * Classes ****/ var BackgroundBack = Container.expand(function () { var self = Container.call(this); var backgroundGraphics = self.attachAsset('background', { anchorX: 0.5, anchorY: 0.5 }); backgroundGraphics.x = 1024; backgroundGraphics.y = 1366; }); var BackgroundFront = Container.expand(function () { var self = Container.call(this); var backgroundGraphics = self.attachAsset('backgroundfront', { anchorX: 0.5, anchorY: 0.5 }); backgroundGraphics.x = 1024 - 200; backgroundGraphics.y = 1366; }); var Cloud = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5 }); cloudGraphics.alpha = 0.8; // Make clouds dim self.speed = 0.8; self.update = function () { self.x += self.speed; if (self.x > 2048 + cloudGraphics.width / 2) { self.x = -cloudGraphics.width / 2; } }; }); var Coconut = Container.expand(function () { var self = Container.call(this); var coconutGraphics = self.attachAsset('coconut', { anchorX: 0.5, anchorY: 0.5 }); self.hitbox = { x: 25, y: 25, width: 100, height: 100 }; var hitboxGraphics = self.attachAsset('coconutHitbox', { anchorX: 0.5, anchorY: 0.5 }); hitboxGraphics.alpha = 0; self.setSpeed = function (score) { self.speed = 10 + Math.floor(score / 10); }; self.rotationSpeed = 0.05 * (Math.random() < 0.5 ? -1 : 1); self._move_migrated = function () { self.y += self.speed; self.rotation += self.rotationSpeed; }; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.hitbox = { x: 50, y: 50, width: 200, height: 400 }; var hitboxGraphics = self.attachAsset('playerHitbox', { anchorX: 0.5, anchorY: 0.5 }); hitboxGraphics.alpha = 0; var playerShadow = self.attachAsset('playerShadow', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.8, scaleY: 0.8 }); self.addChildAt(playerShadow, 0); playerShadow.y = playerGraphics.height * 0.1 + 200; playerShadow.alpha = 0.5; self.targetX = self.x; self.targetY = self.y; self.moveSpeed = 20; self._move_migrated = function (x, y) { self.targetX = x; self.targetY = y; LK.getSound('sand').play(); }; self._update_migrated = function () { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distanceX = Math.abs(dx); var distanceY = Math.abs(dy); if (distanceX > self.moveSpeed) { var newX = self.x + dx / distanceX * self.moveSpeed; // Add condition to stop player from moving when it reaches the sides of screen if (newX > playerGraphics.width / 2 && newX < 2048 - playerGraphics.width / 2) { self.x = newX; } } else if (distanceX > 0) { self.x = self.targetX; } // Add a tilt animation to the player even when it's not moving if (dx > 0) { playerGraphics.scale.x = 1; playerGraphics.rotation = Math.sin(LK.ticks / 5) * 0.05; } else if (dx < 0) { playerGraphics.scale.x = -1; playerGraphics.rotation = Math.sin(LK.ticks / 5) * -0.05; } else { playerGraphics.rotation = Math.sin(LK.ticks / 5) * 0.02; } // Check for collision with coconuts using hitboxes for (var i = 0; i < coconuts.length; i++) { var playerHitbox = { x: self.x - self.hitbox.width / 2, y: self.y - self.hitbox.height / 2, width: self.hitbox.width, height: self.hitbox.height }; var coconutHitbox = { x: coconuts[i].x - coconuts[i].hitbox.width / 2, y: coconuts[i].y - coconuts[i].hitbox.height / 2, width: coconuts[i].hitbox.width, height: coconuts[i].hitbox.height }; if (playerHitbox.x < coconutHitbox.x + coconutHitbox.width && playerHitbox.x + playerHitbox.width > coconutHitbox.x && playerHitbox.y < coconutHitbox.y + coconutHitbox.height && playerHitbox.y + playerHitbox.height > coconutHitbox.y) { LK.showGameOver(); } } }; }); var ScoreBackground = Container.expand(function () { var self = Container.call(this); var scoreBgGraphics = self.attachAsset('scoreBg', { anchorX: 0.5 }); scoreBgGraphics.x = 1024 - 300 - 20 + 10; scoreBgGraphics.y = 0 - 20 + 10; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Play background music on game start LK.playMusic('backgroundmusic'); var backgroundBack = game.addChild(new BackgroundBack()); var clouds = []; for (var i = 0; i < 3; i++) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * 2732 * 0.3; // Spawn only in the top 30% of the screen clouds.push(cloud); game.addChild(cloud); } var backgroundFront = game.addChild(new BackgroundFront()); var score = 0; var scoreBackground = LK.gui.addChildAt(new ScoreBackground(), 0); var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff", font: "'Press Start 2P', monospace", dropShadow: true, dropShadowColor: '#000000', dropShadowBlur: 4, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreTxt.anchor.set(.5, 0); scoreTxt.y = 20; LK.gui.top.addChild(scoreTxt); var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 350; var coconuts = []; game.on('down', function (x, y, obj) { var event = obj; var pos = game.toLocal(event.global); player._move_migrated(pos.x, pos.y); }); LK.on('tick', function () { player._update_migrated(); for (var i = 0; i < clouds.length; i++) { clouds[i].update(); } for (var a = coconuts.length - 1; a >= 0; a--) { var coconut = coconuts[a]; coconut._move_migrated(); if (coconut.y > 2732 - 200) { // Create a small particle explosion when a coconut is destroyed for (var i = 0; i < 10; i++) { var particle = game.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7, scaleX: 0.1, scaleY: 0.1 }); particle.x = coconut.x; particle.y = coconut.y; game.addChild(particle); // Randomize the direction and speed of the particles particle.speedX = (Math.random() - 0.5) * 5; particle.speedY = -Math.random() * 5; // Update the position of the particles every tick particle.update = function () { this.x += this.speedX; this.y += this.speedY; this.alpha -= 0.01; // Fade out the particles if (this.alpha <= 0) { this.destroy(); } }; } coconut.destroy(); coconuts.splice(a, 1); score++; scoreTxt.setText(score.toString()); // Play coconut sound when it is destroyed LK.getSound('coconut').play(); } } if (LK.ticks % Math.max(10, 60 - Math.floor(score / 10)) == 0) { var newCoconut = new Coconut(); newCoconut.setSpeed(score); newCoconut.x = Math.random() * 2048; newCoconut.y = 0; coconuts.push(newCoconut); game.addChild(newCoconut); } });
/****
* Classes
****/
var BackgroundBack = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics.x = 1024;
backgroundGraphics.y = 1366;
});
var BackgroundFront = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('backgroundfront', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundGraphics.x = 1024 - 200;
backgroundGraphics.y = 1366;
});
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
cloudGraphics.alpha = 0.8; // Make clouds dim
self.speed = 0.8;
self.update = function () {
self.x += self.speed;
if (self.x > 2048 + cloudGraphics.width / 2) {
self.x = -cloudGraphics.width / 2;
}
};
});
var Coconut = Container.expand(function () {
var self = Container.call(this);
var coconutGraphics = self.attachAsset('coconut', {
anchorX: 0.5,
anchorY: 0.5
});
self.hitbox = {
x: 25,
y: 25,
width: 100,
height: 100
};
var hitboxGraphics = self.attachAsset('coconutHitbox', {
anchorX: 0.5,
anchorY: 0.5
});
hitboxGraphics.alpha = 0;
self.setSpeed = function (score) {
self.speed = 10 + Math.floor(score / 10);
};
self.rotationSpeed = 0.05 * (Math.random() < 0.5 ? -1 : 1);
self._move_migrated = function () {
self.y += self.speed;
self.rotation += self.rotationSpeed;
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.hitbox = {
x: 50,
y: 50,
width: 200,
height: 400
};
var hitboxGraphics = self.attachAsset('playerHitbox', {
anchorX: 0.5,
anchorY: 0.5
});
hitboxGraphics.alpha = 0;
var playerShadow = self.attachAsset('playerShadow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
self.addChildAt(playerShadow, 0);
playerShadow.y = playerGraphics.height * 0.1 + 200;
playerShadow.alpha = 0.5;
self.targetX = self.x;
self.targetY = self.y;
self.moveSpeed = 20;
self._move_migrated = function (x, y) {
self.targetX = x;
self.targetY = y;
LK.getSound('sand').play();
};
self._update_migrated = function () {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distanceX = Math.abs(dx);
var distanceY = Math.abs(dy);
if (distanceX > self.moveSpeed) {
var newX = self.x + dx / distanceX * self.moveSpeed;
// Add condition to stop player from moving when it reaches the sides of screen
if (newX > playerGraphics.width / 2 && newX < 2048 - playerGraphics.width / 2) {
self.x = newX;
}
} else if (distanceX > 0) {
self.x = self.targetX;
}
// Add a tilt animation to the player even when it's not moving
if (dx > 0) {
playerGraphics.scale.x = 1;
playerGraphics.rotation = Math.sin(LK.ticks / 5) * 0.05;
} else if (dx < 0) {
playerGraphics.scale.x = -1;
playerGraphics.rotation = Math.sin(LK.ticks / 5) * -0.05;
} else {
playerGraphics.rotation = Math.sin(LK.ticks / 5) * 0.02;
}
// Check for collision with coconuts using hitboxes
for (var i = 0; i < coconuts.length; i++) {
var playerHitbox = {
x: self.x - self.hitbox.width / 2,
y: self.y - self.hitbox.height / 2,
width: self.hitbox.width,
height: self.hitbox.height
};
var coconutHitbox = {
x: coconuts[i].x - coconuts[i].hitbox.width / 2,
y: coconuts[i].y - coconuts[i].hitbox.height / 2,
width: coconuts[i].hitbox.width,
height: coconuts[i].hitbox.height
};
if (playerHitbox.x < coconutHitbox.x + coconutHitbox.width && playerHitbox.x + playerHitbox.width > coconutHitbox.x && playerHitbox.y < coconutHitbox.y + coconutHitbox.height && playerHitbox.y + playerHitbox.height > coconutHitbox.y) {
LK.showGameOver();
}
}
};
});
var ScoreBackground = Container.expand(function () {
var self = Container.call(this);
var scoreBgGraphics = self.attachAsset('scoreBg', {
anchorX: 0.5
});
scoreBgGraphics.x = 1024 - 300 - 20 + 10;
scoreBgGraphics.y = 0 - 20 + 10;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Play background music on game start
LK.playMusic('backgroundmusic');
var backgroundBack = game.addChild(new BackgroundBack());
var clouds = [];
for (var i = 0; i < 3; i++) {
var cloud = new Cloud();
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * 2732 * 0.3; // Spawn only in the top 30% of the screen
clouds.push(cloud);
game.addChild(cloud);
}
var backgroundFront = game.addChild(new BackgroundFront());
var score = 0;
var scoreBackground = LK.gui.addChildAt(new ScoreBackground(), 0);
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff",
font: "'Press Start 2P', monospace",
dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreTxt.anchor.set(.5, 0);
scoreTxt.y = 20;
LK.gui.top.addChild(scoreTxt);
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 350;
var coconuts = [];
game.on('down', function (x, y, obj) {
var event = obj;
var pos = game.toLocal(event.global);
player._move_migrated(pos.x, pos.y);
});
LK.on('tick', function () {
player._update_migrated();
for (var i = 0; i < clouds.length; i++) {
clouds[i].update();
}
for (var a = coconuts.length - 1; a >= 0; a--) {
var coconut = coconuts[a];
coconut._move_migrated();
if (coconut.y > 2732 - 200) {
// Create a small particle explosion when a coconut is destroyed
for (var i = 0; i < 10; i++) {
var particle = game.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7,
scaleX: 0.1,
scaleY: 0.1
});
particle.x = coconut.x;
particle.y = coconut.y;
game.addChild(particle);
// Randomize the direction and speed of the particles
particle.speedX = (Math.random() - 0.5) * 5;
particle.speedY = -Math.random() * 5;
// Update the position of the particles every tick
particle.update = function () {
this.x += this.speedX;
this.y += this.speedY;
this.alpha -= 0.01; // Fade out the particles
if (this.alpha <= 0) {
this.destroy();
}
};
}
coconut.destroy();
coconuts.splice(a, 1);
score++;
scoreTxt.setText(score.toString());
// Play coconut sound when it is destroyed
LK.getSound('coconut').play();
}
}
if (LK.ticks % Math.max(10, 60 - Math.floor(score / 10)) == 0) {
var newCoconut = new Coconut();
newCoconut.setSpeed(score);
newCoconut.x = Math.random() * 2048;
newCoconut.y = 0;
coconuts.push(newCoconut);
game.addChild(newCoconut);
}
});
8-bit. Cartoon. Guy the beach. Full body. Looking up. Sunglasses. Worried. In game asset. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
delete inpain selection
pixelart cartoon beach schene. just the beach and a big palm tree. no background.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixelart cartoon beach background for a mobile screen.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.