User prompt
The faster we are, the faster our speed appears and the speed of the deer decreases considerably ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Slow down the deer
User prompt
Add a speedometer and my speed is 100 and the deer speed is 80 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make everything a little bigger ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Have someone in the truck
User prompt
Decrease the speed of the deer
User prompt
Speed up the truck as much as I can catch the deer
User prompt
Make truck speed 20
User prompt
Increase the speed of the truck by 2
User prompt
Make Deer's speed 2 times
User prompt
If deer Touch the black Barrier, let's teleport down (Deer and truck) ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Don't let the black barrier move and put the barrier at the end of the road
User prompt
When we reach the top, add something black, and when we deer Touched to that black thing, let's teleport to the bottom (Truck and deer) ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Something still holds us back. Remove it
User prompt
When we reach the top, something stops us, remove it
User prompt
When Deer reaches the top, let's both go down again
User prompt
Let's be below. Let the deer be in front of us In other words, let us be at the bottom, let the room be in front of us, but not at the top, let it be in front of us
User prompt
End of the road = top
User prompt
If the deer reaches the end of the road, let him go to the continuation of the road and we will go there
User prompt
Target 0, only 1 deer, and the room escapes. Don't go to random places
User prompt
Let's not control the truck, let it go on the road, let it accelerate as we click on the screen
User prompt
If we go a path,deer let it teleport there ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
When you get to the end of the road, let there be a road again and the deer will continue to run away
User prompt
Let there be no trees, and let us be at the bottom of the road, and the deer may be above us, and may it perceive us and flee
User prompt
Let there be a road, let that road be long, and let the deer escape from us
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Deer = Container.expand(function () {
var self = Container.call(this);
var deerGraphics = self.attachAsset('deer', {
anchorX: 0.5,
anchorY: 0.5
});
self.baseSpeed = 3;
self.currentSpeed = self.baseSpeed;
self.directionX = 1;
self.directionY = 0;
self.changeDirectionTimer = 0;
self.evasiveness = 1;
self.update = function () {
// Calculate distance to truck for perception
var distanceToTruck = Math.sqrt(Math.pow(truck.x - self.x, 2) + Math.pow(truck.y - self.y, 2));
var perceptionRadius = 300 + self.evasiveness * 50;
// If truck is within perception range, flee
if (distanceToTruck < perceptionRadius) {
// Calculate direction away from truck
var fleeX = self.x - truck.x;
var fleeY = self.y - truck.y;
// Normalize flee direction
var fleeLength = Math.sqrt(fleeX * fleeX + fleeY * fleeY);
if (fleeLength > 0) {
fleeX = fleeX / fleeLength;
fleeY = fleeY / fleeLength;
}
// Set direction to flee from truck
self.directionX = fleeX;
self.directionY = fleeY;
// Increase speed when fleeing
self.currentSpeed = self.baseSpeed + self.evasiveness * 2;
} else {
// Normal behavior when truck is far - move straight down the road
self.directionX = 0; // Stay centered on road
self.directionY = 1; // Move down the road
self.currentSpeed = self.baseSpeed + self.evasiveness * 1.5;
}
// Move deer
self.x += self.directionX * self.currentSpeed;
self.y += self.directionY * self.currentSpeed;
// Keep deer on road with preference for road boundaries
var roadCenterX = 1024;
var roadWidth = 250;
var roadLeft = roadCenterX - roadWidth / 2;
var roadRight = roadCenterX + roadWidth / 2;
// Boundary check with road preference
if (self.x < roadLeft - 50) {
self.x = roadLeft - 50;
self.directionX = Math.abs(self.directionX);
}
if (self.x > roadRight + 50) {
self.x = roadRight + 50;
self.directionX = -Math.abs(self.directionX);
}
if (self.y < 100) {
self.y = 100;
self.directionY = Math.abs(self.directionY);
}
// Allow deer to continue past the top
if (self.y < 100) {
self.y = 100;
self.directionY = Math.abs(self.directionY);
}
// Bias deer movement towards staying on road
if (self.x < roadLeft || self.x > roadRight) {
// If off road, guide back to road
if (self.x < roadLeft) {
self.directionX += 0.1;
} else {
self.directionX -= 0.1;
}
}
};
self.increaseEvasiveness = function () {
self.evasiveness += 0.5;
self.currentSpeed = self.baseSpeed + self.evasiveness * 1.5;
};
self.escape = function () {
// Deer escapes by running down the road
var roadCenterX = 1024;
// Position deer at center of road without randomness
self.x = roadCenterX;
// Move further down the road by fixed amount
self.y = self.y + 400;
// Set direction to run straight down the road
self.directionX = 0; // No horizontal movement
self.directionY = 1; // Moving down the road
// Flash effect when escaping
LK.effects.flashObject(self, 0xffff00, 500);
};
self.teleport = function () {
// Store original position for tween effect
var originalAlpha = self.alpha;
// Fade out effect
tween(self, {
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Teleport to new position ahead of truck on road
var roadCenterX = 1024;
self.x = roadCenterX;
self.y = truck.y - 600; // Position deer ahead of truck, not at top
// Reset direction to move straight down road
self.directionX = 0;
self.directionY = 1;
// Fade back in with flash effect
tween(self, {
alpha: originalAlpha
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
LK.effects.flashObject(self, 0x00ffff, 400);
}
});
}
});
};
return self;
});
var Road = Container.expand(function () {
var self = Container.call(this);
var roadGraphics = self.attachAsset('road', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Truck = Container.expand(function () {
var self = Container.call(this);
var truckGraphics = self.attachAsset('truck', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x228b22
});
/****
* Game Code
****/
// Game variables
var truck;
var deer;
var roads = [];
var lastIntersecting = false;
var hitCount = 0;
var targetScore = 0;
// Create the long road system
for (var r = 0; r < 7; r++) {
var road = game.addChild(new Road());
road.x = 1024; // Center horizontally
road.y = r * 2732;
roads.push(road);
}
// Change background to grass
game.setBackgroundColor(0x228b22);
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create target display
var targetTxt = new Text2('Target: ' + targetScore, {
size: 60,
fill: 0xFFFF00
});
targetTxt.anchor.set(1, 0);
targetTxt.x = -20;
targetTxt.y = 100;
LK.gui.topRight.addChild(targetTxt);
// Initialize truck at bottom of road
truck = game.addChild(new Truck());
truck.x = 1024;
truck.y = 2600;
// Initialize deer in front of truck on road
deer = game.addChild(new Deer());
deer.x = 1024;
deer.y = 2200; // Position deer in front of truck but not too far ahead
// Touch controls for acceleration
var truckSpeed = 2;
var maxSpeed = 8;
var isAccelerating = false;
game.down = function (x, y, obj) {
isAccelerating = true;
};
game.up = function (x, y, obj) {
isAccelerating = false;
};
// Main game loop
game.update = function () {
// Handle truck acceleration and movement
if (isAccelerating && truckSpeed < maxSpeed) {
truckSpeed += 0.2;
} else if (!isAccelerating && truckSpeed > 2) {
truckSpeed -= 0.1;
}
// Move truck forward on road automatically
truck.y -= truckSpeed;
// Keep truck within road bounds horizontally
var roadCenterX = 1024;
var roadWidth = 250;
var roadLeft = roadCenterX - roadWidth / 2;
var roadRight = roadCenterX + roadWidth / 2;
if (truck.x < roadLeft) truck.x = roadLeft;
if (truck.x > roadRight) truck.x = roadRight;
// Allow truck to continue past the top
if (truck.y < 100) {
// Just keep the truck at the boundary instead of resetting
truck.y = 100;
}
// Maintain distance behind deer when deer teleports
if (deer.y < truck.y - 1000) {
// Deer has moved far ahead, adjust truck position to maintain chase
truck.y = deer.y + 400; // Keep truck behind deer at reasonable distance
truck.x = 1024; // Center truck on road
}
// Check collision between truck and deer
var currentIntersecting = truck.intersects(deer);
if (!lastIntersecting && currentIntersecting) {
// Hit detected!
hitCount++;
LK.setScore(hitCount);
scoreTxt.setText('Score: ' + hitCount);
// Play hit sound
LK.getSound('hit').play();
// Flash screen briefly
LK.effects.flashScreen(0xff0000, 300);
// Make deer more evasive
deer.increaseEvasiveness();
// Deer escapes to new position
deer.escape();
// Play escape sound
LK.getSound('escape').play();
// Check win condition
if (hitCount >= targetScore) {
LK.showYouWin();
}
}
lastIntersecting = currentIntersecting;
// Check if deer is approaching the end of the road and add more road segments
var lastRoad = roads[roads.length - 1];
var distanceToEnd = lastRoad.y + 1366 - deer.y; // Half road height from deer to road end
if (distanceToEnd < 1000) {
// When deer is within 1000 pixels of road end
// Add new road segments ahead
for (var i = 0; i < 3; i++) {
var newRoad = game.addChild(new Road());
newRoad.x = 1024; // Center horizontally
newRoad.y = roads[roads.length - 1].y + 2732; // Position after last road
roads.push(newRoad);
}
}
// Remove old road segments that are far behind to prevent memory issues
for (var r = roads.length - 1; r >= 0; r--) {
if (roads[r].y < deer.y - 3000) {
// If road is 3000 pixels behind deer
roads[r].destroy();
roads.splice(r, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -64,22 +64,10 @@
if (self.y < 100) {
self.y = 100;
self.directionY = Math.abs(self.directionY);
}
- // Teleportation behavior when deer reaches end of road (top)
+ // Allow deer to continue past the top
if (self.y < 100) {
- // Both deer and truck go back down to bottom
- self.x = 1024; // Center on road
- self.y = 2200; // Reset to starting position in front of truck
- truck.x = 1024; // Center truck on road
- truck.y = 2600; // Reset truck to bottom position
- // Reset direction to move straight down road
- self.directionX = 0;
- self.directionY = 1;
- // Flash effect when resetting
- LK.effects.flashObject(self, 0x00ffff, 400);
- }
- if (self.y < 100) {
self.y = 100;
self.directionY = Math.abs(self.directionY);
}
// Bias deer movement towards staying on road
@@ -243,11 +231,12 @@
var roadLeft = roadCenterX - roadWidth / 2;
var roadRight = roadCenterX + roadWidth / 2;
if (truck.x < roadLeft) truck.x = roadLeft;
if (truck.x > roadRight) truck.x = roadRight;
- // Reset truck position if it goes too far up
+ // Allow truck to continue past the top
if (truck.y < 100) {
- truck.y = 2600;
+ // Just keep the truck at the boundary instead of resetting
+ truck.y = 100;
}
// Maintain distance behind deer when deer teleports
if (deer.y < truck.y - 1000) {
// Deer has moved far ahead, adjust truck position to maintain chase