User prompt
play sand when player moves
User prompt
hitboxes should nto be visible
User prompt
make sure collision detectionn is using hte actual size of the player and coconut hitbox
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.hitbox.intersects is not a function' in or related to this line: 'if (self.hitbox.intersects(coconuts[i].hitbox)) {' Line Number: 139
User prompt
Check for collision with coconuts should use playerhitbox and coconuthitbox
User prompt
when player hitbox collides with coconut hitbox, then game over
User prompt
remove collision detection between player and coconut
User prompt
make sure to check that coconut an player hitbox colide before game over
User prompt
Please fix the bug: 'TypeError: player.hitbox.intersects is not a function' in or related to this line: 'if (player.hitbox.intersects(coconuts[b].hitbox)) {' Line Number: 245
User prompt
player should only colide wiht cocount wen hitboxes colide, no the player and coconut asset
User prompt
create an asset to show the coconut hitbox
User prompt
create an asset to show the player hitbox
User prompt
remove player left asset
User prompt
show player hitbox
Code edit (2 edits merged)
Please save this source code
User prompt
esplosion of coconuts should only be upwards
Code edit (1 edits merged)
Please save this source code
User prompt
add a small particle explosion when a coconut is destroyed
User prompt
play coconut sound when it is destroyed
User prompt
play backgorundmusic on game start
User prompt
add small tilting to player when still
/****
* 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
};
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 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;
var playerLeftGraphics = self.attachAsset('playerLeft', {
anchorX: 0.5,
anchorY: 0.5
});
playerLeftGraphics.visible = false;
self.targetX = self.x;
self.targetY = self.y;
self.moveSpeed = 20;
self._move_migrated = function (x, y) {
self.targetX = x;
self.targetY = y;
};
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;
}
};
});
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
****/
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) {
var explosion = game.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
explosion.x = coconut.x;
explosion.y = coconut.y;
game.addChild(explosion);
LK.setTimeout(function () {
explosion.destroy();
}, 500);
coconut.destroy();
coconuts.splice(a, 1);
score++;
scoreTxt.setText(score.toString());
}
}
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);
}
for (var b = 0; b < coconuts.length; b++) {
if (player.intersects(coconuts[b], {
x: player.hitbox.x + player.hitbox.width * 0.15,
y: player.hitbox.y + player.hitbox.height * 0.15,
width: player.hitbox.width * 0.7,
height: player.hitbox.height * 0.7
}, {
x: coconuts[b].hitbox.x + coconuts[b].hitbox.width * 0.15,
y: coconuts[b].hitbox.y + coconuts[b].hitbox.height * 0.15,
width: coconuts[b].hitbox.width * 0.7,
height: coconuts[b].hitbox.height * 0.7
})) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
});
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.