/**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
	highScore: 0
});
/**** 
* Classes
****/ 
var Ground = Container.expand(function () {
	var self = Container.call(this);
	var groundGraphics = self.attachAsset('ground', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -8;
	self.update = function () {
		self.x += self.speed;
		// If ground piece moves off screen, move it to the right side
		if (self.x < -groundGraphics.width / 2) {
			self.x = 2048 + groundGraphics.width / 2;
		}
	};
	return self;
});
var Obstacle = Container.expand(function (type) {
	var self = Container.call(this);
	self.type = type || 'spike';
	self.speed = -8; // Default movement speed
	var assetId = self.type;
	var obstacleGraphics = self.attachAsset(assetId, {
		anchorX: 0.5,
		anchorY: 0.5
	});
	if (self.type === 'spike') {
		// Rotate spikes to point upward
		obstacleGraphics.rotation = Math.PI * 0.75;
	}
	self.update = function () {
		self.x += self.speed;
		// Remove if off screen to the left
		if (self.x < -100) {
			self.destroy();
			return true; // Signal that this obstacle should be removed
		}
		return false;
	};
	return self;
});
var Particle = Container.expand(function () {
	var self = Container.call(this);
	var particleGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.vx = (Math.random() - 0.5) * 10;
	self.vy = (Math.random() - 0.5) * 10 - 5;
	self.gravity = 0.3;
	self.life = 30 + Math.random() * 20;
	self.update = function () {
		self.x += self.vx;
		self.vy += self.gravity;
		self.y += self.vy;
		self.life--;
		particleGraphics.alpha = self.life / 50;
		if (self.life <= 0) {
			self.destroy();
			return true; // Signal that this particle should be removed
		}
		return false;
	};
	return self;
});
var Player = Container.expand(function () {
	var self = Container.call(this);
	var playerGraphics = self.attachAsset('player', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.gravity = 0.8;
	self.velocity = 0;
	self.jumpForce = -18;
	self.isJumping = false;
	self.isDead = false;
	self.friction = 0.95; // Ice physics - less friction
	self.jump = function () {
		if (!self.isJumping && !self.isDead) {
			self.velocity = self.jumpForce;
			self.isJumping = true;
			LK.getSound('jump').play();
			// Create jump particles
			for (var i = 0; i < 5; i++) {
				createParticle(self.x, self.y + 40);
			}
		}
	};
	self.die = function () {
		if (!self.isDead) {
			self.isDead = true;
			LK.getSound('death').play();
			LK.effects.flashObject(self, 0xff0000, 500);
			// Create death particles
			for (var i = 0; i < 15; i++) {
				createParticle(self.x, self.y);
			}
			LK.setTimeout(function () {
				LK.showGameOver();
			}, 1000);
		}
	};
	self.update = function () {
		if (self.isDead) {
			return;
		}
		// Apply gravity
		if (!self.isFlying) {
			self.velocity += self.gravity;
		} else {
			self.velocity = 0; // Neutralize gravity when flying
		}
		// Apply velocity with ice physics (less friction when moving horizontally)
		self.y += self.velocity;
		// Rotation based on velocity
		playerGraphics.rotation += 0.05;
		// Check if player is below the screen
		if (self.y > 2732) {
			self.die();
		}
	};
	self.activateFlyPowerUp = function () {
		if (!self.isDead) {
			self.isFlying = true;
			LK.setTimeout(function () {
				self.isFlying = false;
			}, 5000); // Fly for 5 seconds
		}
	};
	return self;
});
var PowerUp = Container.expand(function () {
	var self = Container.call(this);
	var powerUpGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.type = 'fly';
	self.speed = -8;
	self.update = function () {
		self.x += self.speed;
		if (self.x < -100) {
			self.destroy();
			return true;
		}
		return false;
	};
	return self;
});
var RotatingSaw = Container.expand(function () {
	var self = Container.call(this);
	var sawGraphics = self.attachAsset('spike', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -8;
	self.rotationSpeed = 0.1; // Rotation speed for the saw
	self.update = function () {
		self.x += self.speed;
		sawGraphics.rotation += self.rotationSpeed; // Rotate the saw
		// Remove if off screen to the left
		if (self.x < -100) {
			self.destroy();
			return true; // Signal that this obstacle should be removed
		}
		return false;
	};
	return self;
});
var ShieldPowerUp = Container.expand(function () {
	var self = Container.call(this);
	var shieldGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.type = 'shield';
	self.speed = -8;
	self.update = function () {
		self.x += self.speed;
		if (self.x < -100) {
			self.destroy();
			return true;
		}
		return false;
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x87CEFA
});
/**** 
* Game Code
****/ 
// Game variables
Player.prototype.activateShield = function () {
	if (!this.isDead) {
		this.hasShield = true;
		LK.effects.flashObject(this, 0x00ff00, 500);
		var self = this;
		LK.setTimeout(function () {
			self.hasShield = false;
		}, 10000); // Shield lasts for 10 seconds
	}
};
var player;
var obstacles = [];
var grounds = [];
var particles = [];
var gameSpeed = 1;
var score = 0;
var highScore = storage.highScore || 0;
var difficulty = 1;
var isGameStarted = false;
var obstacleTimer;
var scoreInterval;
var difficultyInterval;
// UI elements
var scoreTxt = new Text2('0', {
	size: 100,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var highScoreTxt = new Text2('Best: 0', {
	size: 60,
	fill: 0xFFFFFF
});
highScoreTxt.anchor.set(0.5, 0);
highScoreTxt.y = 110;
LK.gui.top.addChild(highScoreTxt);
var instructionsTxt = new Text2('Tap to Jump', {
	size: 80,
	fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionsTxt);
// Initialize the player
function initPlayer() {
	player = new Player();
	player.x = 500;
	player.y = 2732 / 2;
	game.addChild(player);
}
// Initialize the ground
function initGround() {
	// Create multiple ground pieces to cover the width
	var groundWidth = LK.getAsset('ground', {}).width;
	var numGroundPieces = Math.ceil(2048 / groundWidth) + 2;
	for (var i = 0; i < numGroundPieces; i++) {
		var ground = new Ground();
		ground.x = i * groundWidth;
		ground.y = 2732 - 100;
		game.addChild(ground);
		grounds.push(ground);
	}
	// Create ceiling
	var ceiling = game.addChild(LK.getAsset('ceiling', {
		anchorX: 0.5,
		anchorY: 0.5
	}));
	ceiling.x = 2048 / 2;
	ceiling.y = 100;
}
// Create an obstacle
function createObstacle() {
	var types = ['spike', 'platform', 'rotatingSaw'];
	var type = types[Math.floor(Math.random() * types.length)];
	var obstacle = new Obstacle(type);
	obstacle.x = 2048 + 100;
	// Position based on type
	if (type === 'spike') {
		// Place spikes on the ground
		obstacle.y = 2732 - 130;
	} else if (type === 'platform') {
		// Random height for platforms
		obstacle.y = 1600 + Math.random() * 800;
	} else if (type === 'rotatingSaw') {
		// Random height for rotating saws
		obstacle.y = 1400 + Math.random() * 1000;
	}
	game.addChild(obstacle);
	obstacles.push(obstacle);
	// Adjust timer for next obstacle based on difficulty
	var nextTime = 1500 - difficulty * 100;
	if (nextTime < 800) {
		nextTime = 800;
	}
	obstacleTimer = LK.setTimeout(createObstacle, nextTime);
}
// Create a particle
function createParticle(x, y) {
	var particle = new Particle();
	particle.x = x;
	particle.y = y;
	game.addChild(particle);
	particles.push(particle);
}
// Start the game
function startGame() {
	if (isGameStarted) {
		return;
	}
	isGameStarted = true;
	instructionsTxt.visible = false;
	// Reset score
	score = 0;
	difficulty = 1;
	updateScore();
	// Start creating obstacles
	createObstacle();
	// Update score every second
	scoreInterval = LK.setInterval(function () {
		score += 1;
		updateScore();
	}, 1000);
	// Increase difficulty every 10 seconds
	difficultyInterval = LK.setInterval(function () {
		difficulty += 0.5;
		gameSpeed += 0.1;
		// Update obstacle and ground speed
		obstacles.forEach(function (obstacle) {
			obstacle.speed = -8 * gameSpeed;
		});
		grounds.forEach(function (ground) {
			ground.speed = -8 * gameSpeed;
		});
	}, 10000);
	// Play the music
	LK.playMusic('iceTheme');
}
// Update the score display
function updateScore() {
	scoreTxt.setText(Math.floor(score));
	if (score > highScore) {
		highScore = score;
		storage.highScore = highScore;
		highScoreTxt.setText('Best: ' + Math.floor(highScore));
	}
}
// Initialize the game
function initGame() {
	initPlayer();
	initGround();
	// Set high score
	highScore = storage.highScore || 0;
	highScoreTxt.setText('Best: ' + Math.floor(highScore));
}
// Check collisions
function checkCollisions() {
	if (!player || player.isDead) {
		return;
	}
	// Check ground collision
	var isOnGround = false;
	grounds.forEach(function (ground) {
		if (player.y + 40 >= ground.y - 15 && player.y - 40 < ground.y + 15 && Math.abs(player.x - ground.x) < 200) {
			isOnGround = true;
			player.y = ground.y - 40;
			player.velocity = 0;
			player.isJumping = false;
		}
	});
	// Check ceiling collision
	if (player.y - 40 <= 100 + 15) {
		player.y = 100 + 15 + 40;
		player.velocity = 0;
	}
	// Check obstacle collisions
	obstacles.forEach(function (obstacle) {
		if (player.intersects(obstacle)) {
			if (player.hasShield) {
				player.hasShield = false; // Remove shield on collision
				obstacle.destroy();
			} else {
				player.die();
			}
		}
	});
}
// Input event handlers
game.down = function (x, y) {
	if (!isGameStarted) {
		startGame();
	}
	if (player && !player.isDead) {
		player.jump();
	}
};
// Main update function
game.update = function () {
	if (!isGameStarted) {
		return;
	}
	// Update player
	if (player) {
		player.update();
	}
	// Update grounds
	for (var i = 0; i < grounds.length; i++) {
		grounds[i].update();
	}
	// Update obstacles
	for (var i = obstacles.length - 1; i >= 0; i--) {
		if (obstacles[i].update()) {
			obstacles.splice(i, 1);
		}
	}
	// Create power-up
	if (LK.ticks % 300 === 0) {
		// Every 5 seconds
		var powerUp = new PowerUp();
		powerUp.x = 2048 + 100;
		powerUp.y = Math.random() * 2000 + 300; // Random y position
		game.addChild(powerUp);
		obstacles.push(powerUp);
	}
	if (LK.ticks % 600 === 0) {
		// Every 10 seconds
		var shieldPowerUp = new ShieldPowerUp();
		shieldPowerUp.x = 2048 + 100;
		shieldPowerUp.y = Math.random() * 2000 + 300; // Random y position
		game.addChild(shieldPowerUp);
		obstacles.push(shieldPowerUp);
	}
	// Check power-up collisions
	for (var i = obstacles.length - 1; i >= 0; i--) {
		if (obstacles[i] instanceof PowerUp && player.intersects(obstacles[i])) {
			player.activateFlyPowerUp();
			obstacles[i].destroy();
			obstacles.splice(i, 1);
		} else if (obstacles[i] instanceof ShieldPowerUp && player.intersects(obstacles[i])) {
			player.activateShield();
			obstacles[i].destroy();
			obstacles.splice(i, 1);
		}
	}
	// Update particles
	for (var i = particles.length - 1; i >= 0; i--) {
		if (particles[i].update()) {
			particles.splice(i, 1);
		}
	}
	// Check collisions
	checkCollisions();
};
// Initialize the game
initGame(); /**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
	highScore: 0
});
/**** 
* Classes
****/ 
var Ground = Container.expand(function () {
	var self = Container.call(this);
	var groundGraphics = self.attachAsset('ground', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -8;
	self.update = function () {
		self.x += self.speed;
		// If ground piece moves off screen, move it to the right side
		if (self.x < -groundGraphics.width / 2) {
			self.x = 2048 + groundGraphics.width / 2;
		}
	};
	return self;
});
var Obstacle = Container.expand(function (type) {
	var self = Container.call(this);
	self.type = type || 'spike';
	self.speed = -8; // Default movement speed
	var assetId = self.type;
	var obstacleGraphics = self.attachAsset(assetId, {
		anchorX: 0.5,
		anchorY: 0.5
	});
	if (self.type === 'spike') {
		// Rotate spikes to point upward
		obstacleGraphics.rotation = Math.PI * 0.75;
	}
	self.update = function () {
		self.x += self.speed;
		// Remove if off screen to the left
		if (self.x < -100) {
			self.destroy();
			return true; // Signal that this obstacle should be removed
		}
		return false;
	};
	return self;
});
var Particle = Container.expand(function () {
	var self = Container.call(this);
	var particleGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.vx = (Math.random() - 0.5) * 10;
	self.vy = (Math.random() - 0.5) * 10 - 5;
	self.gravity = 0.3;
	self.life = 30 + Math.random() * 20;
	self.update = function () {
		self.x += self.vx;
		self.vy += self.gravity;
		self.y += self.vy;
		self.life--;
		particleGraphics.alpha = self.life / 50;
		if (self.life <= 0) {
			self.destroy();
			return true; // Signal that this particle should be removed
		}
		return false;
	};
	return self;
});
var Player = Container.expand(function () {
	var self = Container.call(this);
	var playerGraphics = self.attachAsset('player', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.gravity = 0.8;
	self.velocity = 0;
	self.jumpForce = -18;
	self.isJumping = false;
	self.isDead = false;
	self.friction = 0.95; // Ice physics - less friction
	self.jump = function () {
		if (!self.isJumping && !self.isDead) {
			self.velocity = self.jumpForce;
			self.isJumping = true;
			LK.getSound('jump').play();
			// Create jump particles
			for (var i = 0; i < 5; i++) {
				createParticle(self.x, self.y + 40);
			}
		}
	};
	self.die = function () {
		if (!self.isDead) {
			self.isDead = true;
			LK.getSound('death').play();
			LK.effects.flashObject(self, 0xff0000, 500);
			// Create death particles
			for (var i = 0; i < 15; i++) {
				createParticle(self.x, self.y);
			}
			LK.setTimeout(function () {
				LK.showGameOver();
			}, 1000);
		}
	};
	self.update = function () {
		if (self.isDead) {
			return;
		}
		// Apply gravity
		if (!self.isFlying) {
			self.velocity += self.gravity;
		} else {
			self.velocity = 0; // Neutralize gravity when flying
		}
		// Apply velocity with ice physics (less friction when moving horizontally)
		self.y += self.velocity;
		// Rotation based on velocity
		playerGraphics.rotation += 0.05;
		// Check if player is below the screen
		if (self.y > 2732) {
			self.die();
		}
	};
	self.activateFlyPowerUp = function () {
		if (!self.isDead) {
			self.isFlying = true;
			LK.setTimeout(function () {
				self.isFlying = false;
			}, 5000); // Fly for 5 seconds
		}
	};
	return self;
});
var PowerUp = Container.expand(function () {
	var self = Container.call(this);
	var powerUpGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.type = 'fly';
	self.speed = -8;
	self.update = function () {
		self.x += self.speed;
		if (self.x < -100) {
			self.destroy();
			return true;
		}
		return false;
	};
	return self;
});
var RotatingSaw = Container.expand(function () {
	var self = Container.call(this);
	var sawGraphics = self.attachAsset('spike', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -8;
	self.rotationSpeed = 0.1; // Rotation speed for the saw
	self.update = function () {
		self.x += self.speed;
		sawGraphics.rotation += self.rotationSpeed; // Rotate the saw
		// Remove if off screen to the left
		if (self.x < -100) {
			self.destroy();
			return true; // Signal that this obstacle should be removed
		}
		return false;
	};
	return self;
});
var ShieldPowerUp = Container.expand(function () {
	var self = Container.call(this);
	var shieldGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.type = 'shield';
	self.speed = -8;
	self.update = function () {
		self.x += self.speed;
		if (self.x < -100) {
			self.destroy();
			return true;
		}
		return false;
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x87CEFA
});
/**** 
* Game Code
****/ 
// Game variables
Player.prototype.activateShield = function () {
	if (!this.isDead) {
		this.hasShield = true;
		LK.effects.flashObject(this, 0x00ff00, 500);
		var self = this;
		LK.setTimeout(function () {
			self.hasShield = false;
		}, 10000); // Shield lasts for 10 seconds
	}
};
var player;
var obstacles = [];
var grounds = [];
var particles = [];
var gameSpeed = 1;
var score = 0;
var highScore = storage.highScore || 0;
var difficulty = 1;
var isGameStarted = false;
var obstacleTimer;
var scoreInterval;
var difficultyInterval;
// UI elements
var scoreTxt = new Text2('0', {
	size: 100,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var highScoreTxt = new Text2('Best: 0', {
	size: 60,
	fill: 0xFFFFFF
});
highScoreTxt.anchor.set(0.5, 0);
highScoreTxt.y = 110;
LK.gui.top.addChild(highScoreTxt);
var instructionsTxt = new Text2('Tap to Jump', {
	size: 80,
	fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionsTxt);
// Initialize the player
function initPlayer() {
	player = new Player();
	player.x = 500;
	player.y = 2732 / 2;
	game.addChild(player);
}
// Initialize the ground
function initGround() {
	// Create multiple ground pieces to cover the width
	var groundWidth = LK.getAsset('ground', {}).width;
	var numGroundPieces = Math.ceil(2048 / groundWidth) + 2;
	for (var i = 0; i < numGroundPieces; i++) {
		var ground = new Ground();
		ground.x = i * groundWidth;
		ground.y = 2732 - 100;
		game.addChild(ground);
		grounds.push(ground);
	}
	// Create ceiling
	var ceiling = game.addChild(LK.getAsset('ceiling', {
		anchorX: 0.5,
		anchorY: 0.5
	}));
	ceiling.x = 2048 / 2;
	ceiling.y = 100;
}
// Create an obstacle
function createObstacle() {
	var types = ['spike', 'platform', 'rotatingSaw'];
	var type = types[Math.floor(Math.random() * types.length)];
	var obstacle = new Obstacle(type);
	obstacle.x = 2048 + 100;
	// Position based on type
	if (type === 'spike') {
		// Place spikes on the ground
		obstacle.y = 2732 - 130;
	} else if (type === 'platform') {
		// Random height for platforms
		obstacle.y = 1600 + Math.random() * 800;
	} else if (type === 'rotatingSaw') {
		// Random height for rotating saws
		obstacle.y = 1400 + Math.random() * 1000;
	}
	game.addChild(obstacle);
	obstacles.push(obstacle);
	// Adjust timer for next obstacle based on difficulty
	var nextTime = 1500 - difficulty * 100;
	if (nextTime < 800) {
		nextTime = 800;
	}
	obstacleTimer = LK.setTimeout(createObstacle, nextTime);
}
// Create a particle
function createParticle(x, y) {
	var particle = new Particle();
	particle.x = x;
	particle.y = y;
	game.addChild(particle);
	particles.push(particle);
}
// Start the game
function startGame() {
	if (isGameStarted) {
		return;
	}
	isGameStarted = true;
	instructionsTxt.visible = false;
	// Reset score
	score = 0;
	difficulty = 1;
	updateScore();
	// Start creating obstacles
	createObstacle();
	// Update score every second
	scoreInterval = LK.setInterval(function () {
		score += 1;
		updateScore();
	}, 1000);
	// Increase difficulty every 10 seconds
	difficultyInterval = LK.setInterval(function () {
		difficulty += 0.5;
		gameSpeed += 0.1;
		// Update obstacle and ground speed
		obstacles.forEach(function (obstacle) {
			obstacle.speed = -8 * gameSpeed;
		});
		grounds.forEach(function (ground) {
			ground.speed = -8 * gameSpeed;
		});
	}, 10000);
	// Play the music
	LK.playMusic('iceTheme');
}
// Update the score display
function updateScore() {
	scoreTxt.setText(Math.floor(score));
	if (score > highScore) {
		highScore = score;
		storage.highScore = highScore;
		highScoreTxt.setText('Best: ' + Math.floor(highScore));
	}
}
// Initialize the game
function initGame() {
	initPlayer();
	initGround();
	// Set high score
	highScore = storage.highScore || 0;
	highScoreTxt.setText('Best: ' + Math.floor(highScore));
}
// Check collisions
function checkCollisions() {
	if (!player || player.isDead) {
		return;
	}
	// Check ground collision
	var isOnGround = false;
	grounds.forEach(function (ground) {
		if (player.y + 40 >= ground.y - 15 && player.y - 40 < ground.y + 15 && Math.abs(player.x - ground.x) < 200) {
			isOnGround = true;
			player.y = ground.y - 40;
			player.velocity = 0;
			player.isJumping = false;
		}
	});
	// Check ceiling collision
	if (player.y - 40 <= 100 + 15) {
		player.y = 100 + 15 + 40;
		player.velocity = 0;
	}
	// Check obstacle collisions
	obstacles.forEach(function (obstacle) {
		if (player.intersects(obstacle)) {
			if (player.hasShield) {
				player.hasShield = false; // Remove shield on collision
				obstacle.destroy();
			} else {
				player.die();
			}
		}
	});
}
// Input event handlers
game.down = function (x, y) {
	if (!isGameStarted) {
		startGame();
	}
	if (player && !player.isDead) {
		player.jump();
	}
};
// Main update function
game.update = function () {
	if (!isGameStarted) {
		return;
	}
	// Update player
	if (player) {
		player.update();
	}
	// Update grounds
	for (var i = 0; i < grounds.length; i++) {
		grounds[i].update();
	}
	// Update obstacles
	for (var i = obstacles.length - 1; i >= 0; i--) {
		if (obstacles[i].update()) {
			obstacles.splice(i, 1);
		}
	}
	// Create power-up
	if (LK.ticks % 300 === 0) {
		// Every 5 seconds
		var powerUp = new PowerUp();
		powerUp.x = 2048 + 100;
		powerUp.y = Math.random() * 2000 + 300; // Random y position
		game.addChild(powerUp);
		obstacles.push(powerUp);
	}
	if (LK.ticks % 600 === 0) {
		// Every 10 seconds
		var shieldPowerUp = new ShieldPowerUp();
		shieldPowerUp.x = 2048 + 100;
		shieldPowerUp.y = Math.random() * 2000 + 300; // Random y position
		game.addChild(shieldPowerUp);
		obstacles.push(shieldPowerUp);
	}
	// Check power-up collisions
	for (var i = obstacles.length - 1; i >= 0; i--) {
		if (obstacles[i] instanceof PowerUp && player.intersects(obstacles[i])) {
			player.activateFlyPowerUp();
			obstacles[i].destroy();
			obstacles.splice(i, 1);
		} else if (obstacles[i] instanceof ShieldPowerUp && player.intersects(obstacles[i])) {
			player.activateShield();
			obstacles[i].destroy();
			obstacles.splice(i, 1);
		}
	}
	// Update particles
	for (var i = particles.length - 1; i >= 0; i--) {
		if (particles[i].update()) {
			particles.splice(i, 1);
		}
	}
	// Check collisions
	checkCollisions();
};
// Initialize the game
initGame();