User prompt
make line much slower
User prompt
its all foult. make code all again
User prompt
there is no runner on screen. make gül red. make line white
User prompt
i cant see any player on screen. make them visible
Code edit (1 edits merged)
Please save this source code
User prompt
Gül vs Lina Sprint Race
Initial prompt
a runnig game. player name character "gül" the computer player name "lina". the race takes 100 meters. when pleyer click mouse "gül" will run. hen clik mouse faster gül runs faster. when any one finish first then wins the game
/****
* Classes
****/
var Runner = Container.expand(function (assetName) {
var self = Container.call(this);
var runnerGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 0;
self.distance = 0; // Distance in meters (0-100)
self.animationTime = 0;
self.update = function () {
// Update distance based on speed
self.distance += self.speed / 60;
// Simple running animation
if (self.speed > 0) {
self.animationTime += self.speed * 0.3;
runnerGraphics.rotation = Math.sin(self.animationTime) * 0.1;
runnerGraphics.scaleY = 1 + Math.sin(self.animationTime * 2) * 0.05;
}
// Update visual position on track
self.x = 100 + self.distance * 18; // Scale distance to pixels
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var raceStarted = false;
var raceFinished = false;
var clickCount = 0;
var lastClickTime = 0;
// Create track
var track = game.addChild(LK.getAsset('track', {
anchorX: 0,
anchorY: 0.5,
x: 0,
y: 2732 / 2
}));
// Create finish line at 100 meters (1900 pixels from start)
var finishLine = game.addChild(LK.getAsset('finishLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1900,
y: 2732 / 2
}));
// Create runners
var gul = game.addChild(new Runner('gul'));
gul.y = 2732 / 2 - 60; // Lane 1
var lina = game.addChild(new Runner('lina'));
lina.y = 2732 / 2 + 60; // Lane 2
// UI Elements
var scoreText = new Text2('Gül: 0m | Lina: 0m', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var instructionText = new Text2('Click rapidly to make Gül run faster!', {
size: 50,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
instructionText.y = 80;
LK.gui.top.addChild(instructionText);
var speedText = new Text2('Speed: 0', {
size: 40,
fill: 0xFFFFFF
});
speedText.anchor.set(0.5, 0);
speedText.y = 150;
LK.gui.top.addChild(speedText);
// Event handler
game.down = function (x, y, obj) {
if (raceFinished) {
// Restart race
raceStarted = false;
raceFinished = false;
clickCount = 0;
gul.distance = 0;
lina.distance = 0;
gul.speed = 0;
lina.speed = 0;
instructionText.setText('Click rapidly to make Gül run faster!');
return;
}
if (!raceStarted) {
raceStarted = true;
instructionText.setText('Race started! Keep clicking!');
}
clickCount++;
lastClickTime = LK.ticks;
// Boost Gül's speed
gul.speed = Math.min(gul.speed + 0.8, 5.0);
};
// Main game loop
game.update = function () {
if (!raceStarted || raceFinished) {
return;
}
// Decay Gül's speed over time (must keep clicking)
gul.speed *= 0.95;
if (gul.speed < 0.1) {
gul.speed = 0;
}
// Lina runs at steady pace with some variation
lina.speed = 2.0 + Math.sin(LK.ticks * 0.05) * 0.5 + Math.random() * 0.3;
// Update distances and check for finish
if (gul.distance >= 100 && !raceFinished) {
raceFinished = true;
LK.getSound('victory').play();
instructionText.setText('Gül wins! Click to race again!');
LK.setScore(LK.getScore() + 1);
} else if (lina.distance >= 100 && !raceFinished) {
raceFinished = true;
instructionText.setText('Lina wins! Click to try again!');
}
// Update UI
var gulMeters = Math.floor(gul.distance);
var linaMeters = Math.floor(lina.distance);
scoreText.setText('Gül: ' + gulMeters + 'm | Lina: ' + linaMeters + 'm');
speedText.setText('Speed: ' + Math.floor(gul.speed * 10) + '/50');
}; ===================================================================
--- original.js
+++ change.js
@@ -1,37 +1,27 @@
/****
-* Plugins
-****/
-var tween = LK.import("@upit/tween.v1");
-
-/****
* Classes
****/
-var Runner = Container.expand(function (name, isPlayer) {
+var Runner = Container.expand(function (assetName) {
var self = Container.call(this);
- var runnerGraphics = self.attachAsset(name, {
+ var runnerGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 0;
- self.position = 0; // Position in meters (0-100)
- self.isPlayer = isPlayer || false;
- self.lastStepTime = 0;
- self.animationOffset = 0;
+ self.distance = 0; // Distance in meters (0-100)
+ self.animationTime = 0;
self.update = function () {
- // Update position based on speed
- self.position += self.speed / 60; // Convert to per-frame movement
- // Animate running motion
- self.animationOffset += self.speed * 0.5;
- runnerGraphics.rotation = Math.sin(self.animationOffset) * 0.1;
- runnerGraphics.scaleY = 1 + Math.sin(self.animationOffset * 2) * 0.05;
- // Play footstep sounds occasionally when moving
- if (self.speed > 0.1 && LK.ticks - self.lastStepTime > 20) {
- if (Math.random() < 0.3) {
- LK.getSound('footstep').play();
- self.lastStepTime = LK.ticks;
- }
+ // Update distance based on speed
+ self.distance += self.speed / 60;
+ // Simple running animation
+ if (self.speed > 0) {
+ self.animationTime += self.speed * 0.3;
+ runnerGraphics.rotation = Math.sin(self.animationTime) * 0.1;
+ runnerGraphics.scaleY = 1 + Math.sin(self.animationTime * 2) * 0.05;
}
+ // Update visual position on track
+ self.x = 100 + self.distance * 18; // Scale distance to pixels
};
return self;
});
@@ -44,164 +34,100 @@
/****
* Game Code
****/
-// Game state variables
+// Game variables
var raceStarted = false;
var raceFinished = false;
var clickCount = 0;
var lastClickTime = 0;
-var raceDistance = 100; // meters
-var cameraOffset = 0;
// Create track
var track = game.addChild(LK.getAsset('track', {
anchorX: 0,
anchorY: 0.5,
x: 0,
y: 2732 / 2
}));
-// Create lanes
-var lane1 = game.addChild(LK.getAsset('lane', {
- anchorX: 0,
- anchorY: 0.5,
- x: 0,
- y: 2732 / 2 - 50
-}));
-var lane2 = game.addChild(LK.getAsset('lane', {
- anchorX: 0,
- anchorY: 0.5,
- x: 0,
- y: 2732 / 2 + 50
-}));
-// Create finish line
+// Create finish line at 100 meters (1900 pixels from start)
var finishLine = game.addChild(LK.getAsset('finishLine', {
anchorX: 0.5,
anchorY: 0.5,
- x: 2048 * (raceDistance / 100),
- // Scale track to represent 100 meters
+ x: 1900,
y: 2732 / 2
}));
// Create runners
-var gul = game.addChild(new Runner('gul', true));
-gul.x = 200; // Move further from edge for better visibility
-gul.y = 2732 / 2 - 50; // Lane 1 position
-var lina = game.addChild(new Runner('lina', false));
-lina.x = 200; // Move further from edge for better visibility
-lina.y = 2732 / 2 + 50; // Lane 2 position
-// Create UI elements
-var distanceText = new Text2('0m / 100m', {
+var gul = game.addChild(new Runner('gul'));
+gul.y = 2732 / 2 - 60; // Lane 1
+var lina = game.addChild(new Runner('lina'));
+lina.y = 2732 / 2 + 60; // Lane 2
+// UI Elements
+var scoreText = new Text2('Gül: 0m | Lina: 0m', {
size: 60,
- fill: 0x000000
+ fill: 0xFFFFFF
});
-distanceText.anchor.set(0.5, 0);
-LK.gui.top.addChild(distanceText);
-var instructionText = new Text2('Tap rapidly to make Gül run!', {
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+var instructionText = new Text2('Click rapidly to make Gül run faster!', {
size: 50,
- fill: 0x000000
+ fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
-instructionText.y = 100;
+instructionText.y = 80;
LK.gui.top.addChild(instructionText);
-var clickSpeedText = new Text2('', {
+var speedText = new Text2('Speed: 0', {
size: 40,
- fill: 0x333333
+ fill: 0xFFFFFF
});
-clickSpeedText.anchor.set(0, 0);
-clickSpeedText.x = 20;
-clickSpeedText.y = 200;
-LK.gui.topLeft.addChild(clickSpeedText);
-// Game logic functions
-function calculateClickSpeed() {
- var currentTime = LK.ticks;
- var timeDiff = currentTime - lastClickTime;
- if (timeDiff < 30) {
- // Within half second
- return Math.min(timeDiff / 10, 3); // Max speed multiplier of 3
- }
- return 0.1; // Minimum speed
-}
-function updateCamera() {
- // Follow the leading runner
- var leadPosition = Math.max(gul.position, lina.position);
- var targetCameraX = -leadPosition * 20 + 400; // Scale and offset to keep runners visible
- // Smooth camera movement
- cameraOffset += (targetCameraX - cameraOffset) * 0.1;
- // Apply camera offset to all track elements
- track.x = cameraOffset;
- lane1.x = cameraOffset;
- lane2.x = cameraOffset;
- finishLine.x = cameraOffset + 2048 * (raceDistance / 100);
-}
-function updateRunnerPositions() {
- // Update visual positions based on race progress
- gul.x = 200 + gul.position * 20; // Scale meters to pixels with proper starting offset
- lina.x = 200 + lina.position * 20; // Scale meters to pixels with proper starting offset
-}
-function checkRaceFinish() {
- if (gul.position >= raceDistance || lina.position >= raceDistance) {
- if (!raceFinished) {
- raceFinished = true;
- if (gul.position >= raceDistance && gul.position >= lina.position) {
- // Player wins
- LK.getSound('victory').play();
- instructionText.setText('Gül Wins! Tap to race again!');
- instructionText.style.fill = "#00AA00";
- LK.setScore(LK.getScore() + 1);
- } else {
- // Computer wins
- LK.getSound('defeat').play();
- instructionText.setText('Lina Wins! Tap to try again!');
- instructionText.style.fill = "#AA0000";
- }
- }
- }
-}
-// Event handlers
+speedText.anchor.set(0.5, 0);
+speedText.y = 150;
+LK.gui.top.addChild(speedText);
+// Event handler
game.down = function (x, y, obj) {
if (raceFinished) {
// Restart race
raceStarted = false;
raceFinished = false;
clickCount = 0;
- gul.position = 0;
- lina.position = 0;
+ gul.distance = 0;
+ lina.distance = 0;
gul.speed = 0;
lina.speed = 0;
- cameraOffset = 0;
- instructionText.setText('Tap rapidly to make Gül run!');
- instructionText.style.fill = "#000000";
+ instructionText.setText('Click rapidly to make Gül run faster!');
return;
}
if (!raceStarted) {
raceStarted = true;
- instructionText.setText('Go! Go! Go!');
+ instructionText.setText('Race started! Keep clicking!');
}
clickCount++;
lastClickTime = LK.ticks;
- // Increase Gül's speed based on clicking
- var speedBoost = calculateClickSpeed();
- gul.speed = Math.min(gul.speed + speedBoost * 0.5, 4); // Max speed limit
+ // Boost Gül's speed
+ gul.speed = Math.min(gul.speed + 0.8, 5.0);
};
-// Main game update loop
+// Main game loop
game.update = function () {
if (!raceStarted || raceFinished) {
return;
}
- // Decay Gül's speed over time (player must keep clicking)
- gul.speed *= 0.98;
- gul.speed = Math.max(gul.speed, 0);
- // Computer opponent (Lina) logic - varying speed with some randomness
- var targetSpeed = 2 + Math.sin(LK.ticks * 0.02) * 0.8 + Math.random() * 0.4;
- lina.speed += (targetSpeed - lina.speed) * 0.1;
- // Update camera and positions
- updateCamera();
- updateRunnerPositions();
+ // Decay Gül's speed over time (must keep clicking)
+ gul.speed *= 0.95;
+ if (gul.speed < 0.1) {
+ gul.speed = 0;
+ }
+ // Lina runs at steady pace with some variation
+ lina.speed = 2.0 + Math.sin(LK.ticks * 0.05) * 0.5 + Math.random() * 0.3;
+ // Update distances and check for finish
+ if (gul.distance >= 100 && !raceFinished) {
+ raceFinished = true;
+ LK.getSound('victory').play();
+ instructionText.setText('Gül wins! Click to race again!');
+ LK.setScore(LK.getScore() + 1);
+ } else if (lina.distance >= 100 && !raceFinished) {
+ raceFinished = true;
+ instructionText.setText('Lina wins! Click to try again!');
+ }
// Update UI
- var gulDistance = Math.floor(gul.position);
- var linaDistance = Math.floor(lina.position);
- distanceText.setText('Gül: ' + gulDistance + 'm | Lina: ' + linaDistance + 'm');
- // Show clicking feedback
- var recentClicks = Math.floor(gul.speed * 10);
- clickSpeedText.setText('Speed: ' + recentClicks + '/10');
- // Check for race finish
- checkRaceFinish();
+ var gulMeters = Math.floor(gul.distance);
+ var linaMeters = Math.floor(lina.distance);
+ scoreText.setText('Gül: ' + gulMeters + 'm | Lina: ' + linaMeters + 'm');
+ speedText.setText('Speed: ' + Math.floor(gul.speed * 10) + '/50');
};
\ No newline at end of file