User prompt
add a sound backgroundNoise
Code edit (1 edits merged)
Please save this source code
User prompt
play the backgroundNoise in a loop
User prompt
play the bicycleRing randomly, between 5 and 10 seconds
Code edit (1 edits merged)
Please save this source code
User prompt
add another Obstacle or HorizontalObstacle every 10 seconds, do this 5 times
Code edit (6 edits merged)
Please save this source code
User prompt
scale the player by 10% everytime the player intersects with the safezone
Code edit (1 edits merged)
Please save this source code
User prompt
instead of dragging the player by pointer, the player should move to the current pointer position (on pointer down).
User prompt
the player should not jump to the current pointer position but move to it with a certain speed
User prompt
the player should rotate to where it is moving to
User prompt
wait 2 seconds before spawning all the different obstacles
/****
* Classes
****/
// Define a class for horizontal moving obstacles
var HorizontalObstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.x += self.speed;
self.y += Math.cos(self.x / 100) * 10;
// Rotate the obstacle to the direction it is heading
self.rotation = Math.atan2(Math.cos(self.x / 100) * 10, self.speed);
if (self.x > 2048) {
self.x = -obstacleGraphics.width;
self.y = Math.random() * 2732;
}
};
});
// Define a class for moving obstacles
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.startsBottom = false;
self.update = function () {
var dir = self.startsBottom ? -1 : 1;
self.y += self.speed * dir;
self.x += Math.cos(self.y / 100) * 10;
// Rotate the obstacle to the direction it is heading
self.rotation = Math.atan2(self.speed * dir, Math.cos(self.y / 100) * 10);
if (!self.startsBottom && self.y > 2732) {
self.y = -obstacleGraphics.height;
self.x = Math.random() * 2048;
} else if (self.startsBottom && self.y < -obstacleGraphics.height) {
self.y = 2732 + obstacleGraphics.height;
self.x = Math.random() * 2048;
}
};
});
//<Assets used in the game will automatically appear here>
// Define a class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Player update logic if needed
};
});
// Define a class for the safe zone
var SafeZone = Container.expand(function () {
var self = Container.call(this);
var safeZoneGraphics = self.attachAsset('safeZone', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
}));
// Initialize player
var player = new Player();
player.x = 2048 / 2;
player.y = 2732 / 2;
game.addChild(player);
background.zIndex = -1;
// Initialize obstacles
var obstacles = [];
for (var i = 0; i < 5; i++) {
var startFromTop = Math.random() >= 0.5;
var obstacle;
if (i % 2 == 0) {
obstacle = new Obstacle();
obstacle.startsBottom = !startFromTop;
obstacle.y = startFromTop ? Math.random() * -2732 : 2732 - Math.random() * 2732;
} else {
obstacle = new HorizontalObstacle();
obstacle.x = Math.random() * -2048;
}
obstacle.x = Math.random() * 2048;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Initialize safe zone
var safeZone = new SafeZone();
safeZone.x = 2048 / 2;
safeZone.y = 550;
game.addChild(safeZone);
// Initialize score
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Play the background music
// LK.playMusic('bg');
// Play the background noise
LK.getSound('backgroundNoise').play();
// Handle player movement
var dragNode = null;
game.down = function (x, y, obj) {
dragNode = player;
};
game.move = function (x, y, obj) {
if (dragNode) {
var dx = x - dragNode.x;
var dy = y - dragNode.y;
var targetRotation = Math.atan2(dy, dx);
var lerpFactor = 0.1; // Smoothing factor
dragNode.rotation += (targetRotation - dragNode.rotation) * lerpFactor;
dragNode.x = x;
dragNode.y = y;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game logic
game.update = function () {
// Update obstacles
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].update();
if (player.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Check if player is in the safe zone
if (player.intersects(safeZone)) {
LK.effects.flashScreen(0x00ff00, 1000);
// Increase score
score++;
scoreTxt.setText(score);
// Randomly position the safe zone within the game canvas with a 100px margin
safeZone.x = Math.random() * (2048 - 200) + 100;
safeZone.y = Math.random() * (2732 - 200) + 100;
}
};
vietnamese on a bike, top down, from above, flat, 8 bit art, pixel art, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
top down view of a big crossroad, pixelart style, from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a round pizza, flat. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat