User prompt
finish
User prompt
revert back
User prompt
Please fix the bug: 'ui is not defined' in or related to this line: 'var startupTab = ui.createTab({' Line Number: 91
User prompt
Please fix the bug: 'ui is not defined' in or related to this line: 'var startupTab = ui.createTab({' Line Number: 91
User prompt
add startup tab
User prompt
Let the ticks be a little bigger
User prompt
let the ground be white
User prompt
let the ground be grass
User prompt
let the earth be the ground
Code edit (1 edits merged)
Please save this source code
User prompt
Tick Hunter: Partridge Patrol
Initial prompt
tick-hunting partridge game
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Grass = Container.expand(function () {
var self = Container.call(this);
var grassGraphics = self.attachAsset('grass', {
anchorX: 0.5,
anchorY: 1.0
});
grassGraphics.alpha = 0.6;
return self;
});
var Partridge = Container.expand(function () {
var self = Container.call(this);
var partridgeGraphics = self.attachAsset('partridge', {
anchorX: 0.5,
anchorY: 0.5
});
self.catchRadius = 50;
return self;
});
var Tick = Container.expand(function () {
var self = Container.call(this);
var tickGraphics = self.attachAsset('tick', {
anchorX: 0.5,
anchorY: 0.5
});
self.lifespan = 3000; // 3 seconds to catch
self.timeAlive = 0;
self.caught = false;
self.escaped = false;
self.update = function () {
if (self.caught || self.escaped) return;
self.timeAlive += 16.67; // ~60fps
// Gradually sink into grass (scale down and fade)
var progress = self.timeAlive / self.lifespan;
var scale = 1 - progress * 0.5;
var alpha = 1 - progress * 0.3;
tickGraphics.scaleX = Math.max(0.3, scale);
tickGraphics.scaleY = Math.max(0.3, scale);
tickGraphics.alpha = Math.max(0.4, alpha);
if (self.timeAlive >= self.lifespan) {
self.escaped = true;
escapedTicks++;
LK.getSound('escape').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x90EE90
});
/****
* Game Code
****/
// Game variables
var partridge;
var ticks = [];
var grassPatches = [];
var lives = 3;
var tickSpawnRate = 60; // frames between spawns
var maxTicks = 5;
var escapedTicks = 0;
var maxEscapedTicks = 10;
var comboCount = 0;
var comboTimer = 0;
var comboTimeLimit = 120; // 2 seconds at 60fps
// Create grass background
for (var i = 0; i < 150; i++) {
var grass = new Grass();
grass.x = Math.random() * 2048;
grass.y = Math.random() * 2732;
grassPatches.push(grass);
game.addChild(grass);
}
// Create partridge
partridge = new Partridge();
partridge.x = 1024;
partridge.y = 1366;
game.addChild(partridge);
// Create UI
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var livesTxt = new Text2('Lives: 3', {
size: 60,
fill: 0xFFFFFF
});
livesTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(livesTxt);
var comboTxt = new Text2('', {
size: 50,
fill: 0xFFD700
});
comboTxt.anchor.set(0.5, 0);
comboTxt.y = 120;
LK.gui.top.addChild(comboTxt);
// Dragging variables
var dragNode = null;
// Game functions
function spawnTick() {
if (ticks.length >= maxTicks) return;
var tick = new Tick();
tick.x = Math.random() * 1848 + 100; // Keep away from edges
tick.y = Math.random() * 2532 + 100;
ticks.push(tick);
game.addChild(tick);
}
function checkTickCatch(tick) {
var dx = partridge.x - tick.x;
var dy = partridge.y - tick.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < partridge.catchRadius && !tick.caught && !tick.escaped) {
tick.caught = true;
// Update score
var points = 10;
if (comboCount > 0) {
points += comboCount * 5; // Bonus for combo
}
LK.setScore(LK.getScore() + points);
// Update combo
comboCount++;
comboTimer = comboTimeLimit;
// Visual feedback
tween(tick, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
easing: tween.easeOut
});
LK.getSound('catch').play();
// Flash partridge green
LK.effects.flashObject(partridge, 0x00FF00, 200);
return true;
}
return false;
}
function updateUI() {
scoreTxt.setText('Score: ' + LK.getScore());
livesTxt.setText('Lives: ' + lives);
if (comboCount > 1 && comboTimer > 0) {
comboTxt.setText('Combo x' + comboCount + '!');
comboTxt.alpha = comboTimer / comboTimeLimit;
} else {
comboTxt.setText('');
}
}
function increaseDifficulty() {
var score = LK.getScore();
// Increase spawn rate
if (score > 100) tickSpawnRate = Math.max(30, 60 - Math.floor(score / 100) * 5);
// Increase max ticks
if (score > 200) maxTicks = Math.min(10, 5 + Math.floor(score / 200));
// Reduce tick lifespan
if (score > 300) {
var newLifespan = Math.max(1500, 3000 - Math.floor(score / 300) * 200);
// Apply to new ticks only
}
}
// Event handlers
game.down = function (x, y, obj) {
dragNode = partridge;
partridge.x = x;
partridge.y = y;
};
game.move = function (x, y, obj) {
if (dragNode) {
partridge.x = x;
partridge.y = y;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main game loop
game.update = function () {
// Spawn ticks
if (LK.ticks % tickSpawnRate == 0) {
spawnTick();
}
// Update ticks and check catches
for (var i = ticks.length - 1; i >= 0; i--) {
var tick = ticks[i];
if (tick.caught || tick.escaped) {
// Remove tick after delay
if (tick.caught && tick.alpha <= 0) {
tick.destroy();
ticks.splice(i, 1);
} else if (tick.escaped) {
tick.destroy();
ticks.splice(i, 1);
}
continue;
}
// Check if partridge caught tick
checkTickCatch(tick);
}
// Update combo timer
if (comboTimer > 0) {
comboTimer--;
if (comboTimer <= 0) {
comboCount = 0;
}
}
// Check game over condition
if (escapedTicks >= maxEscapedTicks) {
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
return;
}
// Update difficulty
increaseDifficulty();
// Update UI
updateUI();
// Win condition (survive long enough)
if (LK.getScore() >= 500) {
LK.showYouWin();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,234 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Grass = Container.expand(function () {
+ var self = Container.call(this);
+ var grassGraphics = self.attachAsset('grass', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ grassGraphics.alpha = 0.6;
+ return self;
+});
+var Partridge = Container.expand(function () {
+ var self = Container.call(this);
+ var partridgeGraphics = self.attachAsset('partridge', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.catchRadius = 50;
+ return self;
+});
+var Tick = Container.expand(function () {
+ var self = Container.call(this);
+ var tickGraphics = self.attachAsset('tick', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lifespan = 3000; // 3 seconds to catch
+ self.timeAlive = 0;
+ self.caught = false;
+ self.escaped = false;
+ self.update = function () {
+ if (self.caught || self.escaped) return;
+ self.timeAlive += 16.67; // ~60fps
+ // Gradually sink into grass (scale down and fade)
+ var progress = self.timeAlive / self.lifespan;
+ var scale = 1 - progress * 0.5;
+ var alpha = 1 - progress * 0.3;
+ tickGraphics.scaleX = Math.max(0.3, scale);
+ tickGraphics.scaleY = Math.max(0.3, scale);
+ tickGraphics.alpha = Math.max(0.4, alpha);
+ if (self.timeAlive >= self.lifespan) {
+ self.escaped = true;
+ escapedTicks++;
+ LK.getSound('escape').play();
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x90EE90
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var partridge;
+var ticks = [];
+var grassPatches = [];
+var lives = 3;
+var tickSpawnRate = 60; // frames between spawns
+var maxTicks = 5;
+var escapedTicks = 0;
+var maxEscapedTicks = 10;
+var comboCount = 0;
+var comboTimer = 0;
+var comboTimeLimit = 120; // 2 seconds at 60fps
+// Create grass background
+for (var i = 0; i < 150; i++) {
+ var grass = new Grass();
+ grass.x = Math.random() * 2048;
+ grass.y = Math.random() * 2732;
+ grassPatches.push(grass);
+ game.addChild(grass);
+}
+// Create partridge
+partridge = new Partridge();
+partridge.x = 1024;
+partridge.y = 1366;
+game.addChild(partridge);
+// Create UI
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var livesTxt = new Text2('Lives: 3', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+livesTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(livesTxt);
+var comboTxt = new Text2('', {
+ size: 50,
+ fill: 0xFFD700
+});
+comboTxt.anchor.set(0.5, 0);
+comboTxt.y = 120;
+LK.gui.top.addChild(comboTxt);
+// Dragging variables
+var dragNode = null;
+// Game functions
+function spawnTick() {
+ if (ticks.length >= maxTicks) return;
+ var tick = new Tick();
+ tick.x = Math.random() * 1848 + 100; // Keep away from edges
+ tick.y = Math.random() * 2532 + 100;
+ ticks.push(tick);
+ game.addChild(tick);
+}
+function checkTickCatch(tick) {
+ var dx = partridge.x - tick.x;
+ var dy = partridge.y - tick.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < partridge.catchRadius && !tick.caught && !tick.escaped) {
+ tick.caught = true;
+ // Update score
+ var points = 10;
+ if (comboCount > 0) {
+ points += comboCount * 5; // Bonus for combo
+ }
+ LK.setScore(LK.getScore() + points);
+ // Update combo
+ comboCount++;
+ comboTimer = comboTimeLimit;
+ // Visual feedback
+ tween(tick, {
+ alpha: 0,
+ scaleX: 2,
+ scaleY: 2
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ LK.getSound('catch').play();
+ // Flash partridge green
+ LK.effects.flashObject(partridge, 0x00FF00, 200);
+ return true;
+ }
+ return false;
+}
+function updateUI() {
+ scoreTxt.setText('Score: ' + LK.getScore());
+ livesTxt.setText('Lives: ' + lives);
+ if (comboCount > 1 && comboTimer > 0) {
+ comboTxt.setText('Combo x' + comboCount + '!');
+ comboTxt.alpha = comboTimer / comboTimeLimit;
+ } else {
+ comboTxt.setText('');
+ }
+}
+function increaseDifficulty() {
+ var score = LK.getScore();
+ // Increase spawn rate
+ if (score > 100) tickSpawnRate = Math.max(30, 60 - Math.floor(score / 100) * 5);
+ // Increase max ticks
+ if (score > 200) maxTicks = Math.min(10, 5 + Math.floor(score / 200));
+ // Reduce tick lifespan
+ if (score > 300) {
+ var newLifespan = Math.max(1500, 3000 - Math.floor(score / 300) * 200);
+ // Apply to new ticks only
+ }
+}
+// Event handlers
+game.down = function (x, y, obj) {
+ dragNode = partridge;
+ partridge.x = x;
+ partridge.y = y;
+};
+game.move = function (x, y, obj) {
+ if (dragNode) {
+ partridge.x = x;
+ partridge.y = y;
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+// Main game loop
+game.update = function () {
+ // Spawn ticks
+ if (LK.ticks % tickSpawnRate == 0) {
+ spawnTick();
+ }
+ // Update ticks and check catches
+ for (var i = ticks.length - 1; i >= 0; i--) {
+ var tick = ticks[i];
+ if (tick.caught || tick.escaped) {
+ // Remove tick after delay
+ if (tick.caught && tick.alpha <= 0) {
+ tick.destroy();
+ ticks.splice(i, 1);
+ } else if (tick.escaped) {
+ tick.destroy();
+ ticks.splice(i, 1);
+ }
+ continue;
+ }
+ // Check if partridge caught tick
+ checkTickCatch(tick);
+ }
+ // Update combo timer
+ if (comboTimer > 0) {
+ comboTimer--;
+ if (comboTimer <= 0) {
+ comboCount = 0;
+ }
+ }
+ // Check game over condition
+ if (escapedTicks >= maxEscapedTicks) {
+ LK.effects.flashScreen(0xFF0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ // Update difficulty
+ increaseDifficulty();
+ // Update UI
+ updateUI();
+ // Win condition (survive long enough)
+ if (LK.getScore() >= 500) {
+ LK.showYouWin();
+ }
+};
\ No newline at end of file