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);
}
// Teleportation behavior when deer reaches path boundaries
if (self.y > 2600) {
// Teleport deer to a new position on the road
self.teleport();
}
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
var roadCenterX = 1024;
self.x = roadCenterX;
self.y = 300; // Teleport to fixed position on upper part of road
// 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 higher up on road
deer = game.addChild(new Deer());
deer.x = 1024;
deer.y = 800;
// 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;
// Reset truck position if it goes too far up
if (truck.y < 100) {
truck.y = 2600;
}
// 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
@@ -38,17 +38,11 @@
self.directionY = fleeY;
// Increase speed when fleeing
self.currentSpeed = self.baseSpeed + self.evasiveness * 2;
} else {
- // Normal wandering behavior when truck is far
- self.changeDirectionTimer++;
- if (self.changeDirectionTimer > 60 / self.evasiveness) {
- self.changeDirectionTimer = 0;
- // Random direction change
- var angle = Math.random() * Math.PI * 2;
- self.directionX = Math.cos(angle);
- self.directionY = Math.sin(angle);
- }
+ // 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;
@@ -96,15 +90,14 @@
};
self.escape = function () {
// Deer escapes by running down the road
var roadCenterX = 1024;
- var roadWidth = 250;
- // Position on road with some randomness
- self.x = roadCenterX + (Math.random() - 0.5) * roadWidth;
- // Move further down the road
- self.y = Math.max(self.y + 300 + Math.random() * 200, 2500);
- // Set direction to run away down the road
- self.directionX = (Math.random() - 0.5) * 0.3; // Slight horizontal wobble
+ // 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);
};
@@ -119,14 +112,13 @@
easing: tween.easeOut,
onFinish: function onFinish() {
// Teleport to new position
var roadCenterX = 1024;
- var roadWidth = 250;
- self.x = roadCenterX + (Math.random() - 0.5) * roadWidth;
- self.y = 200 + Math.random() * 400; // Teleport to upper part of road
- // Reset direction
- self.directionX = (Math.random() - 0.5) * 0.5;
- self.directionY = Math.random() > 0.5 ? 1 : -1;
+ self.x = roadCenterX;
+ self.y = 300; // Teleport to fixed position on upper part of road
+ // Reset direction to move straight down road
+ self.directionX = 0;
+ self.directionY = 1;
// Fade back in with flash effect
tween(self, {
alpha: originalAlpha
}, {
@@ -182,9 +174,9 @@
var deer;
var roads = [];
var lastIntersecting = false;
var hitCount = 0;
-var targetScore = 10;
+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