/**** 
* Classes
****/ 
// Class for BrainIcon
var BrainIcon = Container.expand(function () {
	var self = Container.call(this);
	var brainGraphics = self.attachAsset('Lives', {
		anchorX: 0.5,
		anchorY: 0.5
	});
});
// Class for Envelopes
var Envelope = Container.expand(function () {
	var self = Container.call(this);
	var envelopeGraphics = self.attachAsset('envelope', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 5;
	self.update = function () {
		self.y += self.speed;
	};
});
// Class for HR Gun Bullets
var HRBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('hrBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -10;
	self.update = function () {
		self.y += self.speed;
		for (var i = 0; i < shoutingPeople.length; i++) {
			if (self.intersects(shoutingPeople[i])) {
				shoutingPeople[i].destroy();
				shoutingPeople.splice(i, 1);
				LK.setScore(LK.getScore() + 1);
				break;
			}
		}
	};
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Class for the HR character
var HRCharacter = Container.expand(function () {
	var self = Container.call(this);
	var hrGraphics = self.attachAsset('hrCharacter', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 10;
	self.update = function () {
		// Update logic for HR character
	};
});
// Class for Player Lives
var PlayerLives = Container.expand(function () {
	var self = Container.call(this);
	self.lives = 3; // Player starts with 3 lives
	self.text = new Text2('Lives: ' + self.lives, {
		size: 50,
		fill: "#ffffff"
	});
	self.updateLives = function (lives) {
		self.lives = lives;
		self.text.setText('Lives: ' + self.lives);
	};
	self.updateLives(self.lives);
});
// Class for Shouting People
var ShoutingPerson = Container.expand(function () {
	var self = Container.call(this);
	var personGraphics = self.attachAsset('shoutingPerson', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 3;
	self.update = function () {
		self.y += self.speed;
	};
	self.destroyed = false;
	self.destroy = function () {
		if (!self.destroyed) {
			self.destroyed = true;
			Container.prototype.destroy.call(self);
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 // Init game with black background
});
/**** 
* Game Code
****/ 
// Add the 'background' asset as a background to the game.
var background = game.attachAsset('background', {
	anchorX: 0.0,
	anchorY: 0.0,
	x: 0,
	y: 0
});
// Initialize game variables
var hrCharacter = game.addChild(new HRCharacter());
hrCharacter.x = 2048 / 2;
hrCharacter.y = 2732 - 150;
// Initialize Player Lives
var playerLives = game.addChild(new PlayerLives());
playerLives.x = 50;
playerLives.y = 50;
// Initialize Brain Icons
var brainIcons = [];
for (var i = 0; i < 3; i++) {
	var newBrainIcon = new BrainIcon();
	newBrainIcon.x = 50 + i * 120;
	newBrainIcon.y = 150;
	brainIcons.push(newBrainIcon);
	game.addChild(newBrainIcon);
}
var envelopes = [];
var shoutingPeople = [];
var hrBullets = [];
// Function to handle movement
function handleMove(x, y, obj) {
	hrCharacter.x = x;
	hrCharacter.y = y;
}
// Function to handle shooting
function shootHRGun() {
	var newBullet = new HRBullet();
	newBullet.x = hrCharacter.x;
	newBullet.y = hrCharacter.y;
	hrBullets.push(newBullet);
	game.addChild(newBullet);
}
// Game event listeners
game.down = function (x, y, obj) {
	handleMove(x, y, obj);
	shootHRGun();
};
game.move = handleMove;
game.update = function () {
	// Reset the counter when the game restarts
	fallenShoutingPeople = 0;
	// Reset brain icons
	for (var i = brainIcons.length - 1; i >= 0; i--) {
		brainIcons[i].destroy();
		brainIcons.splice(i, 1);
	}
	for (var i = 0; i < playerLives.lives; i++) {
		var newBrainIcon = new BrainIcon();
		newBrainIcon.x = 50 + i * 120;
		newBrainIcon.y = 150;
		brainIcons.push(newBrainIcon);
		game.addChild(newBrainIcon);
	}
	// Update envelopes
	for (var i = envelopes.length - 1; i >= 0; i--) {
		envelopes[i].update();
		if (envelopes[i].y > 2732) {
			envelopes[i].destroy();
			envelopes.splice(i, 1);
		}
		// Check for collision with player
		if (hrCharacter.intersects(envelopes[i])) {
			envelopes[i].destroy();
			envelopes.splice(i, 1);
			playerLives.updateLives(playerLives.lives - 1); // Deduct one life
			// Update brain icons
			var lastBrainIcon = brainIcons.pop();
			lastBrainIcon.destroy();
		}
	}
	// Initialize a counter for shouting people that fall to the ground
	var fallenShoutingPeople = 0;
	// Update shouting people
	for (var j = shoutingPeople.length - 1; j >= 0; j--) {
		shoutingPeople[j].update();
		if (shoutingPeople[j].y > 2732 || shoutingPeople[j].destroyed) {
			shoutingPeople[j].destroy();
			shoutingPeople.splice(j, 1);
			// Increase the counter each time a shouting person falls to the ground
			fallenShoutingPeople++;
		}
	}
	// Update HR bullets
	for (var k = hrBullets.length - 1; k >= 0; k--) {
		hrBullets[k].update();
		if (hrBullets[k].y < 0) {
			hrBullets[k].destroy();
			hrBullets.splice(k, 1);
		}
	}
	// Check if player has 0 lives or if 3 shouting people have fallen to the ground
	if (playerLives.lives <= 0 || fallenShoutingPeople >= 3) {
		LK.showGameOver(); // Show game over screen
	} else {
		// Spawn new envelopes and shouting people
		if (LK.ticks % 60 == 0) {
			var newEnvelope = new Envelope();
			newEnvelope.x = Math.random() * 2048;
			newEnvelope.y = 0;
			envelopes.push(newEnvelope);
			game.addChild(newEnvelope);
			var newShoutingPerson = new ShoutingPerson();
			newShoutingPerson.x = Math.random() * 2048;
			newShoutingPerson.y = 0;
			shoutingPeople.push(newShoutingPerson);
			game.addChild(newShoutingPerson);
		}
	}
}; /**** 
* Classes
****/ 
// Class for BrainIcon
var BrainIcon = Container.expand(function () {
	var self = Container.call(this);
	var brainGraphics = self.attachAsset('Lives', {
		anchorX: 0.5,
		anchorY: 0.5
	});
});
// Class for Envelopes
var Envelope = Container.expand(function () {
	var self = Container.call(this);
	var envelopeGraphics = self.attachAsset('envelope', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 5;
	self.update = function () {
		self.y += self.speed;
	};
});
// Class for HR Gun Bullets
var HRBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('hrBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -10;
	self.update = function () {
		self.y += self.speed;
		for (var i = 0; i < shoutingPeople.length; i++) {
			if (self.intersects(shoutingPeople[i])) {
				shoutingPeople[i].destroy();
				shoutingPeople.splice(i, 1);
				LK.setScore(LK.getScore() + 1);
				break;
			}
		}
	};
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Class for the HR character
var HRCharacter = Container.expand(function () {
	var self = Container.call(this);
	var hrGraphics = self.attachAsset('hrCharacter', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 10;
	self.update = function () {
		// Update logic for HR character
	};
});
// Class for Player Lives
var PlayerLives = Container.expand(function () {
	var self = Container.call(this);
	self.lives = 3; // Player starts with 3 lives
	self.text = new Text2('Lives: ' + self.lives, {
		size: 50,
		fill: "#ffffff"
	});
	self.updateLives = function (lives) {
		self.lives = lives;
		self.text.setText('Lives: ' + self.lives);
	};
	self.updateLives(self.lives);
});
// Class for Shouting People
var ShoutingPerson = Container.expand(function () {
	var self = Container.call(this);
	var personGraphics = self.attachAsset('shoutingPerson', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 3;
	self.update = function () {
		self.y += self.speed;
	};
	self.destroyed = false;
	self.destroy = function () {
		if (!self.destroyed) {
			self.destroyed = true;
			Container.prototype.destroy.call(self);
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 // Init game with black background
});
/**** 
* Game Code
****/ 
// Add the 'background' asset as a background to the game.
var background = game.attachAsset('background', {
	anchorX: 0.0,
	anchorY: 0.0,
	x: 0,
	y: 0
});
// Initialize game variables
var hrCharacter = game.addChild(new HRCharacter());
hrCharacter.x = 2048 / 2;
hrCharacter.y = 2732 - 150;
// Initialize Player Lives
var playerLives = game.addChild(new PlayerLives());
playerLives.x = 50;
playerLives.y = 50;
// Initialize Brain Icons
var brainIcons = [];
for (var i = 0; i < 3; i++) {
	var newBrainIcon = new BrainIcon();
	newBrainIcon.x = 50 + i * 120;
	newBrainIcon.y = 150;
	brainIcons.push(newBrainIcon);
	game.addChild(newBrainIcon);
}
var envelopes = [];
var shoutingPeople = [];
var hrBullets = [];
// Function to handle movement
function handleMove(x, y, obj) {
	hrCharacter.x = x;
	hrCharacter.y = y;
}
// Function to handle shooting
function shootHRGun() {
	var newBullet = new HRBullet();
	newBullet.x = hrCharacter.x;
	newBullet.y = hrCharacter.y;
	hrBullets.push(newBullet);
	game.addChild(newBullet);
}
// Game event listeners
game.down = function (x, y, obj) {
	handleMove(x, y, obj);
	shootHRGun();
};
game.move = handleMove;
game.update = function () {
	// Reset the counter when the game restarts
	fallenShoutingPeople = 0;
	// Reset brain icons
	for (var i = brainIcons.length - 1; i >= 0; i--) {
		brainIcons[i].destroy();
		brainIcons.splice(i, 1);
	}
	for (var i = 0; i < playerLives.lives; i++) {
		var newBrainIcon = new BrainIcon();
		newBrainIcon.x = 50 + i * 120;
		newBrainIcon.y = 150;
		brainIcons.push(newBrainIcon);
		game.addChild(newBrainIcon);
	}
	// Update envelopes
	for (var i = envelopes.length - 1; i >= 0; i--) {
		envelopes[i].update();
		if (envelopes[i].y > 2732) {
			envelopes[i].destroy();
			envelopes.splice(i, 1);
		}
		// Check for collision with player
		if (hrCharacter.intersects(envelopes[i])) {
			envelopes[i].destroy();
			envelopes.splice(i, 1);
			playerLives.updateLives(playerLives.lives - 1); // Deduct one life
			// Update brain icons
			var lastBrainIcon = brainIcons.pop();
			lastBrainIcon.destroy();
		}
	}
	// Initialize a counter for shouting people that fall to the ground
	var fallenShoutingPeople = 0;
	// Update shouting people
	for (var j = shoutingPeople.length - 1; j >= 0; j--) {
		shoutingPeople[j].update();
		if (shoutingPeople[j].y > 2732 || shoutingPeople[j].destroyed) {
			shoutingPeople[j].destroy();
			shoutingPeople.splice(j, 1);
			// Increase the counter each time a shouting person falls to the ground
			fallenShoutingPeople++;
		}
	}
	// Update HR bullets
	for (var k = hrBullets.length - 1; k >= 0; k--) {
		hrBullets[k].update();
		if (hrBullets[k].y < 0) {
			hrBullets[k].destroy();
			hrBullets.splice(k, 1);
		}
	}
	// Check if player has 0 lives or if 3 shouting people have fallen to the ground
	if (playerLives.lives <= 0 || fallenShoutingPeople >= 3) {
		LK.showGameOver(); // Show game over screen
	} else {
		// Spawn new envelopes and shouting people
		if (LK.ticks % 60 == 0) {
			var newEnvelope = new Envelope();
			newEnvelope.x = Math.random() * 2048;
			newEnvelope.y = 0;
			envelopes.push(newEnvelope);
			game.addChild(newEnvelope);
			var newShoutingPerson = new ShoutingPerson();
			newShoutingPerson.x = Math.random() * 2048;
			newShoutingPerson.y = 0;
			shoutingPeople.push(newShoutingPerson);
			game.addChild(newShoutingPerson);
		}
	}
};
 Envelope. 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.
 bullet. 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.
 shouting person. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Retro.. 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. A pixel-art HR professional wearing a suit and tie, glasses, and holding an oversized cartoonish gun. The character should have a confident stance, professional yet whimsical, styled for a retro game. 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. A pixel-art retro office background featuring cubicles, filing cabinets, and scattered papers. The design is simple but vibrant, with blocky shapes and bright colors suitable for a static 2D game environment.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Brain. 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.