/**** 
* Classes
****/ 
// Obstacle class
var Obstacle = Container.expand(function () {
	var self = Container.call(this);
	var obstacleGraphics = self.attachAsset('obstacle', {
		anchorX: 0.5,
		anchorY: 1.0
	});
	self.speed = -5;
	self.move = function () {
		self.x += self.speed;
	};
});
// Assets will be automatically created based on usage in the code.
// Pony class
var Pony = Container.expand(function () {
	var self = Container.call(this);
	var ponyGraphics = self.attachAsset('pony', {
		anchorX: 0.5,
		anchorY: 0.5,
		width: 162,
		// Reduced width for a smaller hitbox
		height: 162 // Reduced height for a smaller hitbox
	});
	self.jumpSpeed = -30;
	self.gravity = 0.5;
	self.velocity = 0;
	self.isJumping = false;
	self.jump = function () {
		if (!self.isJumping) {
			self.velocity = self.jumpSpeed;
			self.isJumping = true;
		}
	};
	self.update = function () {
		self.y += self.velocity;
		self.velocity += self.gravity;
		if (self.y > game.floorLevel) {
			self.y = game.floorLevel;
			self.isJumping = false;
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x87CEEB // Light blue background
});
/**** 
* Game Code
****/ 
// Game variables
var forestBackground = game.addChild(LK.getAsset('forest', {
	anchorX: 0.0,
	anchorY: 0.0,
	x: 0,
	y: 0
}));
game.floorLevel = 2732 - 200; // Floor level where the pony runs
game.obstacles = [];
game.score = 0;
game.pony = game.addChild(new Pony());
game.pony.x = 400;
game.pony.y = game.floorLevel;
// Score display
var scoreTxt = new Text2('0', {
	size: 150,
	fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Game timer display
var timerTxt = new Text2('0:00', {
	size: 150,
	fill: "#ffffff"
});
LK.gui.topRight.addChild(timerTxt);
// Initialize timer variables
game.timerSeconds = 0;
game.timerMinutes = 0;
// Update timer every second
LK.setInterval(function () {
	game.timerSeconds++;
	if (game.timerSeconds >= 60) {
		game.timerMinutes++;
		game.timerSeconds = 0;
	}
	var formattedTime = game.timerMinutes + ':' + (game.timerSeconds < 10 ? '0' : '') + game.timerSeconds;
	timerTxt.setText(formattedTime);
}, 1000);
// Game tick event
LK.on('tick', function () {
	game.pony.update();
	// Move and check obstacles
	for (var i = game.obstacles.length - 1; i >= 0; i--) {
		game.obstacles[i].move();
		if (game.obstacles[i].x < -100) {
			// Off-screen
			game.obstacles[i].destroy();
			game.obstacles.splice(i, 1);
		} else if (game.pony.intersects(game.obstacles[i])) {
			LK.effects.flashScreen(0xff0000, 1000);
			LK.showGameOver();
		}
	}
	// Increase score over time
	if (LK.ticks % 60 == 0) {
		// Every second
		game.score += 1;
		scoreTxt.setText(game.score.toString());
	}
	// Add obstacles
	if (LK.ticks % 300 == 0) {
		// Every 5 seconds
		var newObstacle = new Obstacle();
		newObstacle.x = 2048;
		newObstacle.y = game.floorLevel;
		game.obstacles.push(newObstacle);
		game.addChild(newObstacle);
	}
});
// Touch event to make the pony jump
game.on('down', function (obj) {
	if (!game.pony.isJumping) {
		game.pony.jump();
		LK.setTimeout(function () {
			game.pony.isJumping = false;
		}, 1000);
	}
}); /**** 
* Classes
****/ 
// Obstacle class
var Obstacle = Container.expand(function () {
	var self = Container.call(this);
	var obstacleGraphics = self.attachAsset('obstacle', {
		anchorX: 0.5,
		anchorY: 1.0
	});
	self.speed = -5;
	self.move = function () {
		self.x += self.speed;
	};
});
// Assets will be automatically created based on usage in the code.
// Pony class
var Pony = Container.expand(function () {
	var self = Container.call(this);
	var ponyGraphics = self.attachAsset('pony', {
		anchorX: 0.5,
		anchorY: 0.5,
		width: 162,
		// Reduced width for a smaller hitbox
		height: 162 // Reduced height for a smaller hitbox
	});
	self.jumpSpeed = -30;
	self.gravity = 0.5;
	self.velocity = 0;
	self.isJumping = false;
	self.jump = function () {
		if (!self.isJumping) {
			self.velocity = self.jumpSpeed;
			self.isJumping = true;
		}
	};
	self.update = function () {
		self.y += self.velocity;
		self.velocity += self.gravity;
		if (self.y > game.floorLevel) {
			self.y = game.floorLevel;
			self.isJumping = false;
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x87CEEB // Light blue background
});
/**** 
* Game Code
****/ 
// Game variables
var forestBackground = game.addChild(LK.getAsset('forest', {
	anchorX: 0.0,
	anchorY: 0.0,
	x: 0,
	y: 0
}));
game.floorLevel = 2732 - 200; // Floor level where the pony runs
game.obstacles = [];
game.score = 0;
game.pony = game.addChild(new Pony());
game.pony.x = 400;
game.pony.y = game.floorLevel;
// Score display
var scoreTxt = new Text2('0', {
	size: 150,
	fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Game timer display
var timerTxt = new Text2('0:00', {
	size: 150,
	fill: "#ffffff"
});
LK.gui.topRight.addChild(timerTxt);
// Initialize timer variables
game.timerSeconds = 0;
game.timerMinutes = 0;
// Update timer every second
LK.setInterval(function () {
	game.timerSeconds++;
	if (game.timerSeconds >= 60) {
		game.timerMinutes++;
		game.timerSeconds = 0;
	}
	var formattedTime = game.timerMinutes + ':' + (game.timerSeconds < 10 ? '0' : '') + game.timerSeconds;
	timerTxt.setText(formattedTime);
}, 1000);
// Game tick event
LK.on('tick', function () {
	game.pony.update();
	// Move and check obstacles
	for (var i = game.obstacles.length - 1; i >= 0; i--) {
		game.obstacles[i].move();
		if (game.obstacles[i].x < -100) {
			// Off-screen
			game.obstacles[i].destroy();
			game.obstacles.splice(i, 1);
		} else if (game.pony.intersects(game.obstacles[i])) {
			LK.effects.flashScreen(0xff0000, 1000);
			LK.showGameOver();
		}
	}
	// Increase score over time
	if (LK.ticks % 60 == 0) {
		// Every second
		game.score += 1;
		scoreTxt.setText(game.score.toString());
	}
	// Add obstacles
	if (LK.ticks % 300 == 0) {
		// Every 5 seconds
		var newObstacle = new Obstacle();
		newObstacle.x = 2048;
		newObstacle.y = game.floorLevel;
		game.obstacles.push(newObstacle);
		game.addChild(newObstacle);
	}
});
// Touch event to make the pony jump
game.on('down', function (obj) {
	if (!game.pony.isJumping) {
		game.pony.jump();
		LK.setTimeout(function () {
			game.pony.isJumping = false;
		}, 1000);
	}
});