/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Car = Container.expand(function (direction, speed, lane) { var self = Container.call(this); var carGraphics = self.attachAsset('car', { anchorX: 0.5, anchorY: 0.5 }); self.direction = direction; // 1 for right, -1 for left self.speed = speed; self.lane = lane; // Position car based on direction if (self.direction === 1) { self.x = -60; // Start from left } else { self.x = 2048 + 60; // Start from right } self.y = 2732 - 250 - lane * 180; // Position in center of road with original spacing self.update = function () { self.x += self.speed * self.direction; // Remove car when it goes off screen if (self.direction === 1 && self.x > 2048 + 100) { self.removeFromParent = true; } else if (self.direction === -1 && self.x < -100) { self.removeFromParent = true; } }; return self; }); var Chicken = Container.expand(function () { var self = Container.call(this); var chickenGraphics = self.attachAsset('chicken', { anchorX: 0.5, anchorY: 0.5 }); self.moveStep = 100; self.isMoving = false; self.targetY = 2732 - 100; // Start near bottom self.moveForward = function () { if (self.isMoving) return; self.isMoving = true; // Calculate next valid road position var currentY = self.y; var nextRoadY = null; var roadSpacing = 180; var startY = 2732 - 250; // Find the next road position above current position for (var i = 0; i < 12; i++) { var roadY = startY - i * roadSpacing; if (roadY < currentY && roadY >= 0) { nextRoadY = roadY; break; } } // If no road found above, move to finish line if (nextRoadY === null) { nextRoadY = 50; } // Animate movement directly to next road tween(self, { y: nextRoadY }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { self.isMoving = false; // Check if crossed a road if (self.y < 150) { // Crossed all roads, reset and increase score crossedRoad(); } } }); LK.getSound('move').play(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x4CAF50 }); /**** * Game Code ****/ var chicken; var cars = []; var roads = []; var gameSpeed = 1; var carSpawnTimer = 0; var carSpawnRate = 40; // frames between car spawns - fewer cars var crossedRoads = 0; var bonusMode = false; var questionAsked = false; var waitingForAnswer = false; var playerHealth = 2; // Player can take 2 hits before dying var invincibilityMode = false; // Cheat mode for invincibility - deactivated var chatInput = ''; // Store chat input var carsPerLane = []; // Track number of cars in each lane // Question system variables var currentLevel = storage.currentLevel || 1; var correctAnswers = 0; var wrongAnswers = 0; var currentQuestion = ''; var questionOptions = []; var correctAnswer = ''; var questionIndex = 0; // Question sets by difficulty level var questionSets = { 1: [{ q: "2 + 2 = ?", options: ["3", "4", "5", "6"], correct: "4" }, { q: "5 - 3 = ?", options: ["1", "2", "3", "4"], correct: "2" }, { q: "3 × 2 = ?", options: ["5", "6", "7", "8"], correct: "6" }, { q: "8 ÷ 2 = ?", options: ["3", "4", "5", "6"], correct: "4" }, { q: "1 + 1 = ?", options: ["1", "2", "3", "4"], correct: "2" }, { q: "6 - 4 = ?", options: ["1", "2", "3", "4"], correct: "2" }, { q: "4 × 3 = ?", options: ["10", "11", "12", "13"], correct: "12" }, { q: "9 ÷ 3 = ?", options: ["2", "3", "4", "5"], correct: "3" }, { q: "7 + 3 = ?", options: ["9", "10", "11", "12"], correct: "10" }, { q: "10 - 5 = ?", options: ["4", "5", "6", "7"], correct: "5" }], 2: [{ q: "15 + 27 = ?", options: ["40", "41", "42", "43"], correct: "42" }, { q: "84 - 36 = ?", options: ["46", "47", "48", "49"], correct: "48" }, { q: "12 × 7 = ?", options: ["82", "83", "84", "85"], correct: "84" }, { q: "96 ÷ 8 = ?", options: ["11", "12", "13", "14"], correct: "12" }, { q: "25 + 39 = ?", options: ["62", "63", "64", "65"], correct: "64" }, { q: "73 - 28 = ?", options: ["43", "44", "45", "46"], correct: "45" }, { q: "9 × 6 = ?", options: ["52", "53", "54", "55"], correct: "54" }, { q: "72 ÷ 9 = ?", options: ["7", "8", "9", "10"], correct: "8" }, { q: "46 + 17 = ?", options: ["61", "62", "63", "64"], correct: "63" }, { q: "81 - 35 = ?", options: ["44", "45", "46", "47"], correct: "46" }], 3: [{ q: "127 + 248 = ?", options: ["373", "374", "375", "376"], correct: "375" }, { q: "543 - 187 = ?", options: ["354", "355", "356", "357"], correct: "356" }, { q: "23 × 15 = ?", options: ["343", "344", "345", "346"], correct: "345" }, { q: "384 ÷ 12 = ?", options: ["30", "31", "32", "33"], correct: "32" }, { q: "289 + 156 = ?", options: ["443", "444", "445", "446"], correct: "445" }, { q: "672 - 298 = ?", options: ["372", "373", "374", "375"], correct: "374" }, { q: "17 × 24 = ?", options: ["406", "407", "408", "409"], correct: "408" }, { q: "456 ÷ 24 = ?", options: ["17", "18", "19", "20"], correct: "19" }, { q: "365 + 278 = ?", options: ["641", "642", "643", "644"], correct: "643" }, { q: "834 - 467 = ?", options: ["365", "366", "367", "368"], correct: "367" }] }; var answerButtons = []; var currentQuestionShown = false; // Create score display var scoreTxt = new Text2('0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0.5); scoreTxt.x = 1024; // Center horizontally scoreTxt.y = 50; // Position at the top end of roads game.addChild(scoreTxt); // Create bonus question UI elements var questionTxt = new Text2('Bonus puan denemek ister misin?', { size: 60, fill: 0xFFFFFF }); questionTxt.anchor.set(0.5, 0.5); questionTxt.x = 1024; questionTxt.y = 1366; questionTxt.visible = false; game.addChild(questionTxt); var bonusBtn = new Text2('BONUS', { size: 50, fill: 0x00FF00 }); bonusBtn.anchor.set(0.5, 0.5); bonusBtn.x = 850; bonusBtn.y = 1500; bonusBtn.visible = false; game.addChild(bonusBtn); var continueBtn = new Text2('DEVAM ET', { size: 50, fill: 0x0080FF }); continueBtn.anchor.set(0.5, 0.5); continueBtn.x = 1200; continueBtn.y = 1500; continueBtn.visible = false; game.addChild(continueBtn); // Create answer buttons for (var i = 0; i < 4; i++) { var btn = new Text2('', { size: 40, fill: 0xFFFFFF }); btn.anchor.set(0.5, 0.5); btn.x = 512 + i * 256; btn.y = 1600; btn.visible = false; btn.buttonIndex = i; answerButtons.push(btn); game.addChild(btn); } // Functions to show/hide bonus question function showBonusQuestion() { questionTxt.visible = true; bonusBtn.visible = true; continueBtn.visible = true; waitingForAnswer = true; } function hideBonusQuestion() { questionTxt.visible = false; bonusBtn.visible = false; continueBtn.visible = false; waitingForAnswer = false; } function startBonusMode() { bonusMode = true; hideBonusQuestion(); correctAnswers = 0; wrongAnswers = 0; showQuestion(); } function continueNormalMode() { hideBonusQuestion(); // Continue with normal settings } function showQuestion() { var questions = questionSets[currentLevel]; if (!questions || questionIndex >= questions.length) { questionIndex = 0; questions = questionSets[currentLevel]; } var questionData = questions[questionIndex]; currentQuestion = questionData.q; questionOptions = questionData.options; correctAnswer = questionData.correct; questionTxt.setText(currentQuestion); questionTxt.visible = true; for (var i = 0; i < 4; i++) { answerButtons[i].setText(questionOptions[i]); answerButtons[i].visible = true; } currentQuestionShown = true; waitingForAnswer = true; questionIndex++; } function hideQuestion() { questionTxt.visible = false; for (var i = 0; i < 4; i++) { answerButtons[i].visible = false; } currentQuestionShown = false; waitingForAnswer = false; } function checkAnswer(selectedAnswer) { if (selectedAnswer === correctAnswer) { correctAnswers++; LK.effects.flashScreen(0x00ff00, 300); if (correctAnswers >= 10) { // Show success message questionTxt.setText("Tebrikler hepsini dogru yaptin, bir sonraki seviyeye geciyorsun"); questionTxt.visible = true; // Hide answer buttons for (var i = 0; i < 4; i++) { answerButtons[i].visible = false; } // Level up after 2 seconds LK.setTimeout(function () { currentLevel++; storage.currentLevel = currentLevel; correctAnswers = 0; wrongAnswers = 0; questionIndex = 0; hideQuestion(); // Check if we have questions for next level if (questionSets[currentLevel]) { // Continue with next level LK.setTimeout(function () { showQuestion(); }, 500); } else { // No more levels, return to normal game bonusMode = false; questionAsked = false; gameSpeed = 1; carSpawnRate = 40; chicken.y = 2732 - 100; crossedRoads = 0; hideQuestion(); waitingForAnswer = false; } }, 2000); } else { // Show next question LK.setTimeout(function () { showQuestion(); }, 500); } } else { wrongAnswers++; LK.effects.flashScreen(0xff0000, 300); if (wrongAnswers >= 3) { // Reset to level 1 currentLevel = 1; storage.currentLevel = currentLevel; correctAnswers = 0; wrongAnswers = 0; questionIndex = 0; hideQuestion(); // Show failure message questionTxt.setText("3 yanlis yaptiniz, basa donuyorsunuz"); questionTxt.visible = true; LK.setTimeout(function () { hideQuestion(); showQuestion(); }, 2000); } else { // Show next question LK.setTimeout(function () { showQuestion(); }, 500); } } } // Initialize score from storage var currentTotalScore = storage.totalScore || 0; LK.setScore(currentTotalScore); scoreTxt.setText(currentTotalScore.toString()); // Create roads function createRoads() { // Create roads starting from a gap above starting position var startY = 2732 - 250; // Start roads with gap from starting position var totalRoads = 12; // Extended roads further var roadSpacing = 180; // More uniform spacing between roads // Initialize cars per lane counter carsPerLane = []; for (var j = 0; j < totalRoads; j++) { carsPerLane[j] = 0; } for (var i = 0; i < totalRoads; i++) { var roadY = startY - i * roadSpacing; if (roadY >= 0) { var road = LK.getAsset('road', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: roadY }); roads.push(road); game.addChild(road); // Add road lines at the edges of roads for better visual separation var roadLineTop = LK.getAsset('roadLine', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: roadY - 75 }); game.addChild(roadLineTop); var roadLineBottom = LK.getAsset('roadLine', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: roadY + 75 }); game.addChild(roadLineBottom); } } } // Create chicken function createChicken() { chicken = game.addChild(new Chicken()); chicken.x = 1024; // Center horizontally chicken.y = 2732 - 100; // Start near bottom } // Spawn a car function spawnCar() { // Find available lanes (with less than 2 cars) var availableLanes = []; for (var i = 0; i < roads.length; i++) { if (carsPerLane[i] < 2) { availableLanes.push(i); } } // Only spawn if there are available lanes if (availableLanes.length > 0) { var lane = availableLanes[Math.floor(Math.random() * availableLanes.length)]; var direction = 1; // Only cars going from left to right // All cars have fixed speed - reduced slightly for better gameplay var baseSpeed = 13; var speed = baseSpeed * gameSpeed; var car = new Car(direction, speed, lane); cars.push(car); game.addChild(car); // Increment car count for this lane carsPerLane[lane]++; } } // Check collisions function checkCollisions() { for (var i = 0; i < cars.length; i++) { var car = cars[i]; if (chicken.intersects(car) && !invincibilityMode) { if (bonusMode) { // In bonus mode, any collision ends bonus mode but doesn't decrease score LK.getSound('hit').play(); LK.effects.flashScreen(0xff4444, 500); bonusMode = false; questionAsked = false; // Reset game settings to normal gameSpeed = 1; carSpawnRate = 25; // Reset chicken position and health chicken.y = 2732 - 100; crossedRoads = 0; playerHealth = 2; // Reset health return; } else { // Reduce health on any car collision playerHealth--; if (playerHealth > 0) { // First hit - injury, player survives LK.getSound('hit').play(); // Create injury effect - flash red and shake LK.effects.flashScreen(0xff4444, 300); tween(chicken, { x: chicken.x + 20 }, { duration: 50, easing: tween.easeOut, onFinish: function onFinish() { tween(chicken, { x: chicken.x - 40 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(chicken, { x: chicken.x + 20 }, { duration: 50, easing: tween.easeIn }); } }); } }); } else { // Second hit - death, game over and reset score LK.getSound('dead').play(); LK.effects.flashScreen(0xff0000, 500); // Reset score to 0 storage.totalScore = 0; LK.setScore(0); scoreTxt.setText('0'); // Reset health for next game playerHealth = 2; LK.setTimeout(function () { LK.showGameOver(); }, 500); return; } // Remove the car after collision carsPerLane[car.lane]--; car.removeFromParent = true; } } } } // Handle successful road crossing function crossedRoad() { crossedRoads++; var totalScore = storage.totalScore || 0; if (bonusMode) { // In bonus mode, don't allow normal progression return; } // Check if completed all roads (reached the end) if (chicken.y <= 50) { // Completed all roads - give 1 point and reset to start totalScore += 1; storage.totalScore = totalScore; LK.setScore(totalScore); scoreTxt.setText(totalScore.toString()); // Reset chicken position to starting position when score increases chicken.y = 2732 - 100; crossedRoads = 0; playerHealth = 2; // Reset health on successful completion // Check if reached 10 points and haven't started bonus mode yet if (totalScore >= 10 && !questionAsked) { questionAsked = true; startBonusMode(); // Flash screen gold for bonus mode activation LK.effects.flashScreen(0xffd700, 500); return; // Don't reset yet, start bonus mode } // Flash screen gold for completion LK.effects.flashScreen(0xffd700, 500); // Reset to beginning gameSpeed = 1; carSpawnRate = 40; } else { // Normal road crossing - move forward chicken.y = 2732 - 100; // Increase difficulty gameSpeed += 0.1; if (carSpawnRate > 30) { carSpawnRate -= 2; } // Flash screen green for success LK.effects.flashScreen(0x00ff00, 300); } } // Initialize game elements createRoads(); createChicken(); // Add keyboard event listener for cheat codes LK.on('keydown', function (event) { var key = String.fromCharCode(event.keyCode).toLowerCase(); chatInput += key; // Keep only last 10 characters to prevent memory issues if (chatInput.length > 10) { chatInput = chatInput.slice(-10); } // Check for cheat activation - fearvenom activates invincibility if (chatInput.includes('fearvenom') && !chatInput.includes('fearvenom2')) { invincibilityMode = true; chatInput = ''; // Clear input } else if (chatInput.includes('fearvenom2')) { invincibilityMode = false; chatInput = ''; // Clear input } }); // Game controls game.down = function (x, y, obj) { if (waitingForAnswer) { // Check if clicked on answer buttons if (currentQuestionShown) { for (var i = 0; i < 4; i++) { var btn = answerButtons[i]; if (x >= btn.x - 120 && x <= btn.x + 120 && y >= btn.y - 30 && y <= btn.y + 30) { checkAnswer(btn.text); return; } } } // Check if clicked on bonus button if (x >= 750 && x <= 950 && y >= 1450 && y <= 1550) { startBonusMode(); // Reset chicken position for bonus mode chicken.y = 2732 - 100; crossedRoads = 0; return; } // Check if clicked on continue button if (x >= 1100 && x <= 1300 && y >= 1450 && y <= 1550) { continueNormalMode(); // Reset chicken position for normal mode chicken.y = 2732 - 100; crossedRoads = 0; return; } } if (chicken && !chicken.isMoving && !waitingForAnswer) { chicken.moveForward(); } }; // Main game loop game.update = function () { // Spawn cars carSpawnTimer++; if (carSpawnTimer >= carSpawnRate) { spawnCar(); carSpawnTimer = 0; } // Clean up cars that are off screen for (var i = cars.length - 1; i >= 0; i--) { var car = cars[i]; if (car.removeFromParent) { // Decrement car count for this lane carsPerLane[car.lane]--; car.destroy(); cars.splice(i, 1); } } // Check collisions checkCollisions(); };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Car = Container.expand(function (direction, speed, lane) {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = direction; // 1 for right, -1 for left
self.speed = speed;
self.lane = lane;
// Position car based on direction
if (self.direction === 1) {
self.x = -60; // Start from left
} else {
self.x = 2048 + 60; // Start from right
}
self.y = 2732 - 250 - lane * 180; // Position in center of road with original spacing
self.update = function () {
self.x += self.speed * self.direction;
// Remove car when it goes off screen
if (self.direction === 1 && self.x > 2048 + 100) {
self.removeFromParent = true;
} else if (self.direction === -1 && self.x < -100) {
self.removeFromParent = true;
}
};
return self;
});
var Chicken = Container.expand(function () {
var self = Container.call(this);
var chickenGraphics = self.attachAsset('chicken', {
anchorX: 0.5,
anchorY: 0.5
});
self.moveStep = 100;
self.isMoving = false;
self.targetY = 2732 - 100; // Start near bottom
self.moveForward = function () {
if (self.isMoving) return;
self.isMoving = true;
// Calculate next valid road position
var currentY = self.y;
var nextRoadY = null;
var roadSpacing = 180;
var startY = 2732 - 250;
// Find the next road position above current position
for (var i = 0; i < 12; i++) {
var roadY = startY - i * roadSpacing;
if (roadY < currentY && roadY >= 0) {
nextRoadY = roadY;
break;
}
}
// If no road found above, move to finish line
if (nextRoadY === null) {
nextRoadY = 50;
}
// Animate movement directly to next road
tween(self, {
y: nextRoadY
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isMoving = false;
// Check if crossed a road
if (self.y < 150) {
// Crossed all roads, reset and increase score
crossedRoad();
}
}
});
LK.getSound('move').play();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x4CAF50
});
/****
* Game Code
****/
var chicken;
var cars = [];
var roads = [];
var gameSpeed = 1;
var carSpawnTimer = 0;
var carSpawnRate = 40; // frames between car spawns - fewer cars
var crossedRoads = 0;
var bonusMode = false;
var questionAsked = false;
var waitingForAnswer = false;
var playerHealth = 2; // Player can take 2 hits before dying
var invincibilityMode = false; // Cheat mode for invincibility - deactivated
var chatInput = ''; // Store chat input
var carsPerLane = []; // Track number of cars in each lane
// Question system variables
var currentLevel = storage.currentLevel || 1;
var correctAnswers = 0;
var wrongAnswers = 0;
var currentQuestion = '';
var questionOptions = [];
var correctAnswer = '';
var questionIndex = 0;
// Question sets by difficulty level
var questionSets = {
1: [{
q: "2 + 2 = ?",
options: ["3", "4", "5", "6"],
correct: "4"
}, {
q: "5 - 3 = ?",
options: ["1", "2", "3", "4"],
correct: "2"
}, {
q: "3 × 2 = ?",
options: ["5", "6", "7", "8"],
correct: "6"
}, {
q: "8 ÷ 2 = ?",
options: ["3", "4", "5", "6"],
correct: "4"
}, {
q: "1 + 1 = ?",
options: ["1", "2", "3", "4"],
correct: "2"
}, {
q: "6 - 4 = ?",
options: ["1", "2", "3", "4"],
correct: "2"
}, {
q: "4 × 3 = ?",
options: ["10", "11", "12", "13"],
correct: "12"
}, {
q: "9 ÷ 3 = ?",
options: ["2", "3", "4", "5"],
correct: "3"
}, {
q: "7 + 3 = ?",
options: ["9", "10", "11", "12"],
correct: "10"
}, {
q: "10 - 5 = ?",
options: ["4", "5", "6", "7"],
correct: "5"
}],
2: [{
q: "15 + 27 = ?",
options: ["40", "41", "42", "43"],
correct: "42"
}, {
q: "84 - 36 = ?",
options: ["46", "47", "48", "49"],
correct: "48"
}, {
q: "12 × 7 = ?",
options: ["82", "83", "84", "85"],
correct: "84"
}, {
q: "96 ÷ 8 = ?",
options: ["11", "12", "13", "14"],
correct: "12"
}, {
q: "25 + 39 = ?",
options: ["62", "63", "64", "65"],
correct: "64"
}, {
q: "73 - 28 = ?",
options: ["43", "44", "45", "46"],
correct: "45"
}, {
q: "9 × 6 = ?",
options: ["52", "53", "54", "55"],
correct: "54"
}, {
q: "72 ÷ 9 = ?",
options: ["7", "8", "9", "10"],
correct: "8"
}, {
q: "46 + 17 = ?",
options: ["61", "62", "63", "64"],
correct: "63"
}, {
q: "81 - 35 = ?",
options: ["44", "45", "46", "47"],
correct: "46"
}],
3: [{
q: "127 + 248 = ?",
options: ["373", "374", "375", "376"],
correct: "375"
}, {
q: "543 - 187 = ?",
options: ["354", "355", "356", "357"],
correct: "356"
}, {
q: "23 × 15 = ?",
options: ["343", "344", "345", "346"],
correct: "345"
}, {
q: "384 ÷ 12 = ?",
options: ["30", "31", "32", "33"],
correct: "32"
}, {
q: "289 + 156 = ?",
options: ["443", "444", "445", "446"],
correct: "445"
}, {
q: "672 - 298 = ?",
options: ["372", "373", "374", "375"],
correct: "374"
}, {
q: "17 × 24 = ?",
options: ["406", "407", "408", "409"],
correct: "408"
}, {
q: "456 ÷ 24 = ?",
options: ["17", "18", "19", "20"],
correct: "19"
}, {
q: "365 + 278 = ?",
options: ["641", "642", "643", "644"],
correct: "643"
}, {
q: "834 - 467 = ?",
options: ["365", "366", "367", "368"],
correct: "367"
}]
};
var answerButtons = [];
var currentQuestionShown = false;
// Create score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0.5);
scoreTxt.x = 1024; // Center horizontally
scoreTxt.y = 50; // Position at the top end of roads
game.addChild(scoreTxt);
// Create bonus question UI elements
var questionTxt = new Text2('Bonus puan denemek ister misin?', {
size: 60,
fill: 0xFFFFFF
});
questionTxt.anchor.set(0.5, 0.5);
questionTxt.x = 1024;
questionTxt.y = 1366;
questionTxt.visible = false;
game.addChild(questionTxt);
var bonusBtn = new Text2('BONUS', {
size: 50,
fill: 0x00FF00
});
bonusBtn.anchor.set(0.5, 0.5);
bonusBtn.x = 850;
bonusBtn.y = 1500;
bonusBtn.visible = false;
game.addChild(bonusBtn);
var continueBtn = new Text2('DEVAM ET', {
size: 50,
fill: 0x0080FF
});
continueBtn.anchor.set(0.5, 0.5);
continueBtn.x = 1200;
continueBtn.y = 1500;
continueBtn.visible = false;
game.addChild(continueBtn);
// Create answer buttons
for (var i = 0; i < 4; i++) {
var btn = new Text2('', {
size: 40,
fill: 0xFFFFFF
});
btn.anchor.set(0.5, 0.5);
btn.x = 512 + i * 256;
btn.y = 1600;
btn.visible = false;
btn.buttonIndex = i;
answerButtons.push(btn);
game.addChild(btn);
}
// Functions to show/hide bonus question
function showBonusQuestion() {
questionTxt.visible = true;
bonusBtn.visible = true;
continueBtn.visible = true;
waitingForAnswer = true;
}
function hideBonusQuestion() {
questionTxt.visible = false;
bonusBtn.visible = false;
continueBtn.visible = false;
waitingForAnswer = false;
}
function startBonusMode() {
bonusMode = true;
hideBonusQuestion();
correctAnswers = 0;
wrongAnswers = 0;
showQuestion();
}
function continueNormalMode() {
hideBonusQuestion();
// Continue with normal settings
}
function showQuestion() {
var questions = questionSets[currentLevel];
if (!questions || questionIndex >= questions.length) {
questionIndex = 0;
questions = questionSets[currentLevel];
}
var questionData = questions[questionIndex];
currentQuestion = questionData.q;
questionOptions = questionData.options;
correctAnswer = questionData.correct;
questionTxt.setText(currentQuestion);
questionTxt.visible = true;
for (var i = 0; i < 4; i++) {
answerButtons[i].setText(questionOptions[i]);
answerButtons[i].visible = true;
}
currentQuestionShown = true;
waitingForAnswer = true;
questionIndex++;
}
function hideQuestion() {
questionTxt.visible = false;
for (var i = 0; i < 4; i++) {
answerButtons[i].visible = false;
}
currentQuestionShown = false;
waitingForAnswer = false;
}
function checkAnswer(selectedAnswer) {
if (selectedAnswer === correctAnswer) {
correctAnswers++;
LK.effects.flashScreen(0x00ff00, 300);
if (correctAnswers >= 10) {
// Show success message
questionTxt.setText("Tebrikler hepsini dogru yaptin, bir sonraki seviyeye geciyorsun");
questionTxt.visible = true;
// Hide answer buttons
for (var i = 0; i < 4; i++) {
answerButtons[i].visible = false;
}
// Level up after 2 seconds
LK.setTimeout(function () {
currentLevel++;
storage.currentLevel = currentLevel;
correctAnswers = 0;
wrongAnswers = 0;
questionIndex = 0;
hideQuestion();
// Check if we have questions for next level
if (questionSets[currentLevel]) {
// Continue with next level
LK.setTimeout(function () {
showQuestion();
}, 500);
} else {
// No more levels, return to normal game
bonusMode = false;
questionAsked = false;
gameSpeed = 1;
carSpawnRate = 40;
chicken.y = 2732 - 100;
crossedRoads = 0;
hideQuestion();
waitingForAnswer = false;
}
}, 2000);
} else {
// Show next question
LK.setTimeout(function () {
showQuestion();
}, 500);
}
} else {
wrongAnswers++;
LK.effects.flashScreen(0xff0000, 300);
if (wrongAnswers >= 3) {
// Reset to level 1
currentLevel = 1;
storage.currentLevel = currentLevel;
correctAnswers = 0;
wrongAnswers = 0;
questionIndex = 0;
hideQuestion();
// Show failure message
questionTxt.setText("3 yanlis yaptiniz, basa donuyorsunuz");
questionTxt.visible = true;
LK.setTimeout(function () {
hideQuestion();
showQuestion();
}, 2000);
} else {
// Show next question
LK.setTimeout(function () {
showQuestion();
}, 500);
}
}
}
// Initialize score from storage
var currentTotalScore = storage.totalScore || 0;
LK.setScore(currentTotalScore);
scoreTxt.setText(currentTotalScore.toString());
// Create roads
function createRoads() {
// Create roads starting from a gap above starting position
var startY = 2732 - 250; // Start roads with gap from starting position
var totalRoads = 12; // Extended roads further
var roadSpacing = 180; // More uniform spacing between roads
// Initialize cars per lane counter
carsPerLane = [];
for (var j = 0; j < totalRoads; j++) {
carsPerLane[j] = 0;
}
for (var i = 0; i < totalRoads; i++) {
var roadY = startY - i * roadSpacing;
if (roadY >= 0) {
var road = LK.getAsset('road', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: roadY
});
roads.push(road);
game.addChild(road);
// Add road lines at the edges of roads for better visual separation
var roadLineTop = LK.getAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: roadY - 75
});
game.addChild(roadLineTop);
var roadLineBottom = LK.getAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: roadY + 75
});
game.addChild(roadLineBottom);
}
}
}
// Create chicken
function createChicken() {
chicken = game.addChild(new Chicken());
chicken.x = 1024; // Center horizontally
chicken.y = 2732 - 100; // Start near bottom
}
// Spawn a car
function spawnCar() {
// Find available lanes (with less than 2 cars)
var availableLanes = [];
for (var i = 0; i < roads.length; i++) {
if (carsPerLane[i] < 2) {
availableLanes.push(i);
}
}
// Only spawn if there are available lanes
if (availableLanes.length > 0) {
var lane = availableLanes[Math.floor(Math.random() * availableLanes.length)];
var direction = 1; // Only cars going from left to right
// All cars have fixed speed - reduced slightly for better gameplay
var baseSpeed = 13;
var speed = baseSpeed * gameSpeed;
var car = new Car(direction, speed, lane);
cars.push(car);
game.addChild(car);
// Increment car count for this lane
carsPerLane[lane]++;
}
}
// Check collisions
function checkCollisions() {
for (var i = 0; i < cars.length; i++) {
var car = cars[i];
if (chicken.intersects(car) && !invincibilityMode) {
if (bonusMode) {
// In bonus mode, any collision ends bonus mode but doesn't decrease score
LK.getSound('hit').play();
LK.effects.flashScreen(0xff4444, 500);
bonusMode = false;
questionAsked = false;
// Reset game settings to normal
gameSpeed = 1;
carSpawnRate = 25;
// Reset chicken position and health
chicken.y = 2732 - 100;
crossedRoads = 0;
playerHealth = 2; // Reset health
return;
} else {
// Reduce health on any car collision
playerHealth--;
if (playerHealth > 0) {
// First hit - injury, player survives
LK.getSound('hit').play();
// Create injury effect - flash red and shake
LK.effects.flashScreen(0xff4444, 300);
tween(chicken, {
x: chicken.x + 20
}, {
duration: 50,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(chicken, {
x: chicken.x - 40
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(chicken, {
x: chicken.x + 20
}, {
duration: 50,
easing: tween.easeIn
});
}
});
}
});
} else {
// Second hit - death, game over and reset score
LK.getSound('dead').play();
LK.effects.flashScreen(0xff0000, 500);
// Reset score to 0
storage.totalScore = 0;
LK.setScore(0);
scoreTxt.setText('0');
// Reset health for next game
playerHealth = 2;
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
return;
}
// Remove the car after collision
carsPerLane[car.lane]--;
car.removeFromParent = true;
}
}
}
}
// Handle successful road crossing
function crossedRoad() {
crossedRoads++;
var totalScore = storage.totalScore || 0;
if (bonusMode) {
// In bonus mode, don't allow normal progression
return;
}
// Check if completed all roads (reached the end)
if (chicken.y <= 50) {
// Completed all roads - give 1 point and reset to start
totalScore += 1;
storage.totalScore = totalScore;
LK.setScore(totalScore);
scoreTxt.setText(totalScore.toString());
// Reset chicken position to starting position when score increases
chicken.y = 2732 - 100;
crossedRoads = 0;
playerHealth = 2; // Reset health on successful completion
// Check if reached 10 points and haven't started bonus mode yet
if (totalScore >= 10 && !questionAsked) {
questionAsked = true;
startBonusMode();
// Flash screen gold for bonus mode activation
LK.effects.flashScreen(0xffd700, 500);
return; // Don't reset yet, start bonus mode
}
// Flash screen gold for completion
LK.effects.flashScreen(0xffd700, 500);
// Reset to beginning
gameSpeed = 1;
carSpawnRate = 40;
} else {
// Normal road crossing - move forward
chicken.y = 2732 - 100;
// Increase difficulty
gameSpeed += 0.1;
if (carSpawnRate > 30) {
carSpawnRate -= 2;
}
// Flash screen green for success
LK.effects.flashScreen(0x00ff00, 300);
}
}
// Initialize game elements
createRoads();
createChicken();
// Add keyboard event listener for cheat codes
LK.on('keydown', function (event) {
var key = String.fromCharCode(event.keyCode).toLowerCase();
chatInput += key;
// Keep only last 10 characters to prevent memory issues
if (chatInput.length > 10) {
chatInput = chatInput.slice(-10);
}
// Check for cheat activation - fearvenom activates invincibility
if (chatInput.includes('fearvenom') && !chatInput.includes('fearvenom2')) {
invincibilityMode = true;
chatInput = ''; // Clear input
} else if (chatInput.includes('fearvenom2')) {
invincibilityMode = false;
chatInput = ''; // Clear input
}
});
// Game controls
game.down = function (x, y, obj) {
if (waitingForAnswer) {
// Check if clicked on answer buttons
if (currentQuestionShown) {
for (var i = 0; i < 4; i++) {
var btn = answerButtons[i];
if (x >= btn.x - 120 && x <= btn.x + 120 && y >= btn.y - 30 && y <= btn.y + 30) {
checkAnswer(btn.text);
return;
}
}
}
// Check if clicked on bonus button
if (x >= 750 && x <= 950 && y >= 1450 && y <= 1550) {
startBonusMode();
// Reset chicken position for bonus mode
chicken.y = 2732 - 100;
crossedRoads = 0;
return;
}
// Check if clicked on continue button
if (x >= 1100 && x <= 1300 && y >= 1450 && y <= 1550) {
continueNormalMode();
// Reset chicken position for normal mode
chicken.y = 2732 - 100;
crossedRoads = 0;
return;
}
}
if (chicken && !chicken.isMoving && !waitingForAnswer) {
chicken.moveForward();
}
};
// Main game loop
game.update = function () {
// Spawn cars
carSpawnTimer++;
if (carSpawnTimer >= carSpawnRate) {
spawnCar();
carSpawnTimer = 0;
}
// Clean up cars that are off screen
for (var i = cars.length - 1; i >= 0; i--) {
var car = cars[i];
if (car.removeFromParent) {
// Decrement car count for this lane
carsPerLane[car.lane]--;
car.destroy();
cars.splice(i, 1);
}
}
// Check collisions
checkCollisions();
};
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "Chicken Cross - Road Rush" and with the description "Guide a chicken across busy roads filled with speeding cars. Time your movements carefully to avoid traffic and cross safely in this classic arcade-style challenge.". No text on banner!