===================================================================
--- original.js
+++ change.js
@@ -30,18 +30,30 @@
// Method to move the runner left
self.moveLeft = function () {
if (self.lane > 0) {
self.lane--;
- self.x -= 300; // Move to the left lane
+ self.slideTo(self.x - 300); // Slide to the left lane
}
};
// Method to move the runner right
self.moveRight = function () {
if (self.lane < 2) {
self.lane++;
- self.x += 300; // Move to the right lane
+ self.slideTo(self.x + 300); // Slide to the right lane
}
};
+ // Method to slide the runner to a new x position
+ self.slideTo = function (newX) {
+ var slideSpeed = 20; // Adjust slide speed as needed
+ var slideInterval = LK.setInterval(function () {
+ if (Math.abs(self.x - newX) < slideSpeed) {
+ self.x = newX;
+ LK.clearInterval(slideInterval);
+ } else {
+ self.x += self.x < newX ? slideSpeed : -slideSpeed;
+ }
+ }, 16); // Approximately 60 FPS
+ };
// Update method for runner
self.update = function () {
// Add any continuous updates for the runner here
};