/**** * Classes ****/ // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 2 + 1; // Random speed between 1 and 3 self.move = function () { self.y += self.speed; }; }); // Assets will be automatically created based on usage in the code. // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.move = function (direction) { if (direction === 'left' && self.x > 0) { self.x -= self.speed; } else if (direction === 'right' && self.x < 2048) { self.x += self.speed; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var player = game.addChild(new Player()); player.x = 1024; // Center horizontally player.y = 2500; // Near bottom var obstacles = []; var spawnRate = 120; // Spawn an obstacle every 2 seconds game.on('down', function (obj) { var pos = obj.event.getLocalPosition(game); if (pos.x < 1024) { player.move('left'); } else { player.move('right'); } }); LK.on('tick', function () { // Spawn obstacles if (LK.ticks % spawnRate === 0) { var obstacle = new Obstacle(); obstacle.x = Math.random() * 2048; // Random position across the width obstacle.y = 0; // Start from the top obstacles.push(obstacle); game.addChild(obstacle); } // Move obstacles for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].move(); // Remove obstacles that are off screen if (obstacles[i].y > 2732) { obstacles[i].destroy(); obstacles.splice(i, 1); } // Check collision with player if (player.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } });
/****
* Classes
****/
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1; // Random speed between 1 and 3
self.move = function () {
self.y += self.speed;
};
});
// Assets will be automatically created based on usage in the code.
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.move = function (direction) {
if (direction === 'left' && self.x > 0) {
self.x -= self.speed;
} else if (direction === 'right' && self.x < 2048) {
self.x += self.speed;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var player = game.addChild(new Player());
player.x = 1024; // Center horizontally
player.y = 2500; // Near bottom
var obstacles = [];
var spawnRate = 120; // Spawn an obstacle every 2 seconds
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
if (pos.x < 1024) {
player.move('left');
} else {
player.move('right');
}
});
LK.on('tick', function () {
// Spawn obstacles
if (LK.ticks % spawnRate === 0) {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048; // Random position across the width
obstacle.y = 0; // Start from the top
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Move obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].move();
// Remove obstacles that are off screen
if (obstacles[i].y > 2732) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
// Check collision with player
if (player.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
});
квадрат со злым лицом.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
нужно закрасить тень за квадратом
квадрат с испуганным лицом. Белый. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
квадрат со злым лицом. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.