User prompt
Seviyelerde ki Bütün duvarlar hareket halinde olsunlar. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Level 12'ye birkaç tane duvar ekle. Ayrıca hareket etsinler. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Bütün duvarların etki alanını, duvar resim alanı ile eşitle.
User prompt
Duvara değince araç patlamasın. Sadece duvara değince duvar içerisinden geçmesin.
User prompt
Power'in de rengi değişmesin.
User prompt
Bunu düzelt. Renk değişmesin hiçbir şekilde.
User prompt
Speed 5 ve üzeri olunca Speed yazısı görünmez oluyor.
User prompt
Her seviyede 100 puan alalım. Bu puanları, güç ve hız geliştirme yapabilmek için kullanalım. Her geliştirme %5 artış sağlasın. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Speed hızlanınca kaybolmasın.
User prompt
Ekranın alt orda kısmına, aracın güç göstergesi gelsin. Hızı ve gücü görünsün. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Brake basınca araç geri gitmiyor.
User prompt
3 saniyelik dokunulmazlık konusunu, yolda gitmeyi muaf et. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Başlangıçta araba 3 saniye dokunulmaz olsun ve patlamasın. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Level 20'de başlangıç yerinin sağında ki duvarı kaldır.
User prompt
Level 20'i yeniden yapılandır. Ayrıca son 5 seviyede, duvarlar yavaş yavaş hareket etsinler. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Araç tramboline değince patlamasın.
User prompt
Araç, duvara değmeden patlıyor. Yakınına gelince değil. Tamamen duvara değdiği zaman parlasın.
User prompt
Araç dik olunca patlamasın. Yolu takip etmeye devam etsin.
User prompt
Çizginin içinden araba geçmesin. Daima çizgiyi takip etsin.
User prompt
Brake butonuna basınca geriye doğru hızlanma oranını %200 oranında azalt. Aynı işlev pedal konusunda da geçerli olsun.
User prompt
Brake butonuna basınca hızlanma oranını %200 azalt.
User prompt
Brake butonuna basınca, hızlanma oranını %200 azalt.
User prompt
Brake butonuna basılı tutunca, ilk yavaş şekilde, hızlanarak geri gitmesini sağla.
User prompt
Brake butonuna basınca, geriye yönlü teklemesin. Aynı ileri gidiyor gibi, geri gitsin.
User prompt
Brake butonunu ve pedal butonunu %100 oranında büyüt.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Car = Container.expand(function () {
var self = Container.call(this);
var carBody = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
var wheelLeft = self.attachAsset('wheel', {
anchorX: 0.5,
anchorY: 0.5,
x: -25,
y: 20
});
var wheelRight = self.attachAsset('wheel', {
anchorX: 0.5,
anchorY: 0.5,
x: 25,
y: 20
});
self.velocityX = 0;
self.velocityY = 0;
self.speed = 2;
self.gravity = 0.3;
self.onGround = false;
self.engineWorking = true;
self.update = function () {
// Only update physics if game has started
if (!gameStarted) return;
// Only apply gravity, no automatic movement
self.velocityY += self.gravity;
self.x += self.velocityX;
self.y += self.velocityY;
wheelLeft.rotation += self.velocityX * 0.1;
wheelRight.rotation += self.velocityX * 0.1;
};
self.setVelocity = function (vx, vy) {
self.velocityX = vx;
self.velocityY = vy;
};
return self;
});
var DrawnLine = Container.expand(function () {
var self = Container.call(this);
self.points = [];
self.segments = [];
self.addPoint = function (x, y) {
self.points.push({
x: x,
y: y
});
if (self.points.length > 1) {
var lastPoint = self.points[self.points.length - 2];
var currentPoint = self.points[self.points.length - 1];
var dx = currentPoint.x - lastPoint.x;
var dy = currentPoint.y - lastPoint.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var angle = Math.atan2(dy, dx);
var segment = self.attachAsset('wall', {
anchorX: 0,
anchorY: 0.5,
x: lastPoint.x,
y: lastPoint.y,
scaleX: distance / 200,
scaleY: 0.1,
rotation: angle,
tint: 0x0000FF
});
self.segments.push(segment);
}
};
self.getSegments = function () {
var segmentData = [];
for (var i = 0; i < self.points.length - 1; i++) {
segmentData.push({
start: self.points[i],
end: self.points[i + 1]
});
}
return segmentData;
};
return self;
});
var SmokeParticle = Container.expand(function () {
var self = Container.call(this);
var smokeGraphics = self.attachAsset('wheel', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x999999,
alpha: 0.6
});
self.init = function (x, y) {
self.x = x;
self.y = y;
self.scale.set(0.3);
// Animate the smoke particle
tween(self, {
y: y - 50,
alpha: 0
}, {
duration: 800,
easing: tween.easeOut
});
tween(self.scale, {
x: 1.2,
y: 1.2
}, {
duration: 800,
easing: tween.easeOut
});
};
return self;
});
var Trampoline = Container.expand(function () {
var self = Container.call(this);
var trampolineGraphics = self.attachAsset('trampoline', {
anchorX: 0.5,
anchorY: 0.5
});
self.bounce = function () {
tween(trampolineGraphics, {
scaleY: 0.7
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(trampolineGraphics, {
scaleY: 1
}, {
duration: 200,
easing: tween.bounceOut
});
}
});
};
return self;
});
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xE8E8E8
});
/****
* Game Code
****/
var currentLevel = storage.currentLevel || 1;
var maxLevel = 20;
var car = null;
var walls = [];
var trampolines = [];
var drawnLine = null;
var isDrawing = false;
var levelComplete = false;
var carCanMove = false;
var gameStarted = false;
var startButton = null;
var startButtonText = null;
var refreshButton = null;
var refreshButtonText = null;
var resetButton = null;
var resetButtonText = null;
var backButton = null;
var backButtonText = null;
var smokeParticles = [];
var smokeTimer = 0;
var drawnLines = []; // Array to store all drawn lines
var maxLines = 3; // Maximum lines per level
var currentLineCount = 0; // Current number of lines drawn
var pedalButton = null;
var pedalButtonText = null;
var brakeButton = null;
var brakeButtonText = null;
var brakeButtonPressed = false;
var brakeAcceleration = 0;
var maxBrakeAcceleration = 3.0;
var brakeAccelerationIncrement = 0.0037; // Reduced by 200% from 0.011 (0.011 / 3)
var pedalButtonPressed = false;
var pedalAcceleration = 0;
var maxPedalAcceleration = 3.0;
var pedalAccelerationIncrement = 0.0037; // Same reduced rate as brake
var startPos = {
x: 200,
y: 1000
};
var finishPos = {
x: 1800,
y: 1000
};
var levelText = new Text2('Level ' + currentLevel, {
size: 80,
fill: 0x333333
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
var instructionText = new Text2('Draw a path from behind the car!', {
size: 50,
fill: 0x666666
});
instructionText.anchor.set(0.5, 0);
instructionText.y = 100;
LK.gui.top.addChild(instructionText);
// Create or update line counter text
if (!game.lineCounterText) {
game.lineCounterText = new Text2('Lines: 3/3', {
size: 40,
fill: 0x666666
});
game.lineCounterText.anchor.set(0.5, 0);
game.lineCounterText.y = 150;
LK.gui.top.addChild(game.lineCounterText);
}
game.lineCounterText.setText('Lines: ' + (maxLines - currentLineCount) + '/' + maxLines);
function setupLevel(level) {
// Clear existing objects
if (car) car.destroy();
for (var i = 0; i < walls.length; i++) {
walls[i].destroy();
}
for (var i = 0; i < trampolines.length; i++) {
trampolines[i].destroy();
}
if (drawnLine) drawnLine.destroy();
// Clear smoke particles
for (var i = 0; i < smokeParticles.length; i++) {
smokeParticles[i].destroy();
}
smokeParticles = [];
// Clear all drawn lines
for (var i = 0; i < drawnLines.length; i++) {
drawnLines[i].destroy();
}
drawnLines = [];
walls = [];
trampolines = [];
drawnLine = null;
isDrawing = false;
levelComplete = false;
carCanMove = false;
gameStarted = false;
currentLineCount = 0; // Reset line counter
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0,
x: 1024,
y: 2532
}));
// Create start and finish flags
var startFlag = game.addChild(LK.getAsset('startFlag', {
anchorX: 0.5,
anchorY: 1,
x: startPos.x,
y: startPos.y + 50
}));
var finishFlag = game.addChild(LK.getAsset('finishFlag', {
anchorX: 0.5,
anchorY: 1,
x: finishPos.x,
y: finishPos.y + 50
}));
// Reset finish position to default for all levels
finishPos.x = 1800;
finishPos.y = 1000;
finishFlag.x = finishPos.x;
finishFlag.y = finishPos.y + 50;
// Setup level-specific elements
if (level === 1) {
// Simple level - just draw from start to finish
instructionText.setText('Draw a path, use PEDAL/BRAKE to control car!');
} else if (level === 2) {
// Wall in the middle
var wall = new Wall();
wall.x = 1024;
wall.y = 1000;
walls.push(wall);
game.addChild(wall);
instructionText.setText('Draw around the wall!');
} else if (level === 3) {
// L-shaped obstacle
var wall1 = new Wall();
wall1.x = 1024;
wall1.y = 1000;
wall1.scaleX = 2;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 1224;
wall2.y = 900;
wall2.rotation = Math.PI / 2;
walls.push(wall2);
game.addChild(wall2);
instructionText.setText('Navigate the L-shape!');
} else if (level === 4) {
// Multiple trampolines with strategic positioning
var wall1 = new Wall();
wall1.x = 600;
wall1.y = 1000;
wall1.scaleX = 1.5;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 1200;
wall2.y = 1200;
wall2.scaleY = 2;
walls.push(wall2);
game.addChild(wall2);
var trampoline1 = new Trampoline();
trampoline1.x = 400;
trampoline1.y = 1200;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 800;
trampoline2.y = 800;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1400;
trampoline3.y = 1000;
trampolines.push(trampoline3);
game.addChild(trampoline3);
finishPos.y = 600;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Bounce through the obstacle course!');
} else if (level === 5) {
// Multi-stage obstacle course with steep climbs and precision jumps
// Create ascending wall platforms
var wall1 = new Wall();
wall1.x = 400;
wall1.y = 1200;
wall1.scaleX = 1.5;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 700;
wall2.y = 1000;
wall2.scaleX = 1.2;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1000;
wall3.y = 800;
wall3.scaleX = 1.8;
walls.push(wall3);
game.addChild(wall3);
var wall4 = new Wall();
wall4.x = 1300;
wall4.y = 600;
wall4.scaleX = 1.5;
walls.push(wall4);
game.addChild(wall4);
// Create vertical barriers for added difficulty
var wall5 = new Wall();
wall5.x = 550;
wall5.y = 1100;
wall5.scaleY = 1.5;
walls.push(wall5);
game.addChild(wall5);
var wall6 = new Wall();
wall6.x = 850;
wall6.y = 900;
wall6.scaleY = 2;
walls.push(wall6);
game.addChild(wall6);
var wall7 = new Wall();
wall7.x = 1150;
wall7.y = 700;
wall7.scaleY = 1.8;
walls.push(wall7);
game.addChild(wall7);
// Strategic trampoline placement for multi-bounce sequences
var trampoline1 = new Trampoline();
trampoline1.x = 600;
trampoline1.y = 1350;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 900;
trampoline2.y = 1150;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1200;
trampoline3.y = 950;
trampolines.push(trampoline3);
game.addChild(trampoline3);
var trampoline4 = new Trampoline();
trampoline4.x = 1500;
trampoline4.y = 750;
trampolines.push(trampoline4);
game.addChild(trampoline4);
finishPos.y = 400;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Master the multi-stage climb! Precision required!');
} else if (level === 6) {
// Multiple trampolines with walls
var wall1 = new Wall();
wall1.x = 800;
wall1.y = 1000;
wall1.scaleY = 2;
walls.push(wall1);
game.addChild(wall1);
var trampoline1 = new Trampoline();
trampoline1.x = 600;
trampoline1.y = 1300;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 1400;
trampoline2.y = 800;
trampolines.push(trampoline2);
game.addChild(trampoline2);
instructionText.setText('Bounce your way through!');
} else if (level === 7) {
// Engine failure with multiple obstacles
var wall1 = new Wall();
wall1.x = 600;
wall1.y = 1100;
wall1.rotation = Math.PI / 4;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 1400;
wall2.y = 900;
wall2.rotation = -Math.PI / 4;
walls.push(wall2);
game.addChild(wall2);
finishPos.y = 1200;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Engine down! Tap car to push! Navigate carefully!');
} else if (level === 8) {
// Maze-like structure
var wall1 = new Wall();
wall1.x = 500;
wall1.y = 1000;
wall1.scaleX = 1.5;
wall1.rotation = Math.PI / 2;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 800;
wall2.y = 800;
wall2.scaleX = 1.5;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1200;
wall3.y = 1200;
wall3.scaleX = 1.5;
wall3.rotation = Math.PI / 2;
walls.push(wall3);
game.addChild(wall3);
var wall4 = new Wall();
wall4.x = 1500;
wall4.y = 900;
wall4.scaleX = 1.5;
walls.push(wall4);
game.addChild(wall4);
instructionText.setText('Find your way through the maze!');
} else if (level === 9) {
// Trampoline sequence
var trampoline1 = new Trampoline();
trampoline1.x = 400;
trampoline1.y = 1200;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 700;
trampoline2.y = 900;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1000;
trampoline3.y = 700;
trampolines.push(trampoline3);
game.addChild(trampoline3);
var trampoline4 = new Trampoline();
trampoline4.x = 1300;
trampoline4.y = 1100;
trampolines.push(trampoline4);
game.addChild(trampoline4);
finishPos.y = 800;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Bounce through the sequence!');
} else if (level === 10) {
// Moving trampolines with precise timing - engine failure
finishPos.y = 400;
finishFlag.y = finishPos.y + 50;
// Create three moving trampolines
var trampoline1 = new Trampoline();
trampoline1.x = 500;
trampoline1.y = 1300;
trampoline1.moveDirection = 1;
trampoline1.moveSpeed = 2;
trampoline1.minX = 400;
trampoline1.maxX = 700;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 1000;
trampoline2.y = 1000;
trampoline2.moveDirection = -1;
trampoline2.moveSpeed = 3;
trampoline2.minX = 800;
trampoline2.maxX = 1200;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1400;
trampoline3.y = 700;
trampoline3.moveDirection = 1;
trampoline3.moveSpeed = 2.5;
trampoline3.minX = 1200;
trampoline3.maxX = 1600;
trampolines.push(trampoline3);
game.addChild(trampoline3);
// Add walls to create platforms
var wall1 = new Wall();
wall1.x = 600;
wall1.y = 1200;
wall1.scaleX = 2;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 1100;
wall2.y = 900;
wall2.scaleX = 2;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1500;
wall3.y = 600;
wall3.scaleX = 2;
walls.push(wall3);
game.addChild(wall3);
instructionText.setText('Time your jumps! Moving trampolines! Engine failed! Tap car to push!');
} else if (level === 11) {
// Complex obstacle course
var wall1 = new Wall();
wall1.x = 400;
wall1.y = 1000;
wall1.scaleY = 3;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 800;
wall2.y = 800;
wall2.scaleX = 2;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1200;
wall3.y = 1200;
wall3.scaleY = 2;
walls.push(wall3);
game.addChild(wall3);
var trampoline = new Trampoline();
trampoline.x = 600;
trampoline.y = 1300;
trampolines.push(trampoline);
game.addChild(trampoline);
finishPos.y = 700;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Navigate the obstacle course!');
} else if (level === 12) {
// Multiple gaps with trampolines
finishPos.y = 1600;
finishFlag.y = finishPos.y + 50;
var trampoline1 = new Trampoline();
trampoline1.x = 500;
trampoline1.y = 1200;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 900;
trampoline2.y = 1000;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1300;
trampoline3.y = 1300;
trampolines.push(trampoline3);
game.addChild(trampoline3);
instructionText.setText('Bridge multiple gaps!');
} else if (level === 13) {
// Simplified level with basic platforms and reasonable difficulty
// Create simple ascending platforms
var wall1 = new Wall();
wall1.x = 600;
wall1.y = 1100;
wall1.scaleX = 1.5;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 1000;
wall2.y = 900;
wall2.scaleX = 1.5;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1300;
wall3.y = 700;
wall3.scaleX = 1.5;
walls.push(wall3);
game.addChild(wall3);
// Add two trampolines for reasonable jumping
var trampoline1 = new Trampoline();
trampoline1.x = 450;
trampoline1.y = 1250;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 850;
trampoline2.y = 1050;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1150;
trampoline3.y = 850;
trampolines.push(trampoline3);
game.addChild(trampoline3);
finishPos.y = 600;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Jump up the platforms! Engine failed! Tap car to push!');
} else if (level === 14) {
// Tower climbing
var wall1 = new Wall();
wall1.x = 500;
wall1.y = 1200;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 700;
wall2.y = 1000;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 900;
wall3.y = 800;
walls.push(wall3);
game.addChild(wall3);
var wall4 = new Wall();
wall4.x = 1100;
wall4.y = 600;
walls.push(wall4);
game.addChild(wall4);
var trampoline1 = new Trampoline();
trampoline1.x = 600;
trampoline1.y = 1300;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 800;
trampoline2.y = 1100;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1000;
trampoline3.y = 900;
trampolines.push(trampoline3);
game.addChild(trampoline3);
finishPos.y = 400;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Climb the tower!');
} else if (level === 15) {
// Zigzag with engine failure
var wall1 = new Wall();
wall1.x = 400;
wall1.y = 1100;
wall1.rotation = Math.PI / 3;
wall1.scaleX = 1.5;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 700;
wall2.y = 900;
wall2.rotation = -Math.PI / 3;
wall2.scaleX = 1.5;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1000;
wall3.y = 1100;
wall3.rotation = Math.PI / 3;
wall3.scaleX = 1.5;
walls.push(wall3);
game.addChild(wall3);
var wall4 = new Wall();
wall4.x = 1300;
wall4.y = 900;
wall4.rotation = -Math.PI / 3;
wall4.scaleX = 1.5;
walls.push(wall4);
game.addChild(wall4);
instructionText.setText('Zigzag to victory! Engine failed! Tap car to push!');
} else if (level === 16) {
// Double trampoline jump
var trampoline1 = new Trampoline();
trampoline1.x = 600;
trampoline1.y = 1200;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 1000;
trampoline2.y = 800;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var wall1 = new Wall();
wall1.x = 800;
wall1.y = 1000;
wall1.scaleX = 3;
walls.push(wall1);
game.addChild(wall1);
finishPos.y = 600;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Double bounce to reach the top!');
} else if (level === 17) {
// Narrow passage with engine failure
var wall1 = new Wall();
wall1.x = 800;
wall1.y = 900;
wall1.scaleY = 4;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 1200;
wall2.y = 1100;
wall2.scaleY = 4;
walls.push(wall2);
game.addChild(wall2);
var trampoline = new Trampoline();
trampoline.x = 1000;
trampoline.y = 1300;
trampolines.push(trampoline);
game.addChild(trampoline);
finishPos.y = 800;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Thread the needle! Engine failed! Tap car to push!');
} else if (level === 18) {
// Multi-level platform
var wall1 = new Wall();
wall1.x = 500;
wall1.y = 1200;
wall1.scaleX = 2;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 800;
wall2.y = 1000;
wall2.scaleX = 2;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1100;
wall3.y = 800;
wall3.scaleX = 2;
walls.push(wall3);
game.addChild(wall3);
var wall4 = new Wall();
wall4.x = 1400;
wall4.y = 600;
wall4.scaleX = 2;
walls.push(wall4);
game.addChild(wall4);
var trampoline1 = new Trampoline();
trampoline1.x = 650;
trampoline1.y = 1300;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 950;
trampoline2.y = 1100;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1250;
trampoline3.y = 900;
trampolines.push(trampoline3);
game.addChild(trampoline3);
finishPos.y = 500;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Climb the platforms!');
} else if (level === 19) {
// Extreme obstacle course with engine failure
var wall1 = new Wall();
wall1.x = 400;
wall1.y = 1100;
wall1.rotation = Math.PI / 4;
wall1.scaleX = 2;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 700;
wall2.y = 800;
wall2.rotation = -Math.PI / 4;
wall2.scaleX = 2;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1000;
wall3.y = 1200;
wall3.rotation = Math.PI / 6;
wall3.scaleX = 2;
walls.push(wall3);
game.addChild(wall3);
var wall4 = new Wall();
wall4.x = 1300;
wall4.y = 700;
wall4.rotation = -Math.PI / 6;
wall4.scaleX = 2;
walls.push(wall4);
game.addChild(wall4);
var trampoline1 = new Trampoline();
trampoline1.x = 550;
trampoline1.y = 1300;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 850;
trampoline2.y = 1000;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1150;
trampoline3.y = 900;
trampolines.push(trampoline3);
game.addChild(trampoline3);
finishPos.y = 500;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Ultimate challenge! Engine failed! Tap car to push!');
} else if (level === 16) {
// Double trampoline jump
var trampoline1 = new Trampoline();
trampoline1.x = 600;
trampoline1.y = 1200;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 1000;
trampoline2.y = 800;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var wall1 = new Wall();
wall1.x = 800;
wall1.y = 1000;
wall1.scaleX = 3;
walls.push(wall1);
game.addChild(wall1);
// Add moving wall for level 16
var movingWall1 = new Wall();
movingWall1.x = 400;
movingWall1.y = 900;
movingWall1.scaleY = 2;
walls.push(movingWall1);
game.addChild(movingWall1);
// Start slow movement
tween(movingWall1, {
y: 1100
}, {
duration: 3000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
y: 900
}, {
duration: 3000,
easing: tween.linear,
onFinish: function onFinish() {
// Loop the movement
tween(movingWall1, {
y: 1100
}, {
duration: 3000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
y: 900
}, {
duration: 3000,
easing: tween.linear
});
}
});
}
});
}
});
finishPos.y = 600;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Double bounce to reach the top! Avoid moving walls!');
} else if (level === 17) {
// Narrow passage with engine failure
var wall1 = new Wall();
wall1.x = 800;
wall1.y = 900;
wall1.scaleY = 4;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 1200;
wall2.y = 1100;
wall2.scaleY = 4;
walls.push(wall2);
game.addChild(wall2);
// Add moving wall for level 17
var movingWall1 = new Wall();
movingWall1.x = 600;
movingWall1.y = 1200;
movingWall1.scaleX = 1.5;
walls.push(movingWall1);
game.addChild(movingWall1);
// Start slow horizontal movement
tween(movingWall1, {
x: 900
}, {
duration: 4000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
x: 600
}, {
duration: 4000,
easing: tween.linear,
onFinish: function onFinish() {
// Loop the movement
tween(movingWall1, {
x: 900
}, {
duration: 4000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
x: 600
}, {
duration: 4000,
easing: tween.linear
});
}
});
}
});
}
});
var trampoline = new Trampoline();
trampoline.x = 1000;
trampoline.y = 1300;
trampolines.push(trampoline);
game.addChild(trampoline);
finishPos.y = 800;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Thread the needle! Engine failed! Tap car to push!');
} else if (level === 18) {
// Multi-level platform
var wall1 = new Wall();
wall1.x = 500;
wall1.y = 1200;
wall1.scaleX = 2;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 800;
wall2.y = 1000;
wall2.scaleX = 2;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1100;
wall3.y = 800;
wall3.scaleX = 2;
walls.push(wall3);
game.addChild(wall3);
var wall4 = new Wall();
wall4.x = 1400;
wall4.y = 600;
wall4.scaleX = 2;
walls.push(wall4);
game.addChild(wall4);
// Add moving wall for level 18
var movingWall1 = new Wall();
movingWall1.x = 700;
movingWall1.y = 900;
movingWall1.scaleY = 2;
walls.push(movingWall1);
game.addChild(movingWall1);
// Start slow vertical movement
tween(movingWall1, {
y: 1100
}, {
duration: 3500,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
y: 900
}, {
duration: 3500,
easing: tween.linear,
onFinish: function onFinish() {
// Loop the movement
tween(movingWall1, {
y: 1100
}, {
duration: 3500,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
y: 900
}, {
duration: 3500,
easing: tween.linear
});
}
});
}
});
}
});
var trampoline1 = new Trampoline();
trampoline1.x = 650;
trampoline1.y = 1300;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 950;
trampoline2.y = 1100;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1250;
trampoline3.y = 900;
trampolines.push(trampoline3);
game.addChild(trampoline3);
finishPos.y = 500;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Climb the platforms! Avoid moving obstacles!');
} else if (level === 19) {
// Extreme obstacle course with engine failure
var wall1 = new Wall();
wall1.x = 400;
wall1.y = 1100;
wall1.rotation = Math.PI / 4;
wall1.scaleX = 2;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 700;
wall2.y = 800;
wall2.rotation = -Math.PI / 4;
wall2.scaleX = 2;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1000;
wall3.y = 1200;
wall3.rotation = Math.PI / 6;
wall3.scaleX = 2;
walls.push(wall3);
game.addChild(wall3);
var wall4 = new Wall();
wall4.x = 1300;
wall4.y = 700;
wall4.rotation = -Math.PI / 6;
wall4.scaleX = 2;
walls.push(wall4);
game.addChild(wall4);
// Add two moving walls for level 19
var movingWall1 = new Wall();
movingWall1.x = 600;
movingWall1.y = 1000;
movingWall1.scaleY = 1.5;
walls.push(movingWall1);
game.addChild(movingWall1);
// Horizontal movement
tween(movingWall1, {
x: 900
}, {
duration: 3000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
x: 600
}, {
duration: 3000,
easing: tween.linear,
onFinish: function onFinish() {
// Loop the movement
tween(movingWall1, {
x: 900
}, {
duration: 3000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
x: 600
}, {
duration: 3000,
easing: tween.linear
});
}
});
}
});
}
});
var movingWall2 = new Wall();
movingWall2.x = 1100;
movingWall2.y = 950;
movingWall2.scaleX = 1.5;
walls.push(movingWall2);
game.addChild(movingWall2);
// Vertical movement
tween(movingWall2, {
y: 1150
}, {
duration: 2500,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall2, {
y: 950
}, {
duration: 2500,
easing: tween.linear,
onFinish: function onFinish() {
// Loop the movement
tween(movingWall2, {
y: 1150
}, {
duration: 2500,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall2, {
y: 950
}, {
duration: 2500,
easing: tween.linear
});
}
});
}
});
}
});
var trampoline1 = new Trampoline();
trampoline1.x = 550;
trampoline1.y = 1300;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 850;
trampoline2.y = 1000;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 1150;
trampoline3.y = 900;
trampolines.push(trampoline3);
game.addChild(trampoline3);
finishPos.y = 500;
finishFlag.y = finishPos.y + 50;
instructionText.setText('Ultimate challenge! Engine failed! Tap car to push!');
} else if (level === 20) {
// Final boss level - completely restructured with moving elements
var wall1 = new Wall();
wall1.x = 400;
wall1.y = 1100;
wall1.scaleX = 1.5;
walls.push(wall1);
game.addChild(wall1);
var wall2 = new Wall();
wall2.x = 700;
wall2.y = 900;
wall2.scaleY = 2;
walls.push(wall2);
game.addChild(wall2);
var wall3 = new Wall();
wall3.x = 1000;
wall3.y = 1300;
wall3.rotation = Math.PI / 4;
wall3.scaleX = 2;
walls.push(wall3);
game.addChild(wall3);
var wall4 = new Wall();
wall4.x = 1300;
wall4.y = 800;
wall4.rotation = -Math.PI / 3;
wall4.scaleX = 1.8;
walls.push(wall4);
game.addChild(wall4);
// Add three moving walls for the final level
var movingWall1 = new Wall();
movingWall1.x = 500;
movingWall1.y = 1200;
movingWall1.scaleX = 1.2;
walls.push(movingWall1);
game.addChild(movingWall1);
// Slow circular movement
var centerX1 = 500;
var centerY1 = 1200;
var radius1 = 100;
var angle1 = 0;
// Complex movement pattern
tween(movingWall1, {
x: centerX1 + radius1
}, {
duration: 2000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
y: centerY1 + radius1
}, {
duration: 2000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
x: centerX1 - radius1
}, {
duration: 2000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall1, {
y: centerY1 - radius1
}, {
duration: 2000,
easing: tween.linear,
onFinish: function onFinish() {
// Loop back to start
tween(movingWall1, {
x: centerX1,
y: centerY1
}, {
duration: 2000,
easing: tween.linear
});
}
});
}
});
}
});
}
});
var movingWall2 = new Wall();
movingWall2.x = 900;
movingWall2.y = 1000;
movingWall2.scaleY = 2;
walls.push(movingWall2);
game.addChild(movingWall2);
// Diagonal movement
tween(movingWall2, {
x: 1200,
y: 1200
}, {
duration: 3000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall2, {
x: 900,
y: 1000
}, {
duration: 3000,
easing: tween.linear,
onFinish: function onFinish() {
// Loop the movement
tween(movingWall2, {
x: 1200,
y: 1200
}, {
duration: 3000,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall2, {
x: 900,
y: 1000
}, {
duration: 3000,
easing: tween.linear
});
}
});
}
});
}
});
var movingWall3 = new Wall();
movingWall3.x = 1400;
movingWall3.y = 1100;
movingWall3.scaleX = 1.5;
movingWall3.rotation = Math.PI / 6;
walls.push(movingWall3);
game.addChild(movingWall3);
// Vertical oscillation
tween(movingWall3, {
y: 1300
}, {
duration: 2500,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall3, {
y: 900
}, {
duration: 2500,
easing: tween.linear,
onFinish: function onFinish() {
// Loop the movement
tween(movingWall3, {
y: 1300
}, {
duration: 2500,
easing: tween.linear,
onFinish: function onFinish() {
tween(movingWall3, {
y: 900
}, {
duration: 2500,
easing: tween.linear
});
}
});
}
});
}
});
// Add strategic trampolines
var trampoline1 = new Trampoline();
trampoline1.x = 350;
trampoline1.y = 1300;
trampolines.push(trampoline1);
game.addChild(trampoline1);
var trampoline2 = new Trampoline();
trampoline2.x = 600;
trampoline2.y = 1050;
trampolines.push(trampoline2);
game.addChild(trampoline2);
var trampoline3 = new Trampoline();
trampoline3.x = 850;
trampoline3.y = 750;
trampolines.push(trampoline3);
game.addChild(trampoline3);
var trampoline4 = new Trampoline();
trampoline4.x = 1150;
trampoline4.y = 1050;
trampolines.push(trampoline4);
game.addChild(trampoline4);
var trampoline5 = new Trampoline();
trampoline5.x = 1500;
trampoline5.y = 650;
trampolines.push(trampoline5);
game.addChild(trampoline5);
finishPos.y = 400;
finishFlag.y = finishPos.y + 50;
instructionText.setText('FINAL BOSS! Navigate moving walls! Master all skills!');
}
// Create car
car = new Car();
car.x = startPos.x;
car.y = startPos.y;
car.engineWorking = false; // All levels now require manual control
car.setVelocity(0, 0); // No automatic movement
car.invulnerabilityTimer = 3000; // 3 seconds of invulnerability
game.addChild(car);
// Apply visual effect to show invulnerability
tween(car, {
alpha: 0.5
}, {
duration: 200,
easing: tween.linear,
onFinish: function onFinish() {
tween(car, {
alpha: 1
}, {
duration: 200,
easing: tween.linear,
onFinish: function onFinish() {
// Continue flashing until invulnerability ends
if (car.invulnerabilityTimer > 0) {
tween(car, {
alpha: 0.5
}, {
duration: 200,
easing: tween.linear,
onFinish: function onFinish() {
tween(car, {
alpha: 1
}, {
duration: 200,
easing: tween.linear
});
}
});
}
}
});
}
});
levelText.setText('Level ' + level);
// Create start button
if (startButton) startButton.destroy();
if (startButtonText) startButtonText.destroy();
startButton = game.addChild(LK.getAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 1366
}));
startButtonText = new Text2('START', {
size: 40,
fill: 0xffffff
});
startButtonText.anchor.set(0.5, 0.5);
startButtonText.x = 150;
startButtonText.y = 1366;
game.addChild(startButtonText);
// Create refresh button
if (refreshButton) refreshButton.destroy();
if (refreshButtonText) refreshButtonText.destroy();
refreshButton = game.addChild(LK.getAsset('refreshButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 1450
}));
refreshButtonText = new Text2('REFRESH', {
size: 35,
fill: 0xffffff
});
refreshButtonText.anchor.set(0.5, 0.5);
refreshButtonText.x = 150;
refreshButtonText.y = 1450;
game.addChild(refreshButtonText);
// Create reset button in top right corner
if (resetButton) resetButton.destroy();
if (resetButtonText) resetButtonText.destroy();
resetButton = game.addChild(LK.getAsset('resetButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1948,
y: 100
}));
resetButtonText = new Text2('RESET', {
size: 30,
fill: 0xffffff
});
resetButtonText.anchor.set(0.5, 0.5);
resetButtonText.x = 1948;
resetButtonText.y = 100;
game.addChild(resetButtonText);
// Create back button next to level text
if (backButton) backButton.destroy();
if (backButtonText) backButtonText.destroy();
backButton = game.addChild(LK.getAsset('backButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 320,
y: 100
}));
backButtonText = new Text2('BACK', {
size: 30,
fill: 0xffffff
});
backButtonText.anchor.set(0.5, 0.5);
backButtonText.x = 320;
backButtonText.y = 100;
game.addChild(backButtonText);
// Create pedal button for all levels
if (pedalButton) pedalButton.destroy();
if (pedalButtonText) pedalButtonText.destroy();
pedalButton = game.addChild(LK.getAsset('pedal', {
anchorX: 0.5,
anchorY: 0.5,
x: 1900,
y: 2600,
scaleX: 2,
scaleY: 2
}));
pedalButtonText = new Text2('PEDAL', {
size: 30,
fill: 0xffffff
});
pedalButtonText.anchor.set(0.5, 0.5);
pedalButtonText.x = 1900;
pedalButtonText.y = 2600;
game.addChild(pedalButtonText);
// Create brake button for all levels
if (brakeButton) brakeButton.destroy();
if (brakeButtonText) brakeButtonText.destroy();
brakeButton = game.addChild(LK.getAsset('brake', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 2600,
scaleX: 2,
scaleY: 2
}));
brakeButtonText = new Text2('BRAKE', {
size: 30,
fill: 0xffffff
});
brakeButtonText.anchor.set(0.5, 0.5);
brakeButtonText.x = 150;
brakeButtonText.y = 2600;
game.addChild(brakeButtonText);
}
function checkLineCollision(line1Start, line1End, line2Start, line2End) {
var x1 = line1Start.x;
var y1 = line1Start.y;
var x2 = line1End.x;
var y2 = line1End.y;
var x3 = line2Start.x;
var y3 = line2Start.y;
var x4 = line2End.x;
var y4 = line2End.y;
var denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
if (Math.abs(denom) < 0.0001) return null;
var t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / denom;
var u = -((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)) / denom;
if (t >= 0 && t <= 1 && u >= 0 && u <= 1) {
return {
x: x1 + t * (x2 - x1),
y: y1 + t * (y2 - y1)
};
}
return null;
}
function createCarDestructionEffect() {
if (!car) return;
// Stop car movement
car.velocityX = 0;
car.velocityY = 0;
car.engineWorking = false;
// Create multiple car fragments for explosion effect
var fragments = [];
for (var i = 0; i < 8; i++) {
var fragment = game.addChild(LK.getAsset('car', {
anchorX: 0.5,
anchorY: 0.5,
x: car.x,
y: car.y,
scaleX: 0.3,
scaleY: 0.3,
tint: 0xff0000
}));
fragments.push(fragment);
// Random explosion direction
var angle = Math.PI * 2 * i / 8;
var distance = 100 + Math.random() * 100;
var targetX = car.x + Math.cos(angle) * distance;
var targetY = car.y + Math.sin(angle) * distance;
// Animate fragment explosion
tween(fragment, {
x: targetX,
y: targetY,
rotation: Math.random() * Math.PI * 4,
alpha: 0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
fragment.destroy();
}
});
// Scale animation
tween(fragment.scale, {
x: 0,
y: 0
}, {
duration: 800,
easing: tween.easeIn
});
}
// Hide original car and restart level after animation
car.alpha = 0;
LK.setTimeout(function () {
setupLevel(currentLevel);
}, 1000);
}
function handleCarPhysics() {
if (!car || !drawnLine || levelComplete || !carCanMove || !gameStarted) return;
// Check invulnerability timer (3 seconds at start)
if (car.invulnerabilityTimer > 0) {
car.invulnerabilityTimer -= 16.67; // Approximately 1 frame at 60fps
return; // Skip all collision checks while invulnerable
}
var carBottom = {
x: car.x,
y: car.y + 20
};
// Check collision with all drawn lines
var onLine = false;
var closestSegment = null;
var closestDistance = Infinity;
var closestCollision = null;
for (var lineIndex = 0; lineIndex < drawnLines.length; lineIndex++) {
var segments = drawnLines[lineIndex].getSegments();
for (var i = 0; i < segments.length; i++) {
var segment = segments[i];
var carRay = {
start: {
x: car.x,
y: car.y
},
end: {
x: car.x,
y: car.y + 30
}
};
var collision = checkLineCollision(carRay.start, carRay.end, segment.start, segment.end);
if (collision) {
var distance = Math.abs(collision.y - car.y);
if (distance < closestDistance) {
closestDistance = distance;
closestSegment = segment;
closestCollision = collision;
onLine = true;
}
}
}
}
// If car is on a line, constrain it to follow the path
if (onLine && closestSegment && closestCollision) {
car.y = closestCollision.y - 20;
car.velocityY = 0;
var dx = closestSegment.end.x - closestSegment.start.x;
var dy = closestSegment.end.y - closestSegment.start.y;
var angle = Math.atan2(dy, dx);
// Constrain car movement to follow the line direction
var lineLength = Math.sqrt(dx * dx + dy * dy);
var normalizedDx = dx / lineLength;
var normalizedDy = dy / lineLength;
// Check if the line is too steep (near vertical)
var absoluteAngle = Math.abs(angle);
var isNearVertical = absoluteAngle > Math.PI * 0.4 && absoluteAngle < Math.PI * 0.6 || absoluteAngle > Math.PI * 1.4 && absoluteAngle < Math.PI * 1.6;
// For steep angles, maintain minimum horizontal movement to prevent getting stuck
if (isNearVertical) {
// Ensure car maintains some horizontal velocity to keep moving along steep paths
var minHorizontalVel = 0.5;
if (Math.abs(car.velocityX) < minHorizontalVel) {
car.velocityX = car.velocityX >= 0 ? minHorizontalVel : -minHorizontalVel;
}
}
// Project car velocity onto the line direction
var projectionMagnitude = car.velocityX * normalizedDx + car.velocityY * normalizedDy;
car.velocityX = projectionMagnitude * normalizedDx;
car.velocityY = projectionMagnitude * normalizedDy;
// Apply slope physics with reduced intensity for steep angles
var slopeIntensity = isNearVertical ? 0.1 : 0.2;
var slopeAcceleration = Math.sin(angle) * slopeIntensity;
car.velocityX += Math.cos(angle) * slopeAcceleration;
car.velocityY += Math.sin(angle) * slopeAcceleration;
// Apply general friction
var frictionFactor = 0.98;
if (Math.sin(angle) > 0) {
// Going downhill - less friction
frictionFactor = 0.995;
} else if (Math.sin(angle) < 0) {
// Going uphill - more friction, but less for steep angles to prevent stalling
frictionFactor = isNearVertical ? 0.97 : 0.96;
}
car.velocityX *= frictionFactor;
car.velocityY *= frictionFactor;
// Limit rotation angle to prevent completely vertical orientation
var maxRotation = Math.PI * 0.45; // 45 degrees max
if (Math.abs(angle) > maxRotation && Math.abs(angle) < Math.PI - maxRotation) {
car.rotation = angle > 0 ? maxRotation : -maxRotation;
} else if (Math.abs(angle) > Math.PI + maxRotation && Math.abs(angle) < 2 * Math.PI - maxRotation) {
car.rotation = angle > Math.PI ? Math.PI + maxRotation : Math.PI - maxRotation;
} else {
car.rotation = angle;
}
}
car.onGround = onLine;
// Check collision with trampolines
for (var i = 0; i < trampolines.length; i++) {
if (car.intersects(trampolines[i])) {
car.velocityY = -7.5; // Reduced from -15 to half
trampolines[i].bounce();
LK.getSound('bounce').play();
// Skip wall collision check this frame to prevent explosion
return;
}
}
// Check if car reached finish
var distToFinish = Math.sqrt(Math.pow(car.x - finishPos.x, 2) + Math.pow(car.y - finishPos.y, 2));
if (distToFinish < 100) {
levelComplete = true;
LK.getSound('success').play();
currentLevel++;
storage.currentLevel = currentLevel;
if (currentLevel > maxLevel) {
LK.setScore(100);
LK.showYouWin();
} else {
LK.setTimeout(function () {
setupLevel(currentLevel);
}, 1500);
}
}
// Check collision with walls - only trigger when car actually touches wall
for (var i = 0; i < walls.length; i++) {
var wall = walls[i];
// Get wall bounds
var wallLeft = wall.x - wall.width * wall.scaleX / 2;
var wallRight = wall.x + wall.width * wall.scaleX / 2;
var wallTop = wall.y - wall.height * wall.scaleY / 2;
var wallBottom = wall.y + wall.height * wall.scaleY / 2;
// Get car bounds
var carLeft = car.x - 40;
var carRight = car.x + 40;
var carTop = car.y - 20;
var carBottom = car.y + 20;
// Check if car is actually touching the wall (not just near it)
var touchingHorizontally = carRight >= wallLeft && carLeft <= wallRight;
var touchingVertically = carBottom >= wallTop && carTop <= wallBottom;
if (touchingHorizontally && touchingVertically) {
// Car is actually touching the wall - create destruction effect
createCarDestructionEffect();
return; // Exit early to prevent further physics
}
}
// Check if car fell off screen
if (car.y > 2732) {
setupLevel(currentLevel);
}
}
game.down = function (x, y, obj) {
if (levelComplete) return;
// Check if start button clicked
if (startButton && Math.abs(x - startButton.x) < 75 && Math.abs(y - startButton.y) < 30) {
// Only start if we have drawn at least one line
if (drawnLines.length > 0 && !gameStarted) {
gameStarted = true;
carCanMove = true;
startButton.tint = 0x888888;
}
return;
}
// Check if refresh button clicked
if (refreshButton && Math.abs(x - refreshButton.x) < 75 && Math.abs(y - refreshButton.y) < 30) {
// Reset current level
setupLevel(currentLevel);
return;
}
// Check if reset button clicked
if (resetButton && Math.abs(x - resetButton.x) < 60 && Math.abs(y - resetButton.y) < 25) {
// Reset everything - go back to level 1
currentLevel = 1;
storage.currentLevel = 1;
setupLevel(currentLevel);
return;
}
// Check if back button clicked
if (backButton && Math.abs(x - 320) < 60 && Math.abs(y - backButton.y) < 25) {
// Go back to previous level if not at level 1
if (currentLevel > 1) {
currentLevel--;
storage.currentLevel = currentLevel;
setupLevel(currentLevel);
}
return;
}
// Check if pedal button clicked for all levels
if (pedalButton && gameStarted && Math.abs(x - pedalButton.x) < 120 && Math.abs(y - pedalButton.y) < 80) {
pedalButtonPressed = true;
pedalAcceleration = 0.5; // Start with slow acceleration
return;
}
// Check if brake button clicked for all levels
if (brakeButton && gameStarted && Math.abs(x - brakeButton.x) < 120 && Math.abs(y - brakeButton.y) < 80) {
brakeButtonPressed = true;
brakeAcceleration = 0.5; // Start with slow acceleration
return;
}
// Check if starting from behind the car and haven't reached line limit
if (x < car.x - 50 && !gameStarted && currentLineCount < maxLines) {
isDrawing = true;
drawnLine = new DrawnLine();
game.addChild(drawnLine);
drawnLine.addPoint(x, y);
}
};
game.move = function (x, y, obj) {
if (isDrawing && drawnLine) {
drawnLine.addPoint(x, y);
}
};
game.up = function (x, y, obj) {
if (isDrawing && drawnLine) {
// Don't automatically allow car to move - wait for start button
// Store the completed line and increment counter
drawnLines.push(drawnLine);
currentLineCount++;
// Update line counter display
if (game.lineCounterText) {
game.lineCounterText.setText('Lines: ' + (maxLines - currentLineCount) + '/' + maxLines);
}
}
// Reset brake and pedal button states when mouse/touch is released
brakeButtonPressed = false;
brakeAcceleration = 0;
pedalButtonPressed = false;
pedalAcceleration = 0;
isDrawing = false;
};
game.update = function () {
// Handle brake button progressive acceleration
if (brakeButtonPressed && gameStarted && car) {
// Gradually increase brake acceleration while button is held
if (brakeAcceleration < maxBrakeAcceleration) {
brakeAcceleration += brakeAccelerationIncrement;
}
// Apply reverse movement with current acceleration
car.velocityX -= brakeAcceleration;
car.velocityY -= brakeAcceleration * 0.5; // Small upward component
}
// Handle pedal button progressive acceleration
if (pedalButtonPressed && gameStarted && car) {
// Gradually increase pedal acceleration while button is held
if (pedalAcceleration < maxPedalAcceleration) {
pedalAcceleration += pedalAccelerationIncrement;
}
// Apply forward movement with current acceleration
car.velocityX += pedalAcceleration;
car.velocityY -= pedalAcceleration * 0.4; // Small upward component
}
handleCarPhysics();
// Move trampolines if they have movement properties
for (var i = 0; i < trampolines.length; i++) {
var trampoline = trampolines[i];
if (trampoline.moveDirection !== undefined) {
trampoline.x += trampoline.moveDirection * trampoline.moveSpeed;
// Bounce off boundaries
if (trampoline.x <= trampoline.minX || trampoline.x >= trampoline.maxX) {
trampoline.moveDirection *= -1;
}
}
}
// Create smoke particles when car is moving
if (car && gameStarted && carCanMove && (Math.abs(car.velocityX) > 0.5 || Math.abs(car.velocityY) > 0.5)) {
smokeTimer++;
if (smokeTimer % 4 === 0) {
// Create smoke every 4 frames
var smoke = new SmokeParticle();
// Position smoke behind the car based on its rotation
var offsetX = -Math.cos(car.rotation) * 40;
var offsetY = -Math.sin(car.rotation) * 40;
smoke.init(car.x + offsetX, car.y + offsetY);
game.addChild(smoke);
smokeParticles.push(smoke);
}
}
// Clean up old smoke particles
for (var i = smokeParticles.length - 1; i >= 0; i--) {
if (smokeParticles[i].alpha <= 0) {
smokeParticles[i].destroy();
smokeParticles.splice(i, 1);
}
}
};
// Initialize first level
setupLevel(currentLevel); ===================================================================
--- original.js
+++ change.js
@@ -1372,9 +1372,44 @@
car.x = startPos.x;
car.y = startPos.y;
car.engineWorking = false; // All levels now require manual control
car.setVelocity(0, 0); // No automatic movement
+ car.invulnerabilityTimer = 3000; // 3 seconds of invulnerability
game.addChild(car);
+ // Apply visual effect to show invulnerability
+ tween(car, {
+ alpha: 0.5
+ }, {
+ duration: 200,
+ easing: tween.linear,
+ onFinish: function onFinish() {
+ tween(car, {
+ alpha: 1
+ }, {
+ duration: 200,
+ easing: tween.linear,
+ onFinish: function onFinish() {
+ // Continue flashing until invulnerability ends
+ if (car.invulnerabilityTimer > 0) {
+ tween(car, {
+ alpha: 0.5
+ }, {
+ duration: 200,
+ easing: tween.linear,
+ onFinish: function onFinish() {
+ tween(car, {
+ alpha: 1
+ }, {
+ duration: 200,
+ easing: tween.linear
+ });
+ }
+ });
+ }
+ }
+ });
+ }
+ });
levelText.setText('Level ' + level);
// Create start button
if (startButton) startButton.destroy();
if (startButtonText) startButtonText.destroy();
@@ -1556,8 +1591,13 @@
}, 1000);
}
function handleCarPhysics() {
if (!car || !drawnLine || levelComplete || !carCanMove || !gameStarted) return;
+ // Check invulnerability timer (3 seconds at start)
+ if (car.invulnerabilityTimer > 0) {
+ car.invulnerabilityTimer -= 16.67; // Approximately 1 frame at 60fps
+ return; // Skip all collision checks while invulnerable
+ }
var carBottom = {
x: car.x,
y: car.y + 20
};
Bitiş bayrağı, yazısız, 3d, gerçekçi. In-Game asset. 2d. High contrast. No shadows
araba gaz pedalı, yazısız, 3d, gerçekçi. In-Game asset. 2d. High contrast. No shadows. In-Game asset. 2d. High contrast. No shadows
araba, yazısız, 3d, gerçekçi, yandan görünüm, In-Game asset. 2d. High contrast. No shadows. In-Game asset. 2d. High contrast. No shadows
ateş, 3d, yazısız. In-Game asset. 2d. High contrast. No shadows
water, 3d, yazısız. In-Game asset. 2d. High contrast. No shadows
wall, 3d, yazısız. In-Game asset. 2d. High contrast. No shadows
trampoline, 3d, yazısız. In-Game asset. 2d. High contrast. No shadows