/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cactus = Container.expand(function () {
var self = Container.call(this);
var cactusGraphics = self.attachAsset('cactus', {
anchorX: 0.5,
anchorY: 1
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Car = Container.expand(function (carType) {
var self = Container.call(this);
var carAssets = ['redCar', 'blueCar', 'greenCar', 'yellowCar'];
var selectedAsset = carType || carAssets[Math.floor(Math.random() * carAssets.length)];
var carGraphics = self.attachAsset(selectedAsset, {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.moveDirection = (Math.random() - 0.5) * 2;
self.update = function () {
self.y += self.speed;
self.x += self.moveDirection;
// Keep cars within screen bounds
if (self.x < 100) self.x = 100;
if (self.x > 1948) self.x = 1948;
};
return self;
});
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 1
});
var camelGraphics = self.attachAsset('camel', {
anchorX: 0.5,
anchorY: 1,
visible: false
});
var playerCarGraphics = self.attachAsset('playerCar', {
anchorX: 0.5,
anchorY: 1,
visible: false
});
self.speed = 8;
self.maxX = 2048 - 100;
self.minX = 100;
self.lastX = 0;
self.trailPositions = [];
self.currentVehicle = characterGraphics;
self.setVehicle = function (vehicleType) {
// Hide all vehicles
characterGraphics.visible = false;
camelGraphics.visible = false;
playerCarGraphics.visible = false;
// Show selected vehicle
if (vehicleType === 'camel') {
camelGraphics.visible = true;
self.currentVehicle = camelGraphics;
} else if (vehicleType === 'car') {
playerCarGraphics.visible = true;
self.currentVehicle = playerCarGraphics;
} else {
characterGraphics.visible = true;
self.currentVehicle = characterGraphics;
}
};
self.moveToX = function (targetX) {
targetX = Math.max(self.minX, Math.min(self.maxX, targetX));
tween(self, {
x: targetX
}, {
duration: 250,
easing: tween.easeOut
});
};
self.update = function () {
// Add horse galloping animation when using character (horse)
if (self.currentVehicle === characterGraphics) {
var galloping = Math.sin(LK.ticks * 0.3) * 0.15;
self.currentVehicle.rotation = galloping;
self.currentVehicle.scaleY = 1 + Math.sin(LK.ticks * 0.25) * 0.1;
// Add horse leg movement animation
var legMovement = Math.sin(LK.ticks * 0.4) * 0.08;
tween.stop(self.currentVehicle, {
scaleX: true
});
tween(self.currentVehicle, {
scaleX: 1 + legMovement
}, {
duration: 100,
easing: tween.easeInOut
});
}
// Add camel running animation when using camel
if (self.currentVehicle === camelGraphics) {
var camelBounce = Math.sin(LK.ticks * 0.35) * 0.12;
self.currentVehicle.rotation = camelBounce * 0.8;
self.currentVehicle.scaleY = 1 + Math.sin(LK.ticks * 0.3) * 0.08;
// Add camel leg movement animation
var camelLegMovement = Math.sin(LK.ticks * 0.45) * 0.06;
tween.stop(self.currentVehicle, {
scaleX: true
});
tween(self.currentVehicle, {
scaleX: 1 + camelLegMovement
}, {
duration: 120,
easing: tween.easeInOut
});
}
// Add subtle sliding animation based on movement
if (self.lastX !== undefined) {
var deltaX = self.x - self.lastX;
// Reduce rotation intensity to prevent exhausting movement
if (self.currentVehicle !== characterGraphics) {
self.currentVehicle.rotation = deltaX * 0.003;
// Reduce scale effect to make movement smoother
self.currentVehicle.scaleX = 1 + Math.abs(deltaX) * 0.0003;
// Gradually return to normal state
self.currentVehicle.rotation *= 0.9;
self.currentVehicle.scaleX = self.currentVehicle.scaleX * 0.95 + 0.05;
}
}
self.lastX = self.x;
};
return self;
});
var HorseRider = Container.expand(function () {
var self = Container.call(this);
var horseRiderGraphics = self.attachAsset('camel', {
anchorX: 0.5,
anchorY: 0.5
});
// Make sure face is oriented toward the screen
horseRiderGraphics.rotation = 0;
return self;
});
var Log = Container.expand(function () {
var self = Container.call(this);
var logGraphics = self.attachAsset('log', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
var RoadLine = Container.expand(function () {
var self = Container.call(this);
var lineGraphics = self.attachAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Rock = Container.expand(function () {
var self = Container.call(this);
var rockGraphics = self.attachAsset('rock', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
var SandParticle = Container.expand(function () {
var self = Container.call(this);
var sandGraphics = self.attachAsset('sand', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: Math.random() * 0.5 + 0.3,
scaleY: Math.random() * 0.5 + 0.3,
alpha: Math.random() * 0.5 + 0.2,
tint: 0xF4A460
});
self.speed = Math.random() * 3 + 2;
self.drift = (Math.random() - 0.5) * 2;
self.update = function () {
self.y += self.speed;
self.x += self.drift;
};
return self;
});
var Scorpion = Container.expand(function () {
var self = Container.call(this);
var scorpionGraphics = self.attachAsset('pixelScorpion', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.moveDirection = (Math.random() - 0.5) * 3;
self.update = function () {
self.y += self.speed;
self.x += self.moveDirection;
// Add scuttling animation
scorpionGraphics.rotation = Math.sin(LK.ticks * 0.2) * 0.3;
scorpionGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.3) * 0.1;
if (self.x < 100 || self.x > 1948) {
self.moveDirection *= -1;
}
};
return self;
});
var SkierFace = Container.expand(function () {
var self = Container.call(this);
var faceGraphics = self.attachAsset('skierFace', {
anchorX: 0.5,
anchorY: 0.5
});
// Make sure face is oriented toward the screen
faceGraphics.rotation = 0;
return self;
});
var Snake = Container.expand(function () {
var self = Container.call(this);
var snakeGraphics = self.attachAsset('pixelSnake', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.moveDirection = (Math.random() - 0.5) * 4;
self.update = function () {
self.y += self.speed;
self.x += self.moveDirection;
if (self.x < 100 || self.x > 1948) {
self.moveDirection *= -1;
}
};
return self;
});
var SnowFlake = Container.expand(function () {
var self = Container.call(this);
var snowGraphics = self.attachAsset('snow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: Math.random() * 0.3 + 0.2,
scaleY: Math.random() * 0.3 + 0.2,
alpha: Math.random() * 0.7 + 0.3,
tint: 0xFFFFFF
});
self.speed = Math.random() * 3 + 2;
self.drift = (Math.random() - 0.5) * 2;
self.update = function () {
self.y += self.speed;
self.x += self.drift;
// Add subtle pixel-like twinkling effect
if (Math.random() < 0.02) {
snowGraphics.alpha = Math.random() * 0.4 + 0.6;
}
};
return self;
});
var SnowFox = Container.expand(function () {
var self = Container.call(this);
var foxGraphics = self.attachAsset('snowFox', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.moveDirection = (Math.random() - 0.5) * 3;
self.update = function () {
self.y += self.speed;
self.x += self.moveDirection;
// Add fox animation - subtle bounce and sway
foxGraphics.rotation = Math.sin(LK.ticks * 0.15) * 0.2;
foxGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.25) * 0.05;
if (self.x < 100 || self.x > 1948) {
self.moveDirection *= -1;
}
};
return self;
});
var TireTrail = Container.expand(function () {
var self = Container.call(this);
var trail = LK.getAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.4,
scaleY: 0.6,
tint: 0x222222
});
self.addChild(trail);
self.speed = 8;
self.alpha = 0.8;
self.update = function () {
self.y += self.speed;
self.alpha -= 0.008;
if (self.alpha <= 0) {
self.alpha = 0;
}
};
return self;
});
var TrailDot = Container.expand(function () {
var self = Container.call(this);
var dot = LK.getAsset('snow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8,
tint: 0x888888
});
self.addChild(dot);
self.speed = 8;
self.alpha = 0.6;
self.update = function () {
self.y += self.speed;
self.alpha -= 0.02;
if (self.alpha <= 0) {
self.alpha = 0;
}
};
return self;
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFAFA
});
/****
* Game Code
****/
var player;
var obstacles = [];
var snowFlakes = [];
var trailDots = [];
var gameSpeed = 8;
var obstacleSpawnTimer = 0;
var snowSpawnTimer = 0;
var trailSpawnTimer = 0;
var difficultyTimer = 0;
var maxObstacleSpawnRate = 60;
var minObstacleSpawnRate = 30;
var currentObstacleSpawnRate = maxObstacleSpawnRate;
var currentLevel = 1;
var levelTransitioned = false;
var sandParticles = [];
var snakes = [];
var scorpions = [];
var snowFoxes = [];
var lives = 3;
var cars = [];
var roadLines = [];
var tireTrails = [];
var scoreTxt = new Text2('0/3000', {
size: 70,
fill: 0x000000,
font: "Aderos"
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
scoreTxt.x = -20;
scoreTxt.y = 20;
var livesTxt = new Text2('Can: 3', {
size: 70,
fill: 0x000000,
font: "Aderos"
});
livesTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(livesTxt);
livesTxt.x = -20;
livesTxt.y = 100;
var levelTxt = new Text2('Seviye: 1', {
size: 70,
fill: 0x000000,
font: "Aderos"
});
levelTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(levelTxt);
levelTxt.x = -20;
levelTxt.y = 180;
// Level selector buttons
var levelSelector1 = new Text2('1', {
size: 80,
fill: 0x333333,
font: "Aderos"
});
levelSelector1.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(levelSelector1);
levelSelector1.x = -200;
levelSelector1.y = -150;
levelSelector1.interactive = true;
var levelSelector2 = new Text2('2', {
size: 80,
fill: 0x333333,
font: "Aderos"
});
levelSelector2.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(levelSelector2);
levelSelector2.x = -120;
levelSelector2.y = -150;
levelSelector2.interactive = true;
var levelSelector3 = new Text2('3', {
size: 80,
fill: 0x333333,
font: "Aderos"
});
levelSelector3.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(levelSelector3);
levelSelector3.x = -40;
levelSelector3.y = -150;
levelSelector3.interactive = true;
// Initialize player
player = game.addChild(new Character());
player.x = 2048 / 2;
player.y = 2732 - 200;
// Game start state
var gameStarted = false;
// Create skier face on the left
var skierFace = game.addChild(new SkierFace());
skierFace.x = 300;
skierFace.y = 2732 - 200;
skierFace.scaleX = 2.0;
skierFace.scaleY = 2.0;
// Create subtitle text containers - first line
var subtitleText1 = new Text2('', {
size: 60,
fill: 0x000000,
font: "drifttype"
});
subtitleText1.anchor.set(0, 1);
subtitleText1.x = 550;
subtitleText1.y = 2732 - 100;
game.addChild(subtitleText1);
// Create subtitle text - second line
var subtitleText2 = new Text2('', {
size: 60,
fill: 0x000000,
font: "drifttype"
});
subtitleText2.anchor.set(0, 1);
subtitleText2.x = 550;
subtitleText2.y = 2732 - 50;
game.addChild(subtitleText2);
// Undertale-style typewriter text animation variables
var fullText1 = 'Kayakçı Çocuk: offf hava çok soğuk bu havada kızak kaymak';
var fullText2 = 'hiç akıllıca bir iş değil annem görürse canımı okur';
var currentCharIndex1 = 0;
var currentCharIndex2 = 0;
var typewriterTimer1 = null;
var typewriterTimer2 = null;
var isTypingFirstLine = false;
var isTypingSecondLine = false;
// Animate subtitle appearance with Undertale-style typewriter effect
skierFace.alpha = 0;
tween(skierFace, {
alpha: 1
}, {
duration: 1000,
easing: tween.easeIn,
onFinish: function onFinish() {
// Start typewriter effect for first line after face appears
isTypingFirstLine = true;
typewriterTimer1 = LK.setInterval(function () {
if (currentCharIndex1 < fullText1.length) {
currentCharIndex1++;
subtitleText1.setText(fullText1.substring(0, currentCharIndex1));
} else {
LK.clearInterval(typewriterTimer1);
isTypingFirstLine = false;
// Start second line after first line is complete
LK.setTimeout(function () {
isTypingSecondLine = true;
typewriterTimer2 = LK.setInterval(function () {
if (currentCharIndex2 < fullText2.length) {
currentCharIndex2++;
subtitleText2.setText(fullText2.substring(0, currentCharIndex2));
} else {
LK.clearInterval(typewriterTimer2);
isTypingSecondLine = false;
// Keep subtitle visible for 4 seconds, then fade out and start game
LK.setTimeout(function () {
tween(skierFace, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(subtitleText1, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(subtitleText2, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
skierFace.destroy();
subtitleText1.destroy();
subtitleText2.destroy();
gameStarted = true;
}
});
}, 4000);
}
}, 80); // 80ms per character for Undertale-style speed
}, 500); // 500ms delay between lines
}
}, 80); // 80ms per character for Undertale-style speed
}
});
function clearAllEnemies() {
// Clear all obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
// Clear snow flakes
for (var j = snowFlakes.length - 1; j >= 0; j--) {
snowFlakes[j].destroy();
snowFlakes.splice(j, 1);
}
// Clear sand particles
for (var k = sandParticles.length - 1; k >= 0; k--) {
sandParticles[k].destroy();
sandParticles.splice(k, 1);
}
// Clear snakes
for (var l = snakes.length - 1; l >= 0; l--) {
snakes[l].destroy();
snakes.splice(l, 1);
}
// Clear scorpions
for (var m = scorpions.length - 1; m >= 0; m--) {
scorpions[m].destroy();
scorpions.splice(m, 1);
}
// Clear snow foxes
for (var n = snowFoxes.length - 1; n >= 0; n--) {
snowFoxes[n].destroy();
snowFoxes.splice(n, 1);
}
// Clear cars
for (var o = cars.length - 1; o >= 0; o--) {
cars[o].destroy();
cars.splice(o, 1);
}
// Clear road lines
for (var p = roadLines.length - 1; p >= 0; p--) {
roadLines[p].destroy();
roadLines.splice(p, 1);
}
}
function spawnObstacle() {
var obstacle;
if (currentLevel === 1) {
var obstacleType = Math.random() < 0.6 ? 'tree' : 'log';
if (obstacleType === 'tree') {
obstacle = new Tree();
} else {
obstacle = new Log();
}
} else if (currentLevel === 2) {
var obstacleType = Math.random() < 0.7 ? 'cactus' : 'rock';
if (obstacleType === 'cactus') {
obstacle = new Cactus();
} else {
obstacle = new Rock();
}
} else {
// Level 3 - City level with different colored cars
var carTypes = ['redCar', 'blueCar', 'greenCar', 'yellowCar'];
var randomCarType = carTypes[Math.floor(Math.random() * carTypes.length)];
var car = new Car(randomCarType);
car.x = Math.random() * (2048 - 400) + 200;
car.y = -150;
car.lastY = car.y;
car.lastIntersecting = false;
cars.push(car);
game.addChild(car);
return;
}
// Ensure spacing between obstacles
var validPosition = false;
var attempts = 0;
var newX;
while (!validPosition && attempts < 20) {
newX = Math.random() * (2048 - 400) + 200;
validPosition = true;
// Check distance from existing obstacles
for (var i = 0; i < obstacles.length; i++) {
var existingObstacle = obstacles[i];
if (existingObstacle.y > -500 && existingObstacle.y < 200) {
var distance = Math.abs(newX - existingObstacle.x);
if (distance < 500) {
validPosition = false;
break;
}
}
}
attempts++;
}
obstacle.x = newX || Math.random() * (2048 - 400) + 200;
obstacle.y = -100;
obstacle.lastY = obstacle.y;
obstacle.lastIntersecting = false;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function spawnSnowFlake() {
if (currentLevel === 1) {
var snowFlake = new SnowFlake();
snowFlake.x = Math.random() * 2048;
snowFlake.y = -50;
snowFlakes.push(snowFlake);
game.addChild(snowFlake);
} else {
var sandParticle = new SandParticle();
sandParticle.x = Math.random() * 2048;
sandParticle.y = -50;
sandParticles.push(sandParticle);
game.addChild(sandParticle);
}
}
function handleMove(x, y, obj) {
if (player && gameStarted) {
player.moveToX(x);
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Check level selector clicks using game coordinates
// Level 1 selector (bottom right area)
if (x >= 1650 && x <= 1750 && y >= 2450 && y <= 2550) {
currentLevel = 1;
levelTxt.setText('Seviye: 1');
game.setBackgroundColor(0xFFFAFA);
clearAllEnemies();
player.setVehicle('character');
levelTransitioned = true;
return;
}
// Level 2 selector
if (x >= 1770 && x <= 1870 && y >= 2450 && y <= 2550) {
currentLevel = 2;
levelTxt.setText('Seviye: 2');
game.setBackgroundColor(0xD2691E);
clearAllEnemies();
player.setVehicle('camel');
levelTransitioned = true;
return;
}
// Level 3 selector
if (x >= 1890 && x <= 1990 && y >= 2450 && y <= 2550) {
currentLevel = 3;
levelTxt.setText('Seviye: 3');
game.setBackgroundColor(0x333333);
clearAllEnemies();
player.setVehicle('car');
levelTransitioned = true;
return;
}
if (player && gameStarted) {
player.moveToX(x);
}
};
game.update = function () {
// Don't run game mechanics until game has started
if (!gameStarted) {
return;
}
// Update score based on time survived
LK.setScore(Math.floor(LK.ticks / 3));
scoreTxt.setText(LK.getScore() + '/3000');
livesTxt.setText('Can: ' + lives);
// Check for winning condition at 3000 points
if (LK.getScore() >= 3000) {
// Create congratulations text
var congratsText = new Text2('TEBRIKLER OYUNU BITIRDINIZ!', {
size: 120,
fill: 0xFFD700,
font: "Aderos"
});
congratsText.anchor.set(0.5, 0.5);
congratsText.x = 2048 / 2;
congratsText.y = 2732 / 2;
game.addChild(congratsText);
// Animate the text with tween
congratsText.scaleX = 0;
congratsText.scaleY = 0;
congratsText.alpha = 0;
tween(congratsText, {
scaleX: 1.2,
scaleY: 1.2,
alpha: 1
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(congratsText, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
});
}
});
return;
}
// Auto level progression every 1000 points - only if not manually selected
if (!levelTransitioned) {
var newLevel = Math.floor(LK.getScore() / 1000) + 1;
if (newLevel > 3) newLevel = 3; // Cap at level 3
if (newLevel !== currentLevel) {
currentLevel = newLevel;
levelTxt.setText('Seviye: ' + currentLevel);
// Set background and clear enemies based on level
if (currentLevel === 2) {
// Pause game for horse rider message
gameStarted = false;
game.setBackgroundColor(0xD2691E); // Desert
// Clear snow
for (var i = snowFlakes.length - 1; i >= 0; i--) {
snowFlakes[i].destroy();
snowFlakes.splice(i, 1);
}
// Clear snow foxes
for (var sf = snowFoxes.length - 1; sf >= 0; sf--) {
snowFoxes[sf].destroy();
snowFoxes.splice(sf, 1);
}
// Clear city elements
for (var c = cars.length - 1; c >= 0; c--) {
cars[c].destroy();
cars.splice(c, 1);
}
for (var r = roadLines.length - 1; r >= 0; r--) {
roadLines[r].destroy();
roadLines.splice(r, 1);
}
// Create horse rider face
var horseRiderFace = game.addChild(new HorseRider());
horseRiderFace.x = 300;
horseRiderFace.y = 2732 - 200;
horseRiderFace.scaleX = 2.0;
horseRiderFace.scaleY = 2.0;
horseRiderFace.alpha = 0;
// Create horse rider message - first line
var horseRiderMessage1 = new Text2('', {
size: 60,
fill: 0x000000,
font: "drifttype"
});
horseRiderMessage1.anchor.set(0, 1);
horseRiderMessage1.x = 550;
horseRiderMessage1.y = 2732 - 100;
game.addChild(horseRiderMessage1);
// Create horse rider message - second line
var horseRiderMessage2 = new Text2('', {
size: 60,
fill: 0x000000,
font: "drifttype"
});
horseRiderMessage2.anchor.set(0, 1);
horseRiderMessage2.x = 550;
horseRiderMessage2.y = 2732 - 50;
game.addChild(horseRiderMessage2);
// Fade in horse rider face first
tween(horseRiderFace, {
alpha: 1
}, {
duration: 1000,
easing: tween.easeIn,
onFinish: function onFinish() {
// Check if score is 1000 or more to start horse rider animation
if (LK.getScore() >= 1000) {
// Undertale-style typewriter effect for two lines
var horseMessageText1 = 'Ata binen adam: çöl çok sıcak olmaya başladı';
var horseMessageText2 = 'bir an önce gitmem lazım';
var horseCharIndex1 = 0;
var horseCharIndex2 = 0;
var isTypingFirstLine = false;
var isTypingSecondLine = false;
var horseTypewriterTimer1 = null;
var horseTypewriterTimer2 = null;
// Start first line typewriter
isTypingFirstLine = true;
horseTypewriterTimer1 = LK.setInterval(function () {
if (horseCharIndex1 < horseMessageText1.length) {
horseCharIndex1++;
horseRiderMessage1.setText(horseMessageText1.substring(0, horseCharIndex1));
} else {
LK.clearInterval(horseTypewriterTimer1);
isTypingFirstLine = false;
// Start second line after first line is complete
LK.setTimeout(function () {
isTypingSecondLine = true;
horseTypewriterTimer2 = LK.setInterval(function () {
if (horseCharIndex2 < horseMessageText2.length) {
horseCharIndex2++;
horseRiderMessage2.setText(horseMessageText2.substring(0, horseCharIndex2));
} else {
LK.clearInterval(horseTypewriterTimer2);
isTypingSecondLine = false;
// Keep message visible for 3 seconds, then fade out and continue game
LK.setTimeout(function () {
tween(horseRiderFace, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(horseRiderMessage1, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(horseRiderMessage2, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
horseRiderFace.destroy();
horseRiderMessage1.destroy();
horseRiderMessage2.destroy();
player.setVehicle('camel');
gameStarted = true;
LK.effects.flashScreen(0xFFD700, 1500); // Golden flash
}
});
}, 3000);
}
}, 80); // 80ms per character for Undertale-style speed
}, 500); // 500ms delay between lines
}
}, 80); // 80ms per character for Undertale-style speed
} else {
// If score is less than 1000, wait for score to reach 1000
var waitForScore = LK.setInterval(function () {
if (LK.getScore() >= 1000) {
LK.clearInterval(waitForScore);
// Restart the horse rider animation
onFinish();
}
}, 100);
}
}
});
} else if (currentLevel === 3) {
// Pause game for motorcycle rider message
gameStarted = false;
game.setBackgroundColor(0x333333); // City
// Clear desert enemies
for (var s = snakes.length - 1; s >= 0; s--) {
snakes[s].destroy();
snakes.splice(s, 1);
}
for (var sc = scorpions.length - 1; sc >= 0; sc--) {
scorpions[sc].destroy();
scorpions.splice(sc, 1);
}
for (var sp = sandParticles.length - 1; sp >= 0; sp--) {
sandParticles[sp].destroy();
sandParticles.splice(sp, 1);
}
// Clear snow
for (var sf = snowFlakes.length - 1; sf >= 0; sf--) {
snowFlakes[sf].destroy();
snowFlakes.splice(sf, 1);
}
// Clear snow foxes
for (var sfx = snowFoxes.length - 1; sfx >= 0; sfx--) {
snowFoxes[sfx].destroy();
snowFoxes.splice(sfx, 1);
}
// Create motorcycle rider face (using playerCar as face placeholder)
var motorcycleRiderFace = game.addChild(new Character());
motorcycleRiderFace.x = 300;
motorcycleRiderFace.y = 2732 - 200;
motorcycleRiderFace.scaleX = 2.0;
motorcycleRiderFace.scaleY = 2.0;
motorcycleRiderFace.alpha = 0;
motorcycleRiderFace.setVehicle('car');
// Create motorcycle rider message - first line
var motorcycleMessage1 = new Text2('', {
size: 60,
fill: 0xFFFFFF,
font: "drifttype"
});
motorcycleMessage1.anchor.set(0, 1);
motorcycleMessage1.x = 550;
motorcycleMessage1.y = 2732 - 100;
game.addChild(motorcycleMessage1);
// Create motorcycle rider message - second line
var motorcycleMessage2 = new Text2('', {
size: 60,
fill: 0xFFFFFF,
font: "drifttype"
});
motorcycleMessage2.anchor.set(0, 1);
motorcycleMessage2.x = 550;
motorcycleMessage2.y = 2732 - 50;
game.addChild(motorcycleMessage2);
// Fade in motorcycle rider face first
tween(motorcycleRiderFace, {
alpha: 1
}, {
duration: 1000,
easing: tween.easeIn,
onFinish: function onFinish() {
// Check if score is 2000 or more to start motorcycle rider animation
if (LK.getScore() >= 2000) {
// Undertale-style typewriter effect for two lines
var motorcycleMessageText1 = 'çok trafik var iş yerine nasıl yetişicem';
var motorcycleMessageText2 = 'en iyisi hızımı artırmak';
var motorcycleCharIndex1 = 0;
var motorcycleCharIndex2 = 0;
var isTypingFirstLine = false;
var isTypingSecondLine = false;
var motorcycleTypewriterTimer1 = null;
var motorcycleTypewriterTimer2 = null;
// Start first line typewriter
isTypingFirstLine = true;
motorcycleTypewriterTimer1 = LK.setInterval(function () {
if (motorcycleCharIndex1 < motorcycleMessageText1.length) {
motorcycleCharIndex1++;
motorcycleMessage1.setText(motorcycleMessageText1.substring(0, motorcycleCharIndex1));
} else {
LK.clearInterval(motorcycleTypewriterTimer1);
isTypingFirstLine = false;
// Start second line after first line is complete
LK.setTimeout(function () {
isTypingSecondLine = true;
motorcycleTypewriterTimer2 = LK.setInterval(function () {
if (motorcycleCharIndex2 < motorcycleMessageText2.length) {
motorcycleCharIndex2++;
motorcycleMessage2.setText(motorcycleMessageText2.substring(0, motorcycleCharIndex2));
} else {
LK.clearInterval(motorcycleTypewriterTimer2);
isTypingSecondLine = false;
// Keep message visible for 3 seconds, then fade out and continue game
LK.setTimeout(function () {
tween(motorcycleRiderFace, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(motorcycleMessage1, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(motorcycleMessage2, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
motorcycleRiderFace.destroy();
motorcycleMessage1.destroy();
motorcycleMessage2.destroy();
player.setVehicle('car');
gameStarted = true;
LK.effects.flashScreen(0x0066FF, 1500); // Blue flash
}
});
}, 3000);
}
}, 80); // 80ms per character for Undertale-style speed
}, 500); // 500ms delay between lines
}
}, 80); // 80ms per character for Undertale-style speed
} else {
// If score is less than 2000, wait for score to reach 2000
var waitForScore = LK.setInterval(function () {
if (LK.getScore() >= 2000) {
LK.clearInterval(waitForScore);
// Restart the motorcycle rider animation
onFinish();
}
}, 100);
}
}
});
}
}
}
// Increase difficulty over time
difficultyTimer++;
if (difficultyTimer % 300 === 0) {
gameSpeed = Math.min(gameSpeed + 0.5, 15);
currentObstacleSpawnRate = Math.max(currentObstacleSpawnRate - 2, minObstacleSpawnRate);
}
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= currentObstacleSpawnRate) {
spawnObstacle();
obstacleSpawnTimer = 0;
}
// Spawn snow
snowSpawnTimer++;
if (snowSpawnTimer >= 15) {
spawnSnowFlake();
snowSpawnTimer = 0;
}
// Spawn snow foxes in snow level
if (currentLevel === 1 && LK.ticks % 200 === 0) {
var snowFox = new SnowFox();
snowFox.x = Math.random() * (2048 - 200) + 100;
snowFox.y = -100;
snowFoxes.push(snowFox);
game.addChild(snowFox);
}
// Spawn snakes and scorpions in desert level
if (currentLevel === 2 && LK.ticks % 180 === 0) {
var enemyType = Math.random() < 0.5 ? 'snake' : 'scorpion';
if (enemyType === 'snake') {
var snake = new Snake();
snake.x = Math.random() * (2048 - 200) + 100;
snake.y = -100;
snakes.push(snake);
game.addChild(snake);
} else {
var scorpion = new Scorpion();
scorpion.x = Math.random() * (2048 - 200) + 100;
scorpion.y = -100;
scorpions.push(scorpion);
game.addChild(scorpion);
}
}
// Spawn city elements in level 3
if (currentLevel === 3) {
// Spawn road lines
if (LK.ticks % 20 === 0) {
var roadLine = new RoadLine();
roadLine.x = 2048 / 2;
roadLine.y = -50;
roadLines.push(roadLine);
game.addChild(roadLine);
}
}
// Spawn trail dots or tire trails based on vehicle
trailSpawnTimer++;
if (trailSpawnTimer >= 8) {
if (currentLevel === 3) {
// Create tire trails for car in city level
var leftTireTrail = new TireTrail();
leftTireTrail.x = player.x - 25;
leftTireTrail.y = player.y + 30;
tireTrails.push(leftTireTrail);
game.addChild(leftTireTrail);
var rightTireTrail = new TireTrail();
rightTireTrail.x = player.x + 25;
rightTireTrail.y = player.y + 30;
tireTrails.push(rightTireTrail);
game.addChild(rightTireTrail);
} else {
// Create regular trail dots for other vehicles
var leftTrail = new TrailDot();
leftTrail.x = player.x - 30;
leftTrail.y = player.y + 20;
trailDots.push(leftTrail);
game.addChild(leftTrail);
var rightTrail = new TrailDot();
rightTrail.x = player.x + 30;
rightTrail.y = player.y + 20;
trailDots.push(rightTrail);
game.addChild(rightTrail);
}
trailSpawnTimer = 0;
}
// Update and check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
// Update speed based on game speed
obstacle.speed = gameSpeed;
// Check if obstacle went off screen
if (obstacle.lastY <= 2800 && obstacle.y > 2800) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with player
var currentIntersecting = obstacle.intersects(player);
if (!obstacle.lastIntersecting && currentIntersecting) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xFF0000, 1000);
lives--;
livesTxt.setText('Can: ' + lives);
if (lives <= 0) {
LK.showGameOver();
return;
} else {
// Flash player to show damage
tween(player, {
alpha: 0.3
}, {
duration: 200,
onFinish: function onFinish() {
tween(player, {
alpha: 1
}, {
duration: 200
});
}
});
}
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
obstacle.lastY = obstacle.y;
obstacle.lastIntersecting = currentIntersecting;
}
// Update and clean up snow flakes
for (var j = snowFlakes.length - 1; j >= 0; j--) {
var snowFlake = snowFlakes[j];
snowFlake.speed = gameSpeed * 0.7;
if (snowFlake.y > 2800 || snowFlake.x < -100 || snowFlake.x > 2148) {
snowFlake.destroy();
snowFlakes.splice(j, 1);
}
}
// Update and clean up sand particles
for (var l = sandParticles.length - 1; l >= 0; l--) {
var sandParticle = sandParticles[l];
sandParticle.speed = gameSpeed * 0.7;
if (sandParticle.y > 2800 || sandParticle.x < -100 || sandParticle.x > 2148) {
sandParticle.destroy();
sandParticles.splice(l, 1);
}
}
// Update and clean up trail dots
for (var k = trailDots.length - 1; k >= 0; k--) {
var trailDot = trailDots[k];
trailDot.speed = gameSpeed;
if (trailDot.y > 2800 || trailDot.alpha <= 0) {
trailDot.destroy();
trailDots.splice(k, 1);
}
}
// Update and clean up tire trails
for (var t = tireTrails.length - 1; t >= 0; t--) {
var tireTrail = tireTrails[t];
tireTrail.speed = gameSpeed;
if (tireTrail.y > 2800 || tireTrail.alpha <= 0) {
tireTrail.destroy();
tireTrails.splice(t, 1);
}
}
// Update and clean up snakes (with collision damage)
for (var m = snakes.length - 1; m >= 0; m--) {
var snake = snakes[m];
snake.speed = gameSpeed * 0.8;
// Initialize collision tracking
if (snake.lastIntersecting === undefined) snake.lastIntersecting = false;
// Check collision with player
var currentIntersecting = snake.intersects(player);
if (!snake.lastIntersecting && currentIntersecting) {
// Make snake fly up and rotate
tween(snake, {
y: snake.y - 200,
rotation: Math.PI * 1.5,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 600,
easing: tween.easeOut
});
snake.destroy();
snakes.splice(m, 1);
continue;
}
snake.lastIntersecting = currentIntersecting;
if (snake.y > 2800 || snake.x < -100 || snake.x > 2148) {
snake.destroy();
snakes.splice(m, 1);
}
}
// Update and clean up scorpions (with collision damage)
for (var n = scorpions.length - 1; n >= 0; n--) {
var scorpion = scorpions[n];
scorpion.speed = gameSpeed * 0.8;
// Initialize collision tracking
if (scorpion.lastIntersecting === undefined) scorpion.lastIntersecting = false;
// Check collision with player
var currentIntersecting = scorpion.intersects(player);
if (!scorpion.lastIntersecting && currentIntersecting) {
// Make scorpion fly up and rotate
tween(scorpion, {
y: scorpion.y - 180,
rotation: -Math.PI * 1.2,
scaleX: 0.6,
scaleY: 0.6
}, {
duration: 500,
easing: tween.easeOut
});
scorpion.destroy();
scorpions.splice(n, 1);
continue;
}
scorpion.lastIntersecting = currentIntersecting;
if (scorpion.y > 2800 || scorpion.x < -100 || scorpion.x > 2148) {
scorpion.destroy();
scorpions.splice(n, 1);
}
}
// Update and clean up cars
for (var p = cars.length - 1; p >= 0; p--) {
var car = cars[p];
car.speed = gameSpeed;
// Initialize collision tracking
if (car.lastIntersecting === undefined) car.lastIntersecting = false;
// Initialize road line intersection tracking
if (car.lastRoadLineIntersecting === undefined) car.lastRoadLineIntersecting = false;
// Check if car is intersecting with any road line and hide the road line instead
for (var rl = 0; rl < roadLines.length; rl++) {
if (car.intersects(roadLines[rl])) {
roadLines[rl].visible = false;
} else {
roadLines[rl].visible = true;
}
}
// Check collision with player
var currentIntersecting = car.intersects(player);
if (!car.lastIntersecting && currentIntersecting) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xFF0000, 1000);
lives--;
livesTxt.setText('Can: ' + lives);
if (lives <= 0) {
LK.showGameOver();
return;
} else {
tween(player, {
alpha: 0.3
}, {
duration: 200,
onFinish: function onFinish() {
tween(player, {
alpha: 1
}, {
duration: 200
});
}
});
}
car.destroy();
cars.splice(p, 1);
continue;
}
car.lastIntersecting = currentIntersecting;
if (car.y > 2800) {
car.destroy();
cars.splice(p, 1);
}
}
// Update and clean up snow foxes (with collision animation)
for (var sf = snowFoxes.length - 1; sf >= 0; sf--) {
var snowFox = snowFoxes[sf];
snowFox.speed = gameSpeed * 0.8;
// Initialize collision tracking
if (snowFox.lastIntersecting === undefined) snowFox.lastIntersecting = false;
// Check collision with player
var currentIntersecting = snowFox.intersects(player);
if (!snowFox.lastIntersecting && currentIntersecting) {
// Make snow fox fly up and rotate gracefully
tween(snowFox, {
y: snowFox.y - 220,
rotation: Math.PI * 1.8,
scaleX: 0.4,
scaleY: 0.4
}, {
duration: 700,
easing: tween.easeOut
});
snowFox.destroy();
snowFoxes.splice(sf, 1);
continue;
}
snowFox.lastIntersecting = currentIntersecting;
if (snowFox.y > 2800 || snowFox.x < -100 || snowFox.x > 2148) {
snowFox.destroy();
snowFoxes.splice(sf, 1);
}
}
// Update and clean up road lines
for (var s = roadLines.length - 1; s >= 0; s--) {
var roadLine = roadLines[s];
roadLine.speed = gameSpeed;
if (roadLine.y > 2800) {
roadLine.destroy();
roadLines.splice(s, 1);
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cactus = Container.expand(function () {
var self = Container.call(this);
var cactusGraphics = self.attachAsset('cactus', {
anchorX: 0.5,
anchorY: 1
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Car = Container.expand(function (carType) {
var self = Container.call(this);
var carAssets = ['redCar', 'blueCar', 'greenCar', 'yellowCar'];
var selectedAsset = carType || carAssets[Math.floor(Math.random() * carAssets.length)];
var carGraphics = self.attachAsset(selectedAsset, {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.moveDirection = (Math.random() - 0.5) * 2;
self.update = function () {
self.y += self.speed;
self.x += self.moveDirection;
// Keep cars within screen bounds
if (self.x < 100) self.x = 100;
if (self.x > 1948) self.x = 1948;
};
return self;
});
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 1
});
var camelGraphics = self.attachAsset('camel', {
anchorX: 0.5,
anchorY: 1,
visible: false
});
var playerCarGraphics = self.attachAsset('playerCar', {
anchorX: 0.5,
anchorY: 1,
visible: false
});
self.speed = 8;
self.maxX = 2048 - 100;
self.minX = 100;
self.lastX = 0;
self.trailPositions = [];
self.currentVehicle = characterGraphics;
self.setVehicle = function (vehicleType) {
// Hide all vehicles
characterGraphics.visible = false;
camelGraphics.visible = false;
playerCarGraphics.visible = false;
// Show selected vehicle
if (vehicleType === 'camel') {
camelGraphics.visible = true;
self.currentVehicle = camelGraphics;
} else if (vehicleType === 'car') {
playerCarGraphics.visible = true;
self.currentVehicle = playerCarGraphics;
} else {
characterGraphics.visible = true;
self.currentVehicle = characterGraphics;
}
};
self.moveToX = function (targetX) {
targetX = Math.max(self.minX, Math.min(self.maxX, targetX));
tween(self, {
x: targetX
}, {
duration: 250,
easing: tween.easeOut
});
};
self.update = function () {
// Add horse galloping animation when using character (horse)
if (self.currentVehicle === characterGraphics) {
var galloping = Math.sin(LK.ticks * 0.3) * 0.15;
self.currentVehicle.rotation = galloping;
self.currentVehicle.scaleY = 1 + Math.sin(LK.ticks * 0.25) * 0.1;
// Add horse leg movement animation
var legMovement = Math.sin(LK.ticks * 0.4) * 0.08;
tween.stop(self.currentVehicle, {
scaleX: true
});
tween(self.currentVehicle, {
scaleX: 1 + legMovement
}, {
duration: 100,
easing: tween.easeInOut
});
}
// Add camel running animation when using camel
if (self.currentVehicle === camelGraphics) {
var camelBounce = Math.sin(LK.ticks * 0.35) * 0.12;
self.currentVehicle.rotation = camelBounce * 0.8;
self.currentVehicle.scaleY = 1 + Math.sin(LK.ticks * 0.3) * 0.08;
// Add camel leg movement animation
var camelLegMovement = Math.sin(LK.ticks * 0.45) * 0.06;
tween.stop(self.currentVehicle, {
scaleX: true
});
tween(self.currentVehicle, {
scaleX: 1 + camelLegMovement
}, {
duration: 120,
easing: tween.easeInOut
});
}
// Add subtle sliding animation based on movement
if (self.lastX !== undefined) {
var deltaX = self.x - self.lastX;
// Reduce rotation intensity to prevent exhausting movement
if (self.currentVehicle !== characterGraphics) {
self.currentVehicle.rotation = deltaX * 0.003;
// Reduce scale effect to make movement smoother
self.currentVehicle.scaleX = 1 + Math.abs(deltaX) * 0.0003;
// Gradually return to normal state
self.currentVehicle.rotation *= 0.9;
self.currentVehicle.scaleX = self.currentVehicle.scaleX * 0.95 + 0.05;
}
}
self.lastX = self.x;
};
return self;
});
var HorseRider = Container.expand(function () {
var self = Container.call(this);
var horseRiderGraphics = self.attachAsset('camel', {
anchorX: 0.5,
anchorY: 0.5
});
// Make sure face is oriented toward the screen
horseRiderGraphics.rotation = 0;
return self;
});
var Log = Container.expand(function () {
var self = Container.call(this);
var logGraphics = self.attachAsset('log', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
var RoadLine = Container.expand(function () {
var self = Container.call(this);
var lineGraphics = self.attachAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Rock = Container.expand(function () {
var self = Container.call(this);
var rockGraphics = self.attachAsset('rock', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
var SandParticle = Container.expand(function () {
var self = Container.call(this);
var sandGraphics = self.attachAsset('sand', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: Math.random() * 0.5 + 0.3,
scaleY: Math.random() * 0.5 + 0.3,
alpha: Math.random() * 0.5 + 0.2,
tint: 0xF4A460
});
self.speed = Math.random() * 3 + 2;
self.drift = (Math.random() - 0.5) * 2;
self.update = function () {
self.y += self.speed;
self.x += self.drift;
};
return self;
});
var Scorpion = Container.expand(function () {
var self = Container.call(this);
var scorpionGraphics = self.attachAsset('pixelScorpion', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.moveDirection = (Math.random() - 0.5) * 3;
self.update = function () {
self.y += self.speed;
self.x += self.moveDirection;
// Add scuttling animation
scorpionGraphics.rotation = Math.sin(LK.ticks * 0.2) * 0.3;
scorpionGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.3) * 0.1;
if (self.x < 100 || self.x > 1948) {
self.moveDirection *= -1;
}
};
return self;
});
var SkierFace = Container.expand(function () {
var self = Container.call(this);
var faceGraphics = self.attachAsset('skierFace', {
anchorX: 0.5,
anchorY: 0.5
});
// Make sure face is oriented toward the screen
faceGraphics.rotation = 0;
return self;
});
var Snake = Container.expand(function () {
var self = Container.call(this);
var snakeGraphics = self.attachAsset('pixelSnake', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.moveDirection = (Math.random() - 0.5) * 4;
self.update = function () {
self.y += self.speed;
self.x += self.moveDirection;
if (self.x < 100 || self.x > 1948) {
self.moveDirection *= -1;
}
};
return self;
});
var SnowFlake = Container.expand(function () {
var self = Container.call(this);
var snowGraphics = self.attachAsset('snow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: Math.random() * 0.3 + 0.2,
scaleY: Math.random() * 0.3 + 0.2,
alpha: Math.random() * 0.7 + 0.3,
tint: 0xFFFFFF
});
self.speed = Math.random() * 3 + 2;
self.drift = (Math.random() - 0.5) * 2;
self.update = function () {
self.y += self.speed;
self.x += self.drift;
// Add subtle pixel-like twinkling effect
if (Math.random() < 0.02) {
snowGraphics.alpha = Math.random() * 0.4 + 0.6;
}
};
return self;
});
var SnowFox = Container.expand(function () {
var self = Container.call(this);
var foxGraphics = self.attachAsset('snowFox', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.moveDirection = (Math.random() - 0.5) * 3;
self.update = function () {
self.y += self.speed;
self.x += self.moveDirection;
// Add fox animation - subtle bounce and sway
foxGraphics.rotation = Math.sin(LK.ticks * 0.15) * 0.2;
foxGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.25) * 0.05;
if (self.x < 100 || self.x > 1948) {
self.moveDirection *= -1;
}
};
return self;
});
var TireTrail = Container.expand(function () {
var self = Container.call(this);
var trail = LK.getAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.4,
scaleY: 0.6,
tint: 0x222222
});
self.addChild(trail);
self.speed = 8;
self.alpha = 0.8;
self.update = function () {
self.y += self.speed;
self.alpha -= 0.008;
if (self.alpha <= 0) {
self.alpha = 0;
}
};
return self;
});
var TrailDot = Container.expand(function () {
var self = Container.call(this);
var dot = LK.getAsset('snow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8,
tint: 0x888888
});
self.addChild(dot);
self.speed = 8;
self.alpha = 0.6;
self.update = function () {
self.y += self.speed;
self.alpha -= 0.02;
if (self.alpha <= 0) {
self.alpha = 0;
}
};
return self;
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFAFA
});
/****
* Game Code
****/
var player;
var obstacles = [];
var snowFlakes = [];
var trailDots = [];
var gameSpeed = 8;
var obstacleSpawnTimer = 0;
var snowSpawnTimer = 0;
var trailSpawnTimer = 0;
var difficultyTimer = 0;
var maxObstacleSpawnRate = 60;
var minObstacleSpawnRate = 30;
var currentObstacleSpawnRate = maxObstacleSpawnRate;
var currentLevel = 1;
var levelTransitioned = false;
var sandParticles = [];
var snakes = [];
var scorpions = [];
var snowFoxes = [];
var lives = 3;
var cars = [];
var roadLines = [];
var tireTrails = [];
var scoreTxt = new Text2('0/3000', {
size: 70,
fill: 0x000000,
font: "Aderos"
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
scoreTxt.x = -20;
scoreTxt.y = 20;
var livesTxt = new Text2('Can: 3', {
size: 70,
fill: 0x000000,
font: "Aderos"
});
livesTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(livesTxt);
livesTxt.x = -20;
livesTxt.y = 100;
var levelTxt = new Text2('Seviye: 1', {
size: 70,
fill: 0x000000,
font: "Aderos"
});
levelTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(levelTxt);
levelTxt.x = -20;
levelTxt.y = 180;
// Level selector buttons
var levelSelector1 = new Text2('1', {
size: 80,
fill: 0x333333,
font: "Aderos"
});
levelSelector1.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(levelSelector1);
levelSelector1.x = -200;
levelSelector1.y = -150;
levelSelector1.interactive = true;
var levelSelector2 = new Text2('2', {
size: 80,
fill: 0x333333,
font: "Aderos"
});
levelSelector2.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(levelSelector2);
levelSelector2.x = -120;
levelSelector2.y = -150;
levelSelector2.interactive = true;
var levelSelector3 = new Text2('3', {
size: 80,
fill: 0x333333,
font: "Aderos"
});
levelSelector3.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(levelSelector3);
levelSelector3.x = -40;
levelSelector3.y = -150;
levelSelector3.interactive = true;
// Initialize player
player = game.addChild(new Character());
player.x = 2048 / 2;
player.y = 2732 - 200;
// Game start state
var gameStarted = false;
// Create skier face on the left
var skierFace = game.addChild(new SkierFace());
skierFace.x = 300;
skierFace.y = 2732 - 200;
skierFace.scaleX = 2.0;
skierFace.scaleY = 2.0;
// Create subtitle text containers - first line
var subtitleText1 = new Text2('', {
size: 60,
fill: 0x000000,
font: "drifttype"
});
subtitleText1.anchor.set(0, 1);
subtitleText1.x = 550;
subtitleText1.y = 2732 - 100;
game.addChild(subtitleText1);
// Create subtitle text - second line
var subtitleText2 = new Text2('', {
size: 60,
fill: 0x000000,
font: "drifttype"
});
subtitleText2.anchor.set(0, 1);
subtitleText2.x = 550;
subtitleText2.y = 2732 - 50;
game.addChild(subtitleText2);
// Undertale-style typewriter text animation variables
var fullText1 = 'Kayakçı Çocuk: offf hava çok soğuk bu havada kızak kaymak';
var fullText2 = 'hiç akıllıca bir iş değil annem görürse canımı okur';
var currentCharIndex1 = 0;
var currentCharIndex2 = 0;
var typewriterTimer1 = null;
var typewriterTimer2 = null;
var isTypingFirstLine = false;
var isTypingSecondLine = false;
// Animate subtitle appearance with Undertale-style typewriter effect
skierFace.alpha = 0;
tween(skierFace, {
alpha: 1
}, {
duration: 1000,
easing: tween.easeIn,
onFinish: function onFinish() {
// Start typewriter effect for first line after face appears
isTypingFirstLine = true;
typewriterTimer1 = LK.setInterval(function () {
if (currentCharIndex1 < fullText1.length) {
currentCharIndex1++;
subtitleText1.setText(fullText1.substring(0, currentCharIndex1));
} else {
LK.clearInterval(typewriterTimer1);
isTypingFirstLine = false;
// Start second line after first line is complete
LK.setTimeout(function () {
isTypingSecondLine = true;
typewriterTimer2 = LK.setInterval(function () {
if (currentCharIndex2 < fullText2.length) {
currentCharIndex2++;
subtitleText2.setText(fullText2.substring(0, currentCharIndex2));
} else {
LK.clearInterval(typewriterTimer2);
isTypingSecondLine = false;
// Keep subtitle visible for 4 seconds, then fade out and start game
LK.setTimeout(function () {
tween(skierFace, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(subtitleText1, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(subtitleText2, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
skierFace.destroy();
subtitleText1.destroy();
subtitleText2.destroy();
gameStarted = true;
}
});
}, 4000);
}
}, 80); // 80ms per character for Undertale-style speed
}, 500); // 500ms delay between lines
}
}, 80); // 80ms per character for Undertale-style speed
}
});
function clearAllEnemies() {
// Clear all obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
// Clear snow flakes
for (var j = snowFlakes.length - 1; j >= 0; j--) {
snowFlakes[j].destroy();
snowFlakes.splice(j, 1);
}
// Clear sand particles
for (var k = sandParticles.length - 1; k >= 0; k--) {
sandParticles[k].destroy();
sandParticles.splice(k, 1);
}
// Clear snakes
for (var l = snakes.length - 1; l >= 0; l--) {
snakes[l].destroy();
snakes.splice(l, 1);
}
// Clear scorpions
for (var m = scorpions.length - 1; m >= 0; m--) {
scorpions[m].destroy();
scorpions.splice(m, 1);
}
// Clear snow foxes
for (var n = snowFoxes.length - 1; n >= 0; n--) {
snowFoxes[n].destroy();
snowFoxes.splice(n, 1);
}
// Clear cars
for (var o = cars.length - 1; o >= 0; o--) {
cars[o].destroy();
cars.splice(o, 1);
}
// Clear road lines
for (var p = roadLines.length - 1; p >= 0; p--) {
roadLines[p].destroy();
roadLines.splice(p, 1);
}
}
function spawnObstacle() {
var obstacle;
if (currentLevel === 1) {
var obstacleType = Math.random() < 0.6 ? 'tree' : 'log';
if (obstacleType === 'tree') {
obstacle = new Tree();
} else {
obstacle = new Log();
}
} else if (currentLevel === 2) {
var obstacleType = Math.random() < 0.7 ? 'cactus' : 'rock';
if (obstacleType === 'cactus') {
obstacle = new Cactus();
} else {
obstacle = new Rock();
}
} else {
// Level 3 - City level with different colored cars
var carTypes = ['redCar', 'blueCar', 'greenCar', 'yellowCar'];
var randomCarType = carTypes[Math.floor(Math.random() * carTypes.length)];
var car = new Car(randomCarType);
car.x = Math.random() * (2048 - 400) + 200;
car.y = -150;
car.lastY = car.y;
car.lastIntersecting = false;
cars.push(car);
game.addChild(car);
return;
}
// Ensure spacing between obstacles
var validPosition = false;
var attempts = 0;
var newX;
while (!validPosition && attempts < 20) {
newX = Math.random() * (2048 - 400) + 200;
validPosition = true;
// Check distance from existing obstacles
for (var i = 0; i < obstacles.length; i++) {
var existingObstacle = obstacles[i];
if (existingObstacle.y > -500 && existingObstacle.y < 200) {
var distance = Math.abs(newX - existingObstacle.x);
if (distance < 500) {
validPosition = false;
break;
}
}
}
attempts++;
}
obstacle.x = newX || Math.random() * (2048 - 400) + 200;
obstacle.y = -100;
obstacle.lastY = obstacle.y;
obstacle.lastIntersecting = false;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function spawnSnowFlake() {
if (currentLevel === 1) {
var snowFlake = new SnowFlake();
snowFlake.x = Math.random() * 2048;
snowFlake.y = -50;
snowFlakes.push(snowFlake);
game.addChild(snowFlake);
} else {
var sandParticle = new SandParticle();
sandParticle.x = Math.random() * 2048;
sandParticle.y = -50;
sandParticles.push(sandParticle);
game.addChild(sandParticle);
}
}
function handleMove(x, y, obj) {
if (player && gameStarted) {
player.moveToX(x);
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Check level selector clicks using game coordinates
// Level 1 selector (bottom right area)
if (x >= 1650 && x <= 1750 && y >= 2450 && y <= 2550) {
currentLevel = 1;
levelTxt.setText('Seviye: 1');
game.setBackgroundColor(0xFFFAFA);
clearAllEnemies();
player.setVehicle('character');
levelTransitioned = true;
return;
}
// Level 2 selector
if (x >= 1770 && x <= 1870 && y >= 2450 && y <= 2550) {
currentLevel = 2;
levelTxt.setText('Seviye: 2');
game.setBackgroundColor(0xD2691E);
clearAllEnemies();
player.setVehicle('camel');
levelTransitioned = true;
return;
}
// Level 3 selector
if (x >= 1890 && x <= 1990 && y >= 2450 && y <= 2550) {
currentLevel = 3;
levelTxt.setText('Seviye: 3');
game.setBackgroundColor(0x333333);
clearAllEnemies();
player.setVehicle('car');
levelTransitioned = true;
return;
}
if (player && gameStarted) {
player.moveToX(x);
}
};
game.update = function () {
// Don't run game mechanics until game has started
if (!gameStarted) {
return;
}
// Update score based on time survived
LK.setScore(Math.floor(LK.ticks / 3));
scoreTxt.setText(LK.getScore() + '/3000');
livesTxt.setText('Can: ' + lives);
// Check for winning condition at 3000 points
if (LK.getScore() >= 3000) {
// Create congratulations text
var congratsText = new Text2('TEBRIKLER OYUNU BITIRDINIZ!', {
size: 120,
fill: 0xFFD700,
font: "Aderos"
});
congratsText.anchor.set(0.5, 0.5);
congratsText.x = 2048 / 2;
congratsText.y = 2732 / 2;
game.addChild(congratsText);
// Animate the text with tween
congratsText.scaleX = 0;
congratsText.scaleY = 0;
congratsText.alpha = 0;
tween(congratsText, {
scaleX: 1.2,
scaleY: 1.2,
alpha: 1
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(congratsText, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
});
}
});
return;
}
// Auto level progression every 1000 points - only if not manually selected
if (!levelTransitioned) {
var newLevel = Math.floor(LK.getScore() / 1000) + 1;
if (newLevel > 3) newLevel = 3; // Cap at level 3
if (newLevel !== currentLevel) {
currentLevel = newLevel;
levelTxt.setText('Seviye: ' + currentLevel);
// Set background and clear enemies based on level
if (currentLevel === 2) {
// Pause game for horse rider message
gameStarted = false;
game.setBackgroundColor(0xD2691E); // Desert
// Clear snow
for (var i = snowFlakes.length - 1; i >= 0; i--) {
snowFlakes[i].destroy();
snowFlakes.splice(i, 1);
}
// Clear snow foxes
for (var sf = snowFoxes.length - 1; sf >= 0; sf--) {
snowFoxes[sf].destroy();
snowFoxes.splice(sf, 1);
}
// Clear city elements
for (var c = cars.length - 1; c >= 0; c--) {
cars[c].destroy();
cars.splice(c, 1);
}
for (var r = roadLines.length - 1; r >= 0; r--) {
roadLines[r].destroy();
roadLines.splice(r, 1);
}
// Create horse rider face
var horseRiderFace = game.addChild(new HorseRider());
horseRiderFace.x = 300;
horseRiderFace.y = 2732 - 200;
horseRiderFace.scaleX = 2.0;
horseRiderFace.scaleY = 2.0;
horseRiderFace.alpha = 0;
// Create horse rider message - first line
var horseRiderMessage1 = new Text2('', {
size: 60,
fill: 0x000000,
font: "drifttype"
});
horseRiderMessage1.anchor.set(0, 1);
horseRiderMessage1.x = 550;
horseRiderMessage1.y = 2732 - 100;
game.addChild(horseRiderMessage1);
// Create horse rider message - second line
var horseRiderMessage2 = new Text2('', {
size: 60,
fill: 0x000000,
font: "drifttype"
});
horseRiderMessage2.anchor.set(0, 1);
horseRiderMessage2.x = 550;
horseRiderMessage2.y = 2732 - 50;
game.addChild(horseRiderMessage2);
// Fade in horse rider face first
tween(horseRiderFace, {
alpha: 1
}, {
duration: 1000,
easing: tween.easeIn,
onFinish: function onFinish() {
// Check if score is 1000 or more to start horse rider animation
if (LK.getScore() >= 1000) {
// Undertale-style typewriter effect for two lines
var horseMessageText1 = 'Ata binen adam: çöl çok sıcak olmaya başladı';
var horseMessageText2 = 'bir an önce gitmem lazım';
var horseCharIndex1 = 0;
var horseCharIndex2 = 0;
var isTypingFirstLine = false;
var isTypingSecondLine = false;
var horseTypewriterTimer1 = null;
var horseTypewriterTimer2 = null;
// Start first line typewriter
isTypingFirstLine = true;
horseTypewriterTimer1 = LK.setInterval(function () {
if (horseCharIndex1 < horseMessageText1.length) {
horseCharIndex1++;
horseRiderMessage1.setText(horseMessageText1.substring(0, horseCharIndex1));
} else {
LK.clearInterval(horseTypewriterTimer1);
isTypingFirstLine = false;
// Start second line after first line is complete
LK.setTimeout(function () {
isTypingSecondLine = true;
horseTypewriterTimer2 = LK.setInterval(function () {
if (horseCharIndex2 < horseMessageText2.length) {
horseCharIndex2++;
horseRiderMessage2.setText(horseMessageText2.substring(0, horseCharIndex2));
} else {
LK.clearInterval(horseTypewriterTimer2);
isTypingSecondLine = false;
// Keep message visible for 3 seconds, then fade out and continue game
LK.setTimeout(function () {
tween(horseRiderFace, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(horseRiderMessage1, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(horseRiderMessage2, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
horseRiderFace.destroy();
horseRiderMessage1.destroy();
horseRiderMessage2.destroy();
player.setVehicle('camel');
gameStarted = true;
LK.effects.flashScreen(0xFFD700, 1500); // Golden flash
}
});
}, 3000);
}
}, 80); // 80ms per character for Undertale-style speed
}, 500); // 500ms delay between lines
}
}, 80); // 80ms per character for Undertale-style speed
} else {
// If score is less than 1000, wait for score to reach 1000
var waitForScore = LK.setInterval(function () {
if (LK.getScore() >= 1000) {
LK.clearInterval(waitForScore);
// Restart the horse rider animation
onFinish();
}
}, 100);
}
}
});
} else if (currentLevel === 3) {
// Pause game for motorcycle rider message
gameStarted = false;
game.setBackgroundColor(0x333333); // City
// Clear desert enemies
for (var s = snakes.length - 1; s >= 0; s--) {
snakes[s].destroy();
snakes.splice(s, 1);
}
for (var sc = scorpions.length - 1; sc >= 0; sc--) {
scorpions[sc].destroy();
scorpions.splice(sc, 1);
}
for (var sp = sandParticles.length - 1; sp >= 0; sp--) {
sandParticles[sp].destroy();
sandParticles.splice(sp, 1);
}
// Clear snow
for (var sf = snowFlakes.length - 1; sf >= 0; sf--) {
snowFlakes[sf].destroy();
snowFlakes.splice(sf, 1);
}
// Clear snow foxes
for (var sfx = snowFoxes.length - 1; sfx >= 0; sfx--) {
snowFoxes[sfx].destroy();
snowFoxes.splice(sfx, 1);
}
// Create motorcycle rider face (using playerCar as face placeholder)
var motorcycleRiderFace = game.addChild(new Character());
motorcycleRiderFace.x = 300;
motorcycleRiderFace.y = 2732 - 200;
motorcycleRiderFace.scaleX = 2.0;
motorcycleRiderFace.scaleY = 2.0;
motorcycleRiderFace.alpha = 0;
motorcycleRiderFace.setVehicle('car');
// Create motorcycle rider message - first line
var motorcycleMessage1 = new Text2('', {
size: 60,
fill: 0xFFFFFF,
font: "drifttype"
});
motorcycleMessage1.anchor.set(0, 1);
motorcycleMessage1.x = 550;
motorcycleMessage1.y = 2732 - 100;
game.addChild(motorcycleMessage1);
// Create motorcycle rider message - second line
var motorcycleMessage2 = new Text2('', {
size: 60,
fill: 0xFFFFFF,
font: "drifttype"
});
motorcycleMessage2.anchor.set(0, 1);
motorcycleMessage2.x = 550;
motorcycleMessage2.y = 2732 - 50;
game.addChild(motorcycleMessage2);
// Fade in motorcycle rider face first
tween(motorcycleRiderFace, {
alpha: 1
}, {
duration: 1000,
easing: tween.easeIn,
onFinish: function onFinish() {
// Check if score is 2000 or more to start motorcycle rider animation
if (LK.getScore() >= 2000) {
// Undertale-style typewriter effect for two lines
var motorcycleMessageText1 = 'çok trafik var iş yerine nasıl yetişicem';
var motorcycleMessageText2 = 'en iyisi hızımı artırmak';
var motorcycleCharIndex1 = 0;
var motorcycleCharIndex2 = 0;
var isTypingFirstLine = false;
var isTypingSecondLine = false;
var motorcycleTypewriterTimer1 = null;
var motorcycleTypewriterTimer2 = null;
// Start first line typewriter
isTypingFirstLine = true;
motorcycleTypewriterTimer1 = LK.setInterval(function () {
if (motorcycleCharIndex1 < motorcycleMessageText1.length) {
motorcycleCharIndex1++;
motorcycleMessage1.setText(motorcycleMessageText1.substring(0, motorcycleCharIndex1));
} else {
LK.clearInterval(motorcycleTypewriterTimer1);
isTypingFirstLine = false;
// Start second line after first line is complete
LK.setTimeout(function () {
isTypingSecondLine = true;
motorcycleTypewriterTimer2 = LK.setInterval(function () {
if (motorcycleCharIndex2 < motorcycleMessageText2.length) {
motorcycleCharIndex2++;
motorcycleMessage2.setText(motorcycleMessageText2.substring(0, motorcycleCharIndex2));
} else {
LK.clearInterval(motorcycleTypewriterTimer2);
isTypingSecondLine = false;
// Keep message visible for 3 seconds, then fade out and continue game
LK.setTimeout(function () {
tween(motorcycleRiderFace, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(motorcycleMessage1, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut
});
tween(motorcycleMessage2, {
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
motorcycleRiderFace.destroy();
motorcycleMessage1.destroy();
motorcycleMessage2.destroy();
player.setVehicle('car');
gameStarted = true;
LK.effects.flashScreen(0x0066FF, 1500); // Blue flash
}
});
}, 3000);
}
}, 80); // 80ms per character for Undertale-style speed
}, 500); // 500ms delay between lines
}
}, 80); // 80ms per character for Undertale-style speed
} else {
// If score is less than 2000, wait for score to reach 2000
var waitForScore = LK.setInterval(function () {
if (LK.getScore() >= 2000) {
LK.clearInterval(waitForScore);
// Restart the motorcycle rider animation
onFinish();
}
}, 100);
}
}
});
}
}
}
// Increase difficulty over time
difficultyTimer++;
if (difficultyTimer % 300 === 0) {
gameSpeed = Math.min(gameSpeed + 0.5, 15);
currentObstacleSpawnRate = Math.max(currentObstacleSpawnRate - 2, minObstacleSpawnRate);
}
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= currentObstacleSpawnRate) {
spawnObstacle();
obstacleSpawnTimer = 0;
}
// Spawn snow
snowSpawnTimer++;
if (snowSpawnTimer >= 15) {
spawnSnowFlake();
snowSpawnTimer = 0;
}
// Spawn snow foxes in snow level
if (currentLevel === 1 && LK.ticks % 200 === 0) {
var snowFox = new SnowFox();
snowFox.x = Math.random() * (2048 - 200) + 100;
snowFox.y = -100;
snowFoxes.push(snowFox);
game.addChild(snowFox);
}
// Spawn snakes and scorpions in desert level
if (currentLevel === 2 && LK.ticks % 180 === 0) {
var enemyType = Math.random() < 0.5 ? 'snake' : 'scorpion';
if (enemyType === 'snake') {
var snake = new Snake();
snake.x = Math.random() * (2048 - 200) + 100;
snake.y = -100;
snakes.push(snake);
game.addChild(snake);
} else {
var scorpion = new Scorpion();
scorpion.x = Math.random() * (2048 - 200) + 100;
scorpion.y = -100;
scorpions.push(scorpion);
game.addChild(scorpion);
}
}
// Spawn city elements in level 3
if (currentLevel === 3) {
// Spawn road lines
if (LK.ticks % 20 === 0) {
var roadLine = new RoadLine();
roadLine.x = 2048 / 2;
roadLine.y = -50;
roadLines.push(roadLine);
game.addChild(roadLine);
}
}
// Spawn trail dots or tire trails based on vehicle
trailSpawnTimer++;
if (trailSpawnTimer >= 8) {
if (currentLevel === 3) {
// Create tire trails for car in city level
var leftTireTrail = new TireTrail();
leftTireTrail.x = player.x - 25;
leftTireTrail.y = player.y + 30;
tireTrails.push(leftTireTrail);
game.addChild(leftTireTrail);
var rightTireTrail = new TireTrail();
rightTireTrail.x = player.x + 25;
rightTireTrail.y = player.y + 30;
tireTrails.push(rightTireTrail);
game.addChild(rightTireTrail);
} else {
// Create regular trail dots for other vehicles
var leftTrail = new TrailDot();
leftTrail.x = player.x - 30;
leftTrail.y = player.y + 20;
trailDots.push(leftTrail);
game.addChild(leftTrail);
var rightTrail = new TrailDot();
rightTrail.x = player.x + 30;
rightTrail.y = player.y + 20;
trailDots.push(rightTrail);
game.addChild(rightTrail);
}
trailSpawnTimer = 0;
}
// Update and check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
// Update speed based on game speed
obstacle.speed = gameSpeed;
// Check if obstacle went off screen
if (obstacle.lastY <= 2800 && obstacle.y > 2800) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with player
var currentIntersecting = obstacle.intersects(player);
if (!obstacle.lastIntersecting && currentIntersecting) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xFF0000, 1000);
lives--;
livesTxt.setText('Can: ' + lives);
if (lives <= 0) {
LK.showGameOver();
return;
} else {
// Flash player to show damage
tween(player, {
alpha: 0.3
}, {
duration: 200,
onFinish: function onFinish() {
tween(player, {
alpha: 1
}, {
duration: 200
});
}
});
}
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
obstacle.lastY = obstacle.y;
obstacle.lastIntersecting = currentIntersecting;
}
// Update and clean up snow flakes
for (var j = snowFlakes.length - 1; j >= 0; j--) {
var snowFlake = snowFlakes[j];
snowFlake.speed = gameSpeed * 0.7;
if (snowFlake.y > 2800 || snowFlake.x < -100 || snowFlake.x > 2148) {
snowFlake.destroy();
snowFlakes.splice(j, 1);
}
}
// Update and clean up sand particles
for (var l = sandParticles.length - 1; l >= 0; l--) {
var sandParticle = sandParticles[l];
sandParticle.speed = gameSpeed * 0.7;
if (sandParticle.y > 2800 || sandParticle.x < -100 || sandParticle.x > 2148) {
sandParticle.destroy();
sandParticles.splice(l, 1);
}
}
// Update and clean up trail dots
for (var k = trailDots.length - 1; k >= 0; k--) {
var trailDot = trailDots[k];
trailDot.speed = gameSpeed;
if (trailDot.y > 2800 || trailDot.alpha <= 0) {
trailDot.destroy();
trailDots.splice(k, 1);
}
}
// Update and clean up tire trails
for (var t = tireTrails.length - 1; t >= 0; t--) {
var tireTrail = tireTrails[t];
tireTrail.speed = gameSpeed;
if (tireTrail.y > 2800 || tireTrail.alpha <= 0) {
tireTrail.destroy();
tireTrails.splice(t, 1);
}
}
// Update and clean up snakes (with collision damage)
for (var m = snakes.length - 1; m >= 0; m--) {
var snake = snakes[m];
snake.speed = gameSpeed * 0.8;
// Initialize collision tracking
if (snake.lastIntersecting === undefined) snake.lastIntersecting = false;
// Check collision with player
var currentIntersecting = snake.intersects(player);
if (!snake.lastIntersecting && currentIntersecting) {
// Make snake fly up and rotate
tween(snake, {
y: snake.y - 200,
rotation: Math.PI * 1.5,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 600,
easing: tween.easeOut
});
snake.destroy();
snakes.splice(m, 1);
continue;
}
snake.lastIntersecting = currentIntersecting;
if (snake.y > 2800 || snake.x < -100 || snake.x > 2148) {
snake.destroy();
snakes.splice(m, 1);
}
}
// Update and clean up scorpions (with collision damage)
for (var n = scorpions.length - 1; n >= 0; n--) {
var scorpion = scorpions[n];
scorpion.speed = gameSpeed * 0.8;
// Initialize collision tracking
if (scorpion.lastIntersecting === undefined) scorpion.lastIntersecting = false;
// Check collision with player
var currentIntersecting = scorpion.intersects(player);
if (!scorpion.lastIntersecting && currentIntersecting) {
// Make scorpion fly up and rotate
tween(scorpion, {
y: scorpion.y - 180,
rotation: -Math.PI * 1.2,
scaleX: 0.6,
scaleY: 0.6
}, {
duration: 500,
easing: tween.easeOut
});
scorpion.destroy();
scorpions.splice(n, 1);
continue;
}
scorpion.lastIntersecting = currentIntersecting;
if (scorpion.y > 2800 || scorpion.x < -100 || scorpion.x > 2148) {
scorpion.destroy();
scorpions.splice(n, 1);
}
}
// Update and clean up cars
for (var p = cars.length - 1; p >= 0; p--) {
var car = cars[p];
car.speed = gameSpeed;
// Initialize collision tracking
if (car.lastIntersecting === undefined) car.lastIntersecting = false;
// Initialize road line intersection tracking
if (car.lastRoadLineIntersecting === undefined) car.lastRoadLineIntersecting = false;
// Check if car is intersecting with any road line and hide the road line instead
for (var rl = 0; rl < roadLines.length; rl++) {
if (car.intersects(roadLines[rl])) {
roadLines[rl].visible = false;
} else {
roadLines[rl].visible = true;
}
}
// Check collision with player
var currentIntersecting = car.intersects(player);
if (!car.lastIntersecting && currentIntersecting) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xFF0000, 1000);
lives--;
livesTxt.setText('Can: ' + lives);
if (lives <= 0) {
LK.showGameOver();
return;
} else {
tween(player, {
alpha: 0.3
}, {
duration: 200,
onFinish: function onFinish() {
tween(player, {
alpha: 1
}, {
duration: 200
});
}
});
}
car.destroy();
cars.splice(p, 1);
continue;
}
car.lastIntersecting = currentIntersecting;
if (car.y > 2800) {
car.destroy();
cars.splice(p, 1);
}
}
// Update and clean up snow foxes (with collision animation)
for (var sf = snowFoxes.length - 1; sf >= 0; sf--) {
var snowFox = snowFoxes[sf];
snowFox.speed = gameSpeed * 0.8;
// Initialize collision tracking
if (snowFox.lastIntersecting === undefined) snowFox.lastIntersecting = false;
// Check collision with player
var currentIntersecting = snowFox.intersects(player);
if (!snowFox.lastIntersecting && currentIntersecting) {
// Make snow fox fly up and rotate gracefully
tween(snowFox, {
y: snowFox.y - 220,
rotation: Math.PI * 1.8,
scaleX: 0.4,
scaleY: 0.4
}, {
duration: 700,
easing: tween.easeOut
});
snowFox.destroy();
snowFoxes.splice(sf, 1);
continue;
}
snowFox.lastIntersecting = currentIntersecting;
if (snowFox.y > 2800 || snowFox.x < -100 || snowFox.x > 2148) {
snowFox.destroy();
snowFoxes.splice(sf, 1);
}
}
// Update and clean up road lines
for (var s = roadLines.length - 1; s >= 0; s--) {
var roadLine = roadLines[s];
roadLine.speed = gameSpeed;
if (roadLine.y > 2800) {
roadLine.destroy();
roadLines.splice(s, 1);
}
}
};
arkasından gördüğümüz kızağa oturan pixel bir çocuk yap. In-Game asset. 2d. High contrast. No shadows
kesilmiş bir pixel ağaç yap sadece kesilmiş tarafı olsun
pixel bir kar yap. In-Game asset. 2d. High contrast. No shadows
pixel kayalar. In-Game asset. 2d. High contrast. No shadows
vazoda olmayan bir çöl kaktüsü yap pixel şekilde. In-Game asset. 2d. High contrast. No shadows
pixel akrep yap. In-Game asset. 2d. High contrast. No shadows
pixel yılan yap. In-Game asset. 2d. High contrast. No shadows
pixel kar tilkisi ekle. In-Game asset. 2d. High contrast. No shadows
kurumuş ağaç ekle pixel şeklinde. In-Game asset. 2d. High contrast. No shadows
yeşil arkası dönük bir pixel araba ekle. In-Game asset. 2d. High contrast. No shadows
arkası dönük mavi bir pixel araba ekle. In-Game asset. 2d. High contrast. No shadows
arkası dönük sarı bir araba ekle pixel şeklinde. In-Game asset. 2d. High contrast. No shadows
at üstünde olan pixel bir adam arkası dönük. In-Game asset. 2d. High contrast. No shadows
pixel mavi kazaklı yüzü dönük çocuk yap. beresi turuncu olsun
pixel motor üstünde bir adam koy arkası dönük olsun. In-Game asset. 2d. High contrast. No shadows