/**** 
* Classes
****/ 
// Enemy class
var Enemy = Container.expand(function () {
	var self = Container.call(this);
	self.health = 20;
	var enemyGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Enemies follow the hero
		var dx = (hero.x - self.x) / 60;
		var dy = (hero.y - self.y) / 60;
		self.x += dx;
		self.y += dy;
		// Enemies return to their original positions every 4 seconds
		if (LK.ticks % 240 == 0) {
			var dx = (self.originalX - self.x) / 120;
			var dy = (self.originalY - self.y) / 120;
			for (var i = 0; i < 120; i++) {
				LK.setTimeout(function () {
					self.x += dx;
					self.y += dy;
				}, i * (1000 / 60)); // 60FPS
			}
		}
		// Enemies start moving again after 6 seconds
		if (LK.ticks % 360 == 0) {
			self.update = function () {
				// Enemies move every 2 seconds
				if (LK.ticks % 120 == 0 && LK.ticks % 360 != 0) {
					var newX = self.x + Math.random() * 200 - 100; // Random horizontal movement
					var newY = self.y + Math.random() * 200 - 100; // Random vertical movement
					// Animate the movement over 2 seconds
					var dx = (newX - self.x) / 120;
					var dy = (newY - self.y) / 120;
					for (var i = 0; i < 120; i++) {
						LK.setTimeout(function () {
							self.x += dx;
							self.y += dy;
						}, i * (1000 / 60)); // 60FPS
					}
				}
			};
		}
		// Enemies lower every 1 second
		if (LK.ticks % 60 == 0) {
			var newY = self.y + 50; // Lower the enemy
			// Animate the lowering over 1 second
			var dy = (newY - self.y) / 60;
			for (var i = 0; i < 60; i++) {
				LK.setTimeout(function () {
					self.y += dy;
				}, i * (1000 / 60)); // 60FPS
			}
		}
	};
});
// Assets will be automatically created and loaded by the LK engine based on usage in the game code.
// Hero class
var Hero = Container.expand(function () {
	var self = Container.call(this);
	var heroGraphics = self.attachAsset('hero', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.shoot = function () {
		var bullet = new HeroBullet();
		bullet.x = self.x;
		bullet.y = self.y;
		game.addChild(bullet);
		bullets.push(bullet);
	};
});
// HeroBullet class
var HeroBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('heroBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -10;
	self.update = function () {
		self.y += self.speed;
		if (self.y < -50) {
			self.destroy();
			bullets.splice(bullets.indexOf(self), 1);
		}
	};
});
// Moving Bar class
var MovingBar = Container.expand(function () {
	var self = Container.call(this);
	var barGraphics = self.attachAsset('bar', {
		width: 150,
		height: 100,
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.direction = 1;
	self.speed = 260 / 60; // Speed per frame
	self.update = function () {
		self.x += self.speed * self.direction;
		if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
			self.direction *= -1; // Change direction
		}
	};
});
// Particle class
var Particle = Container.expand(function () {
	var self = Container.call(this);
	var particleGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speedX = Math.random() * 10 - 5; // Random horizontal speed
	self.speedY = Math.random() * 10 - 5; // Random vertical speed
	self.update = function () {
		self.x += self.speedX;
		self.y += self.speedY;
		self.alpha -= 0.01; // Fade out
		if (self.alpha <= 0) {
			self.destroy();
		}
	};
});
// PlayerEnemy class
var PlayerEnemy = Container.expand(function () {
	var self = Container.call(this);
	var enemyGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// PlayerEnemy moves up
		self.y -= 5;
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 // Init game with black background
});
/**** 
* Game Code
****/ 
// Generate particles at a given position
function generateParticles(x, y) {
	for (var i = 0; i < 100; i++) {
		var particle = new Particle();
		particle.x = x;
		particle.y = y;
		game.addChild(particle);
	}
}
var background = game.attachAsset('background', {
	anchorX: 0,
	anchorY: 0
});
var hero;
var bullets = [];
var enemies = [];
// Initialize hero
function initHero() {
	hero = new Hero();
	hero.x = 1024; // Center horizontally
	hero.y = 2732 - 200; // Position from the bottom
	game.addChild(hero);
	// Initialize moving bar
	bar = new MovingBar();
	bar.x = 1024; // Center horizontally
	bar.y = 2732 - 400; // Position from the bottom
	game.addChild(bar);
}
// Initialize enemies
function initEnemies() {
	for (var i = 0; i < 5; i++) {
		var enemy = new Enemy();
		enemy.x = 100 + i * 400; // Spread enemies horizontally
		enemy.y = 200; // Position enemies from the top
		game.addChild(enemy);
		enemies.push(enemy);
	}
}
// Game touch event to shoot
game.down = function (x, y, obj) {
	hero.x = x;
	hero.y = y;
	hero.shoot();
};
// Check for bullet collisions with enemies and the moving bar
game.update = function () {
	bullets.forEach(function (bullet) {
		enemies.forEach(function (enemy, index) {
			if (bullet.intersects(enemy)) {
				bullet.destroy();
				bullets.splice(bullets.indexOf(bullet), 1);
				enemy.health -= 1;
				// Flash enemy red for 1 second (1000ms) when hit
				LK.effects.flashObject(enemy, 0xff0000, 1000);
				if (enemy.health <= 0) {
					enemy.destroy();
					enemies.splice(index, 1);
					generateParticles(enemy.x, enemy.y);
				}
			}
		});
		if (bullet.intersects(bar)) {
			bullet.destroy();
			bullets.splice(bullets.indexOf(bullet), 1);
		}
	});
	// Check if all enemies are dead
	if (enemies.length == 0) {
		// Do nothing
	} else {
		// Check if hero intersects with any enemy
		enemies.forEach(function (enemy) {
			if (hero.intersects(enemy)) {
				// Flash screen red for 1 second (1000ms) to show we are dead.
				LK.effects.flashScreen(0xff0000, 1000);
				// Show game over. The game will be automatically paused while game over is showing.
				LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state.
			}
		});
	}
};
// Initialize game elements
initHero();
initEnemies();
game.move = function (x, y, obj) {
	hero.x = x;
	hero.y = y;
}; /**** 
* Classes
****/ 
// Enemy class
var Enemy = Container.expand(function () {
	var self = Container.call(this);
	self.health = 20;
	var enemyGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Enemies follow the hero
		var dx = (hero.x - self.x) / 60;
		var dy = (hero.y - self.y) / 60;
		self.x += dx;
		self.y += dy;
		// Enemies return to their original positions every 4 seconds
		if (LK.ticks % 240 == 0) {
			var dx = (self.originalX - self.x) / 120;
			var dy = (self.originalY - self.y) / 120;
			for (var i = 0; i < 120; i++) {
				LK.setTimeout(function () {
					self.x += dx;
					self.y += dy;
				}, i * (1000 / 60)); // 60FPS
			}
		}
		// Enemies start moving again after 6 seconds
		if (LK.ticks % 360 == 0) {
			self.update = function () {
				// Enemies move every 2 seconds
				if (LK.ticks % 120 == 0 && LK.ticks % 360 != 0) {
					var newX = self.x + Math.random() * 200 - 100; // Random horizontal movement
					var newY = self.y + Math.random() * 200 - 100; // Random vertical movement
					// Animate the movement over 2 seconds
					var dx = (newX - self.x) / 120;
					var dy = (newY - self.y) / 120;
					for (var i = 0; i < 120; i++) {
						LK.setTimeout(function () {
							self.x += dx;
							self.y += dy;
						}, i * (1000 / 60)); // 60FPS
					}
				}
			};
		}
		// Enemies lower every 1 second
		if (LK.ticks % 60 == 0) {
			var newY = self.y + 50; // Lower the enemy
			// Animate the lowering over 1 second
			var dy = (newY - self.y) / 60;
			for (var i = 0; i < 60; i++) {
				LK.setTimeout(function () {
					self.y += dy;
				}, i * (1000 / 60)); // 60FPS
			}
		}
	};
});
// Assets will be automatically created and loaded by the LK engine based on usage in the game code.
// Hero class
var Hero = Container.expand(function () {
	var self = Container.call(this);
	var heroGraphics = self.attachAsset('hero', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.shoot = function () {
		var bullet = new HeroBullet();
		bullet.x = self.x;
		bullet.y = self.y;
		game.addChild(bullet);
		bullets.push(bullet);
	};
});
// HeroBullet class
var HeroBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('heroBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -10;
	self.update = function () {
		self.y += self.speed;
		if (self.y < -50) {
			self.destroy();
			bullets.splice(bullets.indexOf(self), 1);
		}
	};
});
// Moving Bar class
var MovingBar = Container.expand(function () {
	var self = Container.call(this);
	var barGraphics = self.attachAsset('bar', {
		width: 150,
		height: 100,
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.direction = 1;
	self.speed = 260 / 60; // Speed per frame
	self.update = function () {
		self.x += self.speed * self.direction;
		if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
			self.direction *= -1; // Change direction
		}
	};
});
// Particle class
var Particle = Container.expand(function () {
	var self = Container.call(this);
	var particleGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speedX = Math.random() * 10 - 5; // Random horizontal speed
	self.speedY = Math.random() * 10 - 5; // Random vertical speed
	self.update = function () {
		self.x += self.speedX;
		self.y += self.speedY;
		self.alpha -= 0.01; // Fade out
		if (self.alpha <= 0) {
			self.destroy();
		}
	};
});
// PlayerEnemy class
var PlayerEnemy = Container.expand(function () {
	var self = Container.call(this);
	var enemyGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// PlayerEnemy moves up
		self.y -= 5;
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 // Init game with black background
});
/**** 
* Game Code
****/ 
// Generate particles at a given position
function generateParticles(x, y) {
	for (var i = 0; i < 100; i++) {
		var particle = new Particle();
		particle.x = x;
		particle.y = y;
		game.addChild(particle);
	}
}
var background = game.attachAsset('background', {
	anchorX: 0,
	anchorY: 0
});
var hero;
var bullets = [];
var enemies = [];
// Initialize hero
function initHero() {
	hero = new Hero();
	hero.x = 1024; // Center horizontally
	hero.y = 2732 - 200; // Position from the bottom
	game.addChild(hero);
	// Initialize moving bar
	bar = new MovingBar();
	bar.x = 1024; // Center horizontally
	bar.y = 2732 - 400; // Position from the bottom
	game.addChild(bar);
}
// Initialize enemies
function initEnemies() {
	for (var i = 0; i < 5; i++) {
		var enemy = new Enemy();
		enemy.x = 100 + i * 400; // Spread enemies horizontally
		enemy.y = 200; // Position enemies from the top
		game.addChild(enemy);
		enemies.push(enemy);
	}
}
// Game touch event to shoot
game.down = function (x, y, obj) {
	hero.x = x;
	hero.y = y;
	hero.shoot();
};
// Check for bullet collisions with enemies and the moving bar
game.update = function () {
	bullets.forEach(function (bullet) {
		enemies.forEach(function (enemy, index) {
			if (bullet.intersects(enemy)) {
				bullet.destroy();
				bullets.splice(bullets.indexOf(bullet), 1);
				enemy.health -= 1;
				// Flash enemy red for 1 second (1000ms) when hit
				LK.effects.flashObject(enemy, 0xff0000, 1000);
				if (enemy.health <= 0) {
					enemy.destroy();
					enemies.splice(index, 1);
					generateParticles(enemy.x, enemy.y);
				}
			}
		});
		if (bullet.intersects(bar)) {
			bullet.destroy();
			bullets.splice(bullets.indexOf(bullet), 1);
		}
	});
	// Check if all enemies are dead
	if (enemies.length == 0) {
		// Do nothing
	} else {
		// Check if hero intersects with any enemy
		enemies.forEach(function (enemy) {
			if (hero.intersects(enemy)) {
				// Flash screen red for 1 second (1000ms) to show we are dead.
				LK.effects.flashScreen(0xff0000, 1000);
				// Show game over. The game will be automatically paused while game over is showing.
				LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state.
			}
		});
	}
};
// Initialize game elements
initHero();
initEnemies();
game.move = function (x, y, obj) {
	hero.x = x;
	hero.y = y;
};
 Uma bolinha preta com chifres dos olhos brancos sorridente laranja,jogo 2d fundo png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Uma bolinha verde dos olhos azuis fofo com uma capa azul fundo png 2d. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 UMA rua de dia com caixas na estrada com bolinha pretas com chifres branco pequenos,jogo 2d. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Um quadrado verde gradiente verde verde claro, com borda branca,2d pixel fundo png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Um quadrado vermelho com luz vermelha escuro, com gradiente preto e borda azul profissional,2d pixeis,fundo png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.