/**** 
* Classes
****/ 
var Bullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('bullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 8;
	self.visible = false;
	self.angle = Math.PI / 18 + Math.random() * (17 * Math.PI / 18); // Random angle between 10 and 170 degrees
	self.update = function () {
		if (LK.ticks > 240) {
			// 4 seconds at 60FPS
			self.visible = true;
			self.x += self.speed * Math.cos(self.angle);
			self.y -= self.speed * Math.sin(self.angle);
		}
	};
});
var Cannon = Container.expand(function () {
	var self = Container.call(this);
	var cannonGraphics = self.attachAsset('Cannon', {
		anchorX: 0.5,
		anchorY: 0.5
	});
});
// Cannon2 class
var Cannon2 = Container.expand(function () {
	var self = Container.call(this);
	var cannon2Graphics = self.attachAsset('Cannon2', {
		anchorX: 0.5,
		anchorY: 0.5
	});
});
// EnemyPlane class
var EnemyPlane = Container.expand(function () {
	var self = Container.call(this);
	var enemyPlaneGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speedX = -6;
	self.speedY = 0;
	// Update enemy plane position
	self.update = function () {
		self.x += self.speedX;
		// Smoothly adjust vertical position within a random range
		if (LK.ticks > 1500 && (!self.verticalTarget || Math.abs(self.verticalTarget - self.y) < 1)) {
			self.verticalTarget = self.y + (Math.random() > 0.5 ? Math.random() * 250 : -Math.random() * 250); // Set or reset target within a random range from 0 to 250 pixels
		}
		self.y += (self.verticalTarget - self.y) * 0.05; // Smoothly move towards the target
	};
});
// EnemyPlaneLeft class
var EnemyPlaneLeft = Container.expand(function () {
	var self = Container.call(this);
	var enemyPlaneGraphics = self.attachAsset('Enemyleft', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speedX = 6;
	self.speedY = 0;
	// Update enemy plane position
	self.update = function () {
		self.x += self.speedX;
		// Smoothly adjust vertical position within a random range
		if (LK.ticks > 1500 && (!self.verticalTarget || Math.abs(self.verticalTarget - self.y) < 1)) {
			self.verticalTarget = self.y + (Math.random() > 0.5 ? Math.random() * 250 : -Math.random() * 250); // Set or reset target within a random range from 0 to 250 pixels
		}
		self.y += (self.verticalTarget - self.y) * 0.05; // Smoothly move towards the target
	};
});
// Plane1 class
var Plane1 = Container.expand(function () {
	var self = Container.call(this);
	var planeGraphics = self.attachAsset('plane', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speedX = 7;
	self.speedY = 0;
	// Update plane position
	self.update = function () {
		self.x += self.speedX;
		self.y += self.speedY;
		// Check if the plane has crossed the screen boundary
		if (self.x < 0) {
			self.x = 2048;
		} else if (self.x > 2048) {
			self.x = 0;
		}
		// Prevent the plane from crossing the floor and ceiling
		if (self.y < 0) {
			self.y = 0;
			self.speedY = 0;
		} else if (self.y > 2752 - self.height) {
			self.y = 2752 - self.height;
			self.speedY = 0;
		}
	};
});
/**** 
* Initialize Game
****/ 
// Assets are automatically created based on usage in the code.
var game = new LK.Game({
	backgroundColor: 0xffffff // Init game with white background
});
/**** 
* Game Code
****/ 
var background2 = game.attachAsset('background2', {
	anchorX: 0.5,
	anchorY: 0.5,
	scaleX: 1,
	scaleY: 1
});
background2.x = 2175 / 2;
background2.y = 2620 / 2;
// Add background to the bottom of the game
var background = game.attachAsset('background', {
	anchorX: 0,
	anchorY: 1,
	scaleX: 1,
	scaleY: 1
});
background.y = 2732;
var enemyPlanes = []; // Global array to keep track of enemy planes
var enemyPlane; // Global variable to keep track of the enemy plane
// Create a player plane
var plane1 = new Plane1();
plane1.x = 150; // Moved 50 units to the right
plane1.y = 2750 - plane1.height; // Bottom of the screen
game.addChild(plane1);
// Create a cannon
var cannon = new Cannon();
cannon.x = -100; // Position at the bottom left of the screen
cannon.y = 2660;
game.addChild(cannon);
// Create a cannon2
var cannon2 = new Cannon2();
cannon2.x = 2150; // Position at the bottom left of the screen
cannon2.y = 2660;
game.addChild(cannon2);
var bullets = []; // Initialize an array to manage multiple bullets
LK.setTimeout(function () {
	var bulletSpawnInterval = LK.setInterval(function () {
		var newBullet = new Bullet();
		newBullet.x = 175;
		newBullet.y = 2590;
		game.addChild(newBullet);
		bullets.push(newBullet);
		var newBulletDuplicate = new Bullet();
		newBulletDuplicate.x = 1882; // New x position
		newBulletDuplicate.y = 2590; // New y position, same as original
		game.addChild(newBulletDuplicate);
		bullets.push(newBulletDuplicate);
	}, 800); // Spawn a new bullet every second, starting from the fourth second
}, 18000);
// Create the rest of the enemy planes every 2 seconds for the first 7 seconds
var enemySpawnTimer = LK.setInterval(function () {
	enemyPlane = new EnemyPlane();
	enemyPlane.x = 2150;
	enemyPlane.y = 100 + Math.random() * (2732 - enemyPlane.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
	game.addChild(enemyPlane);
	enemyPlanes.push(enemyPlane);
	var enemyPlaneLeft = new EnemyPlaneLeft();
	enemyPlaneLeft.x = -100;
	enemyPlaneLeft.y = 100 + Math.random() * (2732 - enemyPlaneLeft.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
	game.addChild(enemyPlaneLeft);
	enemyPlanes.push(enemyPlaneLeft);
}, 1300);
// After 7 seconds, change the enemy spawn interval to 1 every 1.3 seconds
LK.setTimeout(function () {
	LK.clearInterval(enemySpawnTimer);
	enemySpawnTimer = LK.setInterval(function () {
		enemyPlane = new EnemyPlane();
		enemyPlane.x = 2150;
		enemyPlane.y = 100 + Math.random() * (2732 - enemyPlane.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
		game.addChild(enemyPlane);
		enemyPlanes.push(enemyPlane);
		var enemyPlaneLeft = new EnemyPlaneLeft();
		enemyPlaneLeft.x = -100;
		enemyPlaneLeft.y = 100 + Math.random() * (2732 - enemyPlaneLeft.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
		game.addChild(enemyPlaneLeft);
		enemyPlanes.push(enemyPlaneLeft);
	}, 1100);
}, 5000);
// After 14 seconds, change the enemy spawn interval to 1 every second
LK.setTimeout(function () {
	LK.clearInterval(enemySpawnTimer);
	enemySpawnTimer = LK.setInterval(function () {
		enemyPlane = new EnemyPlane();
		enemyPlane.x = 2150;
		enemyPlane.y = 100 + Math.random() * (2732 - enemyPlane.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
		game.addChild(enemyPlane);
		enemyPlanes.push(enemyPlane);
		var enemyPlaneLeft = new EnemyPlaneLeft();
		enemyPlaneLeft.x = -100;
		enemyPlaneLeft.y = 100 + Math.random() * (2732 - enemyPlaneLeft.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
		game.addChild(enemyPlaneLeft);
		enemyPlanes.push(enemyPlaneLeft);
	}, 900);
}, 11000);
// Initialize score based on game ticks
var scoreCounter = 0;
var scoreTxt = new Text2(scoreCounter.toString(), {
	size: 70,
	fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt); // Add score text to the top-center of the screen
// Add instruction in the center of the screen
var instruction = game.attachAsset('Instruction', {
	anchorX: 0.5,
	anchorY: 0.5
});
instruction.x = 2048 / 2;
instruction.y = 2732 / 2;
// Smoothly move instruction with a speed of 8
var moveInstruction = function moveInstruction() {
	var targetXLeft = instruction.x - 100; // Target position after moving left by 100 pixels
	var targetXRight = instruction.x + 100; // Target position after moving right by 200 pixels from original position
	var moveLeft = function moveLeft() {
		if (instruction.x > targetXLeft) {
			instruction.x -= 8; // Move instruction left by 8 pixels per tick
			LK.setTimeout(moveLeft, 1000 / 60); // Continue moving at 60FPS
		} else {
			moveRight();
		}
	};
	var moveRight = function moveRight() {
		if (instruction.x < targetXRight) {
			instruction.x += 8; // Move instruction right by 8 pixels per tick
			LK.setTimeout(moveRight, 1000 / 60); // Continue moving at 60FPS
		} else {
			instruction.visible = false; // Make instruction disappear after reaching target
		}
	};
	moveLeft();
};
moveInstruction(); // Start moving immediately without delay
// Update score based on game ticks
LK.on('tick', function () {
	scoreCounter = Math.floor(LK.ticks / 60); // Convert ticks to seconds for score
	scoreTxt.setText(scoreCounter.toString()); // Update score display
	scoreTxt.x = 0; // Move the timer 10 pixels to the right
	scoreTxt.y = 0; // Lower the timer by 10 pixels
	LK.setScore(scoreCounter); // Save the score the player has earned
});
// Set up game tick
LK.on('tick', function () {
	plane1.update();
	for (var j = 0; j < bullets.length; j++) {
		bullets[j].update();
	}
	for (var i = 0; i < enemyPlanes.length; i++) {
		enemyPlanes[i].update();
	}
});
// Flags to track if the screen is being touched
var isTouchingLeft = false;
var isTouchingRight = false;
// Change enemy direction when the screen is touched
var initialTouchPosition = null;
game.on('down', function (obj) {
	initialTouchPosition = obj.event.getLocalPosition(game);
});
game.on('move', function (obj) {
	if (initialTouchPosition) {
		var currentTouchPosition = obj.event.getLocalPosition(game);
		var swipeDirection = currentTouchPosition.x - initialTouchPosition.x;
		if (swipeDirection < 0) {
			isTouchingLeft = true;
			isTouchingRight = false;
		} else if (swipeDirection > 0) {
			isTouchingRight = true;
			isTouchingLeft = false;
		}
	}
});
// Stop changing enemy direction when the screen is no longer being touched
game.on('up', function (obj) {
	isTouchingLeft = false;
	isTouchingRight = false;
	initialTouchPosition = null;
});
// In the game tick, change plane direction while the screen is being touched
LK.on('tick', function () {
	if (isTouchingLeft) {
		var angle = Math.atan2(plane1.speedY, plane1.speedX);
		angle -= Math.PI / 60; // Subtract 1.5 degrees (in radians) for counter-clockwise rotation
		plane1.speedX = Math.cos(angle) * 7;
		plane1.speedY = Math.sin(angle) * 7;
		plane1.rotation -= Math.PI / 60; // Rotate the plane counter-clockwise
	}
	if (isTouchingRight && LK.ticks > 78) {
		var angle = Math.atan2(plane1.speedY, plane1.speedX);
		angle += Math.PI / 60; // Add 1.5 degrees (in radians) for clockwise rotation
		plane1.speedX = Math.cos(angle) * 7;
		plane1.speedY = Math.sin(angle) * 7;
		plane1.rotation += Math.PI / 60; // Rotate the plane clockwise
	}
	// Check if the plane crosses the side boundaries of the screen, touches the top or bottom of the screen, or collides with the health_bar
	if (plane1.x <= 70 || plane1.x >= 2170 - plane1.width || plane1.y <= 70 || plane1.y >= 2752 - plane1.height) {
		// Trigger game over
		LK.effects.flashScreen(0xff0000, 1000);
		LK.showGameOver("Final Score: " + scoreCounter.toString());
	}
	// Check if the bullet touches the player within a 100x100 square area
	for (var j = 0; j < bullets.length; j++) {
		if (bullets[j].visible && Math.abs(bullets[j].x - plane1.x) <= 50 && Math.abs(bullets[j].y - plane1.y) <= 50) {
			// Trigger game over
			LK.effects.flashScreen(0xff0000, 1000);
			LK.showGameOver("Final Score: " + scoreCounter.toString());
		}
	}
	// Check for collision between player and enemy planes
	for (var i = 0; i < enemyPlanes.length; i++) {
		if (plane1.x < enemyPlanes[i].x + 100 && plane1.x + 100 > enemyPlanes[i].x && plane1.y < enemyPlanes[i].y + 100 && plane1.y + 100 > enemyPlanes[i].y) {
			// Add a red flash screen effect
			LK.effects.flashScreen(0xff0000, 1000);
			// Trigger game over
			LK.showGameOver("Final Score: " + LK.getScore());
		}
	}
	// Delay the movement of the cannons by 4 seconds after the game starts
	LK.setTimeout(function () {
		if (cannon.x < 100) {
			cannon.x += 2;
		}
		if (cannon2.x > 1950) {
			cannon2.x -= 2;
		}
	}, 16000);
}); /**** 
* Classes
****/ 
var Bullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('bullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 8;
	self.visible = false;
	self.angle = Math.PI / 18 + Math.random() * (17 * Math.PI / 18); // Random angle between 10 and 170 degrees
	self.update = function () {
		if (LK.ticks > 240) {
			// 4 seconds at 60FPS
			self.visible = true;
			self.x += self.speed * Math.cos(self.angle);
			self.y -= self.speed * Math.sin(self.angle);
		}
	};
});
var Cannon = Container.expand(function () {
	var self = Container.call(this);
	var cannonGraphics = self.attachAsset('Cannon', {
		anchorX: 0.5,
		anchorY: 0.5
	});
});
// Cannon2 class
var Cannon2 = Container.expand(function () {
	var self = Container.call(this);
	var cannon2Graphics = self.attachAsset('Cannon2', {
		anchorX: 0.5,
		anchorY: 0.5
	});
});
// EnemyPlane class
var EnemyPlane = Container.expand(function () {
	var self = Container.call(this);
	var enemyPlaneGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speedX = -6;
	self.speedY = 0;
	// Update enemy plane position
	self.update = function () {
		self.x += self.speedX;
		// Smoothly adjust vertical position within a random range
		if (LK.ticks > 1500 && (!self.verticalTarget || Math.abs(self.verticalTarget - self.y) < 1)) {
			self.verticalTarget = self.y + (Math.random() > 0.5 ? Math.random() * 250 : -Math.random() * 250); // Set or reset target within a random range from 0 to 250 pixels
		}
		self.y += (self.verticalTarget - self.y) * 0.05; // Smoothly move towards the target
	};
});
// EnemyPlaneLeft class
var EnemyPlaneLeft = Container.expand(function () {
	var self = Container.call(this);
	var enemyPlaneGraphics = self.attachAsset('Enemyleft', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speedX = 6;
	self.speedY = 0;
	// Update enemy plane position
	self.update = function () {
		self.x += self.speedX;
		// Smoothly adjust vertical position within a random range
		if (LK.ticks > 1500 && (!self.verticalTarget || Math.abs(self.verticalTarget - self.y) < 1)) {
			self.verticalTarget = self.y + (Math.random() > 0.5 ? Math.random() * 250 : -Math.random() * 250); // Set or reset target within a random range from 0 to 250 pixels
		}
		self.y += (self.verticalTarget - self.y) * 0.05; // Smoothly move towards the target
	};
});
// Plane1 class
var Plane1 = Container.expand(function () {
	var self = Container.call(this);
	var planeGraphics = self.attachAsset('plane', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speedX = 7;
	self.speedY = 0;
	// Update plane position
	self.update = function () {
		self.x += self.speedX;
		self.y += self.speedY;
		// Check if the plane has crossed the screen boundary
		if (self.x < 0) {
			self.x = 2048;
		} else if (self.x > 2048) {
			self.x = 0;
		}
		// Prevent the plane from crossing the floor and ceiling
		if (self.y < 0) {
			self.y = 0;
			self.speedY = 0;
		} else if (self.y > 2752 - self.height) {
			self.y = 2752 - self.height;
			self.speedY = 0;
		}
	};
});
/**** 
* Initialize Game
****/ 
// Assets are automatically created based on usage in the code.
var game = new LK.Game({
	backgroundColor: 0xffffff // Init game with white background
});
/**** 
* Game Code
****/ 
var background2 = game.attachAsset('background2', {
	anchorX: 0.5,
	anchorY: 0.5,
	scaleX: 1,
	scaleY: 1
});
background2.x = 2175 / 2;
background2.y = 2620 / 2;
// Add background to the bottom of the game
var background = game.attachAsset('background', {
	anchorX: 0,
	anchorY: 1,
	scaleX: 1,
	scaleY: 1
});
background.y = 2732;
var enemyPlanes = []; // Global array to keep track of enemy planes
var enemyPlane; // Global variable to keep track of the enemy plane
// Create a player plane
var plane1 = new Plane1();
plane1.x = 150; // Moved 50 units to the right
plane1.y = 2750 - plane1.height; // Bottom of the screen
game.addChild(plane1);
// Create a cannon
var cannon = new Cannon();
cannon.x = -100; // Position at the bottom left of the screen
cannon.y = 2660;
game.addChild(cannon);
// Create a cannon2
var cannon2 = new Cannon2();
cannon2.x = 2150; // Position at the bottom left of the screen
cannon2.y = 2660;
game.addChild(cannon2);
var bullets = []; // Initialize an array to manage multiple bullets
LK.setTimeout(function () {
	var bulletSpawnInterval = LK.setInterval(function () {
		var newBullet = new Bullet();
		newBullet.x = 175;
		newBullet.y = 2590;
		game.addChild(newBullet);
		bullets.push(newBullet);
		var newBulletDuplicate = new Bullet();
		newBulletDuplicate.x = 1882; // New x position
		newBulletDuplicate.y = 2590; // New y position, same as original
		game.addChild(newBulletDuplicate);
		bullets.push(newBulletDuplicate);
	}, 800); // Spawn a new bullet every second, starting from the fourth second
}, 18000);
// Create the rest of the enemy planes every 2 seconds for the first 7 seconds
var enemySpawnTimer = LK.setInterval(function () {
	enemyPlane = new EnemyPlane();
	enemyPlane.x = 2150;
	enemyPlane.y = 100 + Math.random() * (2732 - enemyPlane.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
	game.addChild(enemyPlane);
	enemyPlanes.push(enemyPlane);
	var enemyPlaneLeft = new EnemyPlaneLeft();
	enemyPlaneLeft.x = -100;
	enemyPlaneLeft.y = 100 + Math.random() * (2732 - enemyPlaneLeft.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
	game.addChild(enemyPlaneLeft);
	enemyPlanes.push(enemyPlaneLeft);
}, 1300);
// After 7 seconds, change the enemy spawn interval to 1 every 1.3 seconds
LK.setTimeout(function () {
	LK.clearInterval(enemySpawnTimer);
	enemySpawnTimer = LK.setInterval(function () {
		enemyPlane = new EnemyPlane();
		enemyPlane.x = 2150;
		enemyPlane.y = 100 + Math.random() * (2732 - enemyPlane.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
		game.addChild(enemyPlane);
		enemyPlanes.push(enemyPlane);
		var enemyPlaneLeft = new EnemyPlaneLeft();
		enemyPlaneLeft.x = -100;
		enemyPlaneLeft.y = 100 + Math.random() * (2732 - enemyPlaneLeft.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
		game.addChild(enemyPlaneLeft);
		enemyPlanes.push(enemyPlaneLeft);
	}, 1100);
}, 5000);
// After 14 seconds, change the enemy spawn interval to 1 every second
LK.setTimeout(function () {
	LK.clearInterval(enemySpawnTimer);
	enemySpawnTimer = LK.setInterval(function () {
		enemyPlane = new EnemyPlane();
		enemyPlane.x = 2150;
		enemyPlane.y = 100 + Math.random() * (2732 - enemyPlane.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
		game.addChild(enemyPlane);
		enemyPlanes.push(enemyPlane);
		var enemyPlaneLeft = new EnemyPlaneLeft();
		enemyPlaneLeft.x = -100;
		enemyPlaneLeft.y = 100 + Math.random() * (2732 - enemyPlaneLeft.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
		game.addChild(enemyPlaneLeft);
		enemyPlanes.push(enemyPlaneLeft);
	}, 900);
}, 11000);
// Initialize score based on game ticks
var scoreCounter = 0;
var scoreTxt = new Text2(scoreCounter.toString(), {
	size: 70,
	fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt); // Add score text to the top-center of the screen
// Add instruction in the center of the screen
var instruction = game.attachAsset('Instruction', {
	anchorX: 0.5,
	anchorY: 0.5
});
instruction.x = 2048 / 2;
instruction.y = 2732 / 2;
// Smoothly move instruction with a speed of 8
var moveInstruction = function moveInstruction() {
	var targetXLeft = instruction.x - 100; // Target position after moving left by 100 pixels
	var targetXRight = instruction.x + 100; // Target position after moving right by 200 pixels from original position
	var moveLeft = function moveLeft() {
		if (instruction.x > targetXLeft) {
			instruction.x -= 8; // Move instruction left by 8 pixels per tick
			LK.setTimeout(moveLeft, 1000 / 60); // Continue moving at 60FPS
		} else {
			moveRight();
		}
	};
	var moveRight = function moveRight() {
		if (instruction.x < targetXRight) {
			instruction.x += 8; // Move instruction right by 8 pixels per tick
			LK.setTimeout(moveRight, 1000 / 60); // Continue moving at 60FPS
		} else {
			instruction.visible = false; // Make instruction disappear after reaching target
		}
	};
	moveLeft();
};
moveInstruction(); // Start moving immediately without delay
// Update score based on game ticks
LK.on('tick', function () {
	scoreCounter = Math.floor(LK.ticks / 60); // Convert ticks to seconds for score
	scoreTxt.setText(scoreCounter.toString()); // Update score display
	scoreTxt.x = 0; // Move the timer 10 pixels to the right
	scoreTxt.y = 0; // Lower the timer by 10 pixels
	LK.setScore(scoreCounter); // Save the score the player has earned
});
// Set up game tick
LK.on('tick', function () {
	plane1.update();
	for (var j = 0; j < bullets.length; j++) {
		bullets[j].update();
	}
	for (var i = 0; i < enemyPlanes.length; i++) {
		enemyPlanes[i].update();
	}
});
// Flags to track if the screen is being touched
var isTouchingLeft = false;
var isTouchingRight = false;
// Change enemy direction when the screen is touched
var initialTouchPosition = null;
game.on('down', function (obj) {
	initialTouchPosition = obj.event.getLocalPosition(game);
});
game.on('move', function (obj) {
	if (initialTouchPosition) {
		var currentTouchPosition = obj.event.getLocalPosition(game);
		var swipeDirection = currentTouchPosition.x - initialTouchPosition.x;
		if (swipeDirection < 0) {
			isTouchingLeft = true;
			isTouchingRight = false;
		} else if (swipeDirection > 0) {
			isTouchingRight = true;
			isTouchingLeft = false;
		}
	}
});
// Stop changing enemy direction when the screen is no longer being touched
game.on('up', function (obj) {
	isTouchingLeft = false;
	isTouchingRight = false;
	initialTouchPosition = null;
});
// In the game tick, change plane direction while the screen is being touched
LK.on('tick', function () {
	if (isTouchingLeft) {
		var angle = Math.atan2(plane1.speedY, plane1.speedX);
		angle -= Math.PI / 60; // Subtract 1.5 degrees (in radians) for counter-clockwise rotation
		plane1.speedX = Math.cos(angle) * 7;
		plane1.speedY = Math.sin(angle) * 7;
		plane1.rotation -= Math.PI / 60; // Rotate the plane counter-clockwise
	}
	if (isTouchingRight && LK.ticks > 78) {
		var angle = Math.atan2(plane1.speedY, plane1.speedX);
		angle += Math.PI / 60; // Add 1.5 degrees (in radians) for clockwise rotation
		plane1.speedX = Math.cos(angle) * 7;
		plane1.speedY = Math.sin(angle) * 7;
		plane1.rotation += Math.PI / 60; // Rotate the plane clockwise
	}
	// Check if the plane crosses the side boundaries of the screen, touches the top or bottom of the screen, or collides with the health_bar
	if (plane1.x <= 70 || plane1.x >= 2170 - plane1.width || plane1.y <= 70 || plane1.y >= 2752 - plane1.height) {
		// Trigger game over
		LK.effects.flashScreen(0xff0000, 1000);
		LK.showGameOver("Final Score: " + scoreCounter.toString());
	}
	// Check if the bullet touches the player within a 100x100 square area
	for (var j = 0; j < bullets.length; j++) {
		if (bullets[j].visible && Math.abs(bullets[j].x - plane1.x) <= 50 && Math.abs(bullets[j].y - plane1.y) <= 50) {
			// Trigger game over
			LK.effects.flashScreen(0xff0000, 1000);
			LK.showGameOver("Final Score: " + scoreCounter.toString());
		}
	}
	// Check for collision between player and enemy planes
	for (var i = 0; i < enemyPlanes.length; i++) {
		if (plane1.x < enemyPlanes[i].x + 100 && plane1.x + 100 > enemyPlanes[i].x && plane1.y < enemyPlanes[i].y + 100 && plane1.y + 100 > enemyPlanes[i].y) {
			// Add a red flash screen effect
			LK.effects.flashScreen(0xff0000, 1000);
			// Trigger game over
			LK.showGameOver("Final Score: " + LK.getScore());
		}
	}
	// Delay the movement of the cannons by 4 seconds after the game starts
	LK.setTimeout(function () {
		if (cannon.x < 100) {
			cannon.x += 2;
		}
		if (cannon2.x > 1950) {
			cannon2.x -= 2;
		}
	}, 16000);
});
 
 снаряд от пушки. 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.
 Нажатие по экрану. Палец. Мультяшный. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.