User prompt
basladigim yere kadar yol olsun
User prompt
arabalari 2x hizlandir ve daha fazla yol olustur
Code edit (1 edits merged)
Please save this source code
User prompt
Chicken Cross - Road Rush
User prompt
tavuk ile karsidan karsiya gitme oyunu yap yoldan surekli arabalar gecsin bizde kontrol ederek gecmeye calisalim
User prompt
Please continue polishing my design document.
Initial prompt
tavuk ile karsidan karsiya gitme oyunu yap yoldan surekli arabalar gecsin bizde kontrol ederek gecmeye calisalim
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Car = Container.expand(function (direction, speed, lane) {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = direction; // 1 for right, -1 for left
self.speed = speed;
self.lane = lane;
// Position car based on direction
if (self.direction === 1) {
self.x = -60; // Start from left
} else {
self.x = 2048 + 60; // Start from right
}
self.y = 2732 - 100 - lane * 150; // Position in lane using dynamic road positioning
self.update = function () {
self.x += self.speed * self.direction;
// Remove car when it goes off screen
if (self.direction === 1 && self.x > 2048 + 100) {
self.removeFromParent = true;
} else if (self.direction === -1 && self.x < -100) {
self.removeFromParent = true;
}
};
return self;
});
var Chicken = Container.expand(function () {
var self = Container.call(this);
var chickenGraphics = self.attachAsset('chicken', {
anchorX: 0.5,
anchorY: 0.5
});
self.moveStep = 100;
self.isMoving = false;
self.targetY = 2732 - 100; // Start near bottom
self.moveForward = function () {
if (self.isMoving) return;
self.isMoving = true;
var newY = self.y - self.moveStep;
// Animate movement
tween(self, {
y: newY
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isMoving = false;
// Check if crossed a road
if (self.y < 150) {
// Crossed all roads, reset and increase score
crossedRoad();
}
}
});
LK.getSound('move').play();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x4CAF50
});
/****
* Game Code
****/
var chicken;
var cars = [];
var roads = [];
var gameSpeed = 1;
var carSpawnTimer = 0;
var carSpawnRate = 60; // frames between car spawns
var crossedRoads = 0;
// Create score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create roads
function createRoads() {
// Create roads from starting position to current position
var totalRoads = Math.max(6, Math.ceil((2732 - 100) / 150));
for (var i = 0; i < totalRoads; i++) {
var roadY = 2732 - 100 - i * 150;
if (roadY >= 0) {
var road = LK.getAsset('road', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: roadY
});
roads.push(road);
game.addChild(road);
// Add road lines
var roadLine = LK.getAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: roadY
});
game.addChild(roadLine);
}
}
}
// Create chicken
function createChicken() {
chicken = game.addChild(new Chicken());
chicken.x = 1024; // Center horizontally
chicken.y = 2732 - 100; // Start near bottom
}
// Spawn a car
function spawnCar() {
var lane = Math.floor(Math.random() * roads.length);
var direction = Math.random() > 0.5 ? 1 : -1;
var baseSpeed = (3 + Math.random() * 4) * 2; // 2x speed increase
var speed = baseSpeed * gameSpeed;
var car = new Car(direction, speed, lane);
cars.push(car);
game.addChild(car);
}
// Check collisions
function checkCollisions() {
for (var i = 0; i < cars.length; i++) {
var car = cars[i];
if (chicken.intersects(car)) {
// Game over
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
return;
}
}
}
// Handle successful road crossing
function crossedRoad() {
crossedRoads++;
LK.setScore(crossedRoads);
scoreTxt.setText(crossedRoads.toString());
// Reset chicken position
chicken.y = 2732 - 100;
// Increase difficulty
gameSpeed += 0.1;
if (carSpawnRate > 30) {
carSpawnRate -= 2;
}
// Flash screen green for success
LK.effects.flashScreen(0x00ff00, 300);
}
// Initialize game elements
createRoads();
createChicken();
// Game controls
game.down = function (x, y, obj) {
if (chicken && !chicken.isMoving) {
chicken.moveForward();
}
};
// Main game loop
game.update = function () {
// Spawn cars
carSpawnTimer++;
if (carSpawnTimer >= carSpawnRate) {
spawnCar();
carSpawnTimer = 0;
}
// Clean up cars that are off screen
for (var i = cars.length - 1; i >= 0; i--) {
var car = cars[i];
if (car.removeFromParent) {
car.destroy();
cars.splice(i, 1);
}
}
// Check collisions
checkCollisions();
}; ===================================================================
--- original.js
+++ change.js
@@ -20,9 +20,9 @@
self.x = -60; // Start from left
} else {
self.x = 2048 + 60; // Start from right
}
- self.y = 250 + lane * 150; // Position in lane
+ self.y = 2732 - 100 - lane * 150; // Position in lane using dynamic road positioning
self.update = function () {
self.x += self.speed * self.direction;
// Remove car when it goes off screen
if (self.direction === 1 && self.x > 2048 + 100) {
@@ -91,25 +91,30 @@
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create roads
function createRoads() {
- for (var i = 0; i < 6; i++) {
- var road = LK.getAsset('road', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 1024,
- y: 250 + i * 150
- });
- roads.push(road);
- game.addChild(road);
- // Add road lines
- var roadLine = LK.getAsset('roadLine', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 1024,
- y: 250 + i * 150
- });
- game.addChild(roadLine);
+ // Create roads from starting position to current position
+ var totalRoads = Math.max(6, Math.ceil((2732 - 100) / 150));
+ for (var i = 0; i < totalRoads; i++) {
+ var roadY = 2732 - 100 - i * 150;
+ if (roadY >= 0) {
+ var road = LK.getAsset('road', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: roadY
+ });
+ roads.push(road);
+ game.addChild(road);
+ // Add road lines
+ var roadLine = LK.getAsset('roadLine', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: roadY
+ });
+ game.addChild(roadLine);
+ }
}
}
// Create chicken
function createChicken() {
@@ -118,9 +123,9 @@
chicken.y = 2732 - 100; // Start near bottom
}
// Spawn a car
function spawnCar() {
- var lane = Math.floor(Math.random() * 6);
+ var lane = Math.floor(Math.random() * roads.length);
var direction = Math.random() > 0.5 ? 1 : -1;
var baseSpeed = (3 + Math.random() * 4) * 2; // 2x speed increase
var speed = baseSpeed * gameSpeed;
var car = new Car(direction, speed, lane);
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "Chicken Cross - Road Rush" and with the description "Guide a chicken across busy roads filled with speeding cars. Time your movements carefully to avoid traffic and cross safely in this classic arcade-style challenge.". No text on banner!