User prompt
timer will be on top. time will go up.
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'fill')' in or related to this line: 'stageTexts[i].style.fill = i === stageActiveIndex ? "#fff" : "#888";' Line Number: 355
User prompt
there will be a time on right top. and under time there will be 5 stages: Very easy, easy, medium, hard, very hard. very easy will be between times of 0:00-0:15. easy; 0:15:0:45. medium; 0:45-1:30. hard; 1:30-2:30. very hard; 2:30-end of the game.
User prompt
over time timer will go faster and spawn rate will be faster
User prompt
make spawn rate higher sometimes and sometimes make it lower
User prompt
make different variations of mobs and make some of them faster and some of them slower
Code edit (1 edits merged)
Please save this source code
User prompt
Monster Tap Frenzy
Initial prompt
Random monsters will spawn on the map or will walk in the map and my mission is to kill them by clicking on them. there will be a timer and when I kill a mob timer will add some seconds
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Monster class var Monster = Container.expand(function () { var self = Container.call(this); // Monster type: "normal", "fast", "slow" self.type = "normal"; // Attach monster asset var monsterSprite = self.attachAsset('monster', { anchorX: 0.5, anchorY: 0.5 }); // Color by type after setType is called self.updateTypeVisual = function () { if (self.type === "fast") { monsterSprite.tint = 0x3e8ecf; // blue for fast } else if (self.type === "slow") { monsterSprite.tint = 0xcfb53e; // gold for slow } else { monsterSprite.tint = 0x3ecf4c; // green for normal } }; var _oldSetType = self.setType; self.setType = function (type) { _oldSetType(type); self.updateTypeVisual(); }; // Movement speed (pixels per tick) self.speed = 0; // Movement direction (radians) self.direction = 0; // Is monster alive self.alive = true; // Set monster type and speed self.setType = function (type) { self.type = type; if (type === "fast") { // Fast monsters: 5-8 px/tick self.speed = 5 + Math.random() * 3; } else if (type === "slow") { // Slow monsters: 1-2.5 px/tick self.speed = 1 + Math.random() * 1.5; } else { // Normal monsters: 2-6 px/tick self.speed = 2 + Math.random() * 4; } }; // Set random movement self.setRandomMovement = function () { // Randomly assign type var r = Math.random(); if (r < 0.2) { self.setType("fast"); } else if (r > 0.8) { self.setType("slow"); } else { self.setType("normal"); } // Direction: 0-2PI self.direction = Math.random() * Math.PI * 2; }; // Move monster self.update = function () { if (!self.alive) return; // Move self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; // Bounce off walls // Left if (self.x - monsterSprite.width / 2 < 0) { self.x = monsterSprite.width / 2; self.direction = Math.PI - self.direction; } // Right if (self.x + monsterSprite.width / 2 > 2048) { self.x = 2048 - monsterSprite.width / 2; self.direction = Math.PI - self.direction; } // Top if (self.y - monsterSprite.height / 2 < 100) { // leave top 100px for menu self.y = 100 + monsterSprite.height / 2; self.direction = -self.direction; } // Bottom if (self.y + monsterSprite.height / 2 > 2732) { self.y = 2732 - monsterSprite.height / 2; self.direction = -self.direction; } }; // Handle tap self.down = function (x, y, obj) { if (!self.alive) return; self.alive = false; // Show hit effect var hit = LK.getAsset('monsterHit', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, scaleX: 1, scaleY: 1, alpha: 1, tint: self.type === "fast" ? 0x3e8ecf : self.type === "slow" ? 0xcfb53e : 0xff4444 }); self.addChild(hit); // Animate hit effect tween(hit, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { hit.destroy(); } }); // Animate monster fade out tween(monsterSprite, { alpha: 0 }, { duration: 200, onFinish: function onFinish() { self.destroy(); } }); // Add time and score if (self.type === "fast") { addTime(3); // fast: +3s } else if (self.type === "slow") { addTime(1); // slow: +1s } else { addTime(2); // normal: +2s } setScore(getScore() + 1); updateScoreText(); // Remove from monsters array for (var i = 0; i < monsters.length; ++i) { if (monsters[i] === self) { monsters.splice(i, 1); break; } } }; return self; }); // Tap effect class var TapEffect = Container.expand(function () { var self = Container.call(this); var tap = self.attachAsset('tapEffect', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1, alpha: 0.7 }); // Animate tween(tap, { scaleX: 2, scaleY: 2, alpha: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181c2a }); /**** * Game Code ****/ // Tap effect: yellow ellipse, 100x100 // Monster hit effect: red ellipse, 160x160 // Monster: green ellipse, 160x160 // Global variables var monsters = []; var monsterSpawnInterval = 120; // ticks between spawns (2s) var monsterSpawnIntervalTarget = 120; // target interval for smooth transitions var monsterSpawnIntervalChangeTimer = 0; // ticks until next interval change var monsterMax = 6; // max monsters on screen var timerMax = 20; // seconds to start (used for stage boundaries, not for countdown) var timer = 0; // current timer (seconds), now counts up var timerInterval = null; var timerBar = null; var timerBarBg = null; var timerText = null; var score = 0; var scoreText = null; var lastTick = 0; // Helper: get/set score function getScore() { return score; } function setScore(val) { score = val; } function updateScoreText() { scoreText.setText(score + ""); } // Helper: add time function addTime(sec) { timer += sec; if (timer > 9999) timer = 9999; updateTimerText(); updateStageDisplay(); updateTimerBar(); } // Helper: update timer text function updateTimerText() { timerText.setText(Math.floor(timer) + ""); } // Helper: update timer bar function updateTimerBar() { var pct = Math.max(0, Math.min(1, timer / timerMax)); timerBar.width = 800 * pct; if (pct > 0.5) timerBar.tint = 0x3ecf4c;else if (pct > 0.2) timerBar.tint = 0xffe066;else timerBar.tint = 0xff4444; } // Spawn a monster at random position function spawnMonster() { if (monsters.length >= monsterMax) return; var m = new Monster(); // Avoid top 100px (menu) var margin = 100 + 80; m.x = margin + Math.random() * (2048 - margin * 2); m.y = margin + Math.random() * (2732 - margin * 2); m.setRandomMovement(); m.updateTypeVisual && m.updateTypeVisual(); monsters.push(m); game.addChild(m); } // GUI: Score scoreText = new Text2("0", { size: 120, fill: "#fff" }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // GUI: Timer bar background (centered at top) timerBarBg = LK.getAsset('monster', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 100, width: 800, height: 40, tint: 0x222222 }); timerBarBg.alpha = 0.5; game.addChild(timerBarBg); // GUI: Timer bar (centered at top) timerBar = LK.getAsset('monster', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 100, width: 800, height: 40, tint: 0x3ecf4c }); game.addChild(timerBar); // GUI: Timer text (centered above bar) timerText = new Text2("0", { size: 90, fill: "#fff" }); timerText.anchor.set(0.5, 1); timerText.x = 2048 / 2; timerText.y = 100 - 10; game.addChild(timerText); // Stage labels var stageLabels = [{ label: "Very easy", min: 0, max: 15 }, { label: "Easy", min: 15, max: 45 }, { label: "Medium", min: 45, max: 90 }, { label: "Hard", min: 90, max: 150 }, { label: "Very hard", min: 150, max: 9999 }]; var stageTexts = []; var stageActiveIndex = 0; var stageYOffset = 70; for (var i = 0; i < stageLabels.length; ++i) { var st = new Text2(stageLabels[i].label, { size: 60, fill: "#888" }); st.anchor.set(0.5, 0); st.x = 2048 / 2; st.y = timerText.y + 20 + i * stageYOffset; game.addChild(st); stageTexts.push(st); } function updateStageDisplay() { // Find which stage we're in based on timer counting up var elapsed = timer; var idx = 0; for (var i = 0; i < stageLabels.length; ++i) { if (elapsed >= stageLabels[i].min && elapsed < stageLabels[i].max) { idx = i; break; } } stageActiveIndex = idx; for (var i = 0; i < stageTexts.length; ++i) { // Use setStyle to update fill color instead of direct style.fill assignment stageTexts[i].setStyle({ fill: i === stageActiveIndex ? "#fff" : "#888" }); stageTexts[i].setText(stageLabels[i].label); } } updateStageDisplay(); // Position score at top center, below 100px scoreText.x = 2048 / 2; scoreText.y = 10 + 100; // Spawn initial monsters for (var i = 0; i < 3; ++i) { spawnMonster(); } // Timer tick function timerTick() { // Timer increases faster as difficulty increases var difficulty = 1 + Math.floor(LK.ticks / 60 / 10) * 0.1; // +10% every 10s timer += 0.1 * difficulty; if (timer > 9999) timer = 9999; updateTimerText(); updateTimerBar(); updateStageDisplay(); // No game over by timer running out, unless you want to set a max time } // Start timer interval timerInterval = LK.setInterval(timerTick, 100); // Game update game.update = function () { // Increase difficulty over time: timer drains faster, spawn rate increases // Difficulty scaling factor: increases every 10 seconds var difficulty = 1 + Math.floor(LK.ticks / 60 / 10) * 0.1; // +10% every 10s // Randomly change spawn interval every 3-6 seconds, but minimum interval decreases with difficulty if (monsterSpawnIntervalChangeTimer <= 0) { // Minimum interval decreases as difficulty increases, but never below 15 var minInterval = Math.max(15, 40 - Math.floor((difficulty - 1) * 30)); var maxInterval = Math.max(minInterval + 10, 180 - Math.floor((difficulty - 1) * 100)); monsterSpawnIntervalTarget = minInterval + Math.floor(Math.random() * (maxInterval - minInterval + 1)); // Next change in 180-360 ticks (3-6s) monsterSpawnIntervalChangeTimer = 180 + Math.floor(Math.random() * 180); } monsterSpawnIntervalChangeTimer--; // Smoothly approach target interval for a less abrupt change if (monsterSpawnInterval !== monsterSpawnIntervalTarget) { if (monsterSpawnInterval < monsterSpawnIntervalTarget) monsterSpawnInterval++;else monsterSpawnInterval--; } // Spawn monsters if (LK.ticks - lastTick >= monsterSpawnInterval) { spawnMonster(); lastTick = LK.ticks; } // Move monsters for (var i = 0; i < monsters.length; ++i) { monsters[i].update(); } // Update timer bar updateTimerBar(); }; // Handle tap on monsters or empty space game.down = function (x, y, obj) { // Check if tap hits a monster (from topmost to bottom) var tapped = false; for (var i = monsters.length - 1; i >= 0; --i) { var m = monsters[i]; // Only alive monsters if (!m.alive) continue; // Convert tap to monster local coords var local = m.toLocal(game.toGlobal({ x: x, y: y })); // Check if inside monster ellipse var rx = m.children[0].width / 2; var ry = m.children[0].height / 2; if (local.x * local.x / (rx * rx) + local.y * local.y / (ry * ry) <= 1) { m.down(x, y, obj); tapped = true; break; } } // Tap effect var tapFx = new TapEffect(); tapFx.x = x; tapFx.y = y; game.addChild(tapFx); }; // Clean up on game over game.on('destroy', function () { LK.clearInterval(timerInterval); monsters = []; score = 0; timer = timerMax; updateScoreText(); updateTimerText(); updateTimerBar(); updateStageDisplay(); });
===================================================================
--- original.js
+++ change.js
@@ -194,10 +194,10 @@
var monsterSpawnInterval = 120; // ticks between spawns (2s)
var monsterSpawnIntervalTarget = 120; // target interval for smooth transitions
var monsterSpawnIntervalChangeTimer = 0; // ticks until next interval change
var monsterMax = 6; // max monsters on screen
-var timerMax = 20; // seconds to start
-var timer = timerMax; // current timer (seconds)
+var timerMax = 20; // seconds to start (used for stage boundaries, not for countdown)
+var timer = 0; // current timer (seconds), now counts up
var timerInterval = null;
var timerBar = null;
var timerBarBg = null;
var timerText = null;
@@ -216,15 +216,16 @@
}
// Helper: add time
function addTime(sec) {
timer += sec;
- if (timer > 99) timer = 99;
+ if (timer > 9999) timer = 9999;
updateTimerText();
updateStageDisplay();
+ updateTimerBar();
}
// Helper: update timer text
function updateTimerText() {
- timerText.setText(timer > 0 ? Math.ceil(timer) + "" : "0");
+ timerText.setText(Math.floor(timer) + "");
}
// Helper: update timer bar
function updateTimerBar() {
var pct = Math.max(0, Math.min(1, timer / timerMax));
@@ -250,39 +251,39 @@
fill: "#fff"
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
-// GUI: Timer bar background
+// GUI: Timer bar background (centered at top)
timerBarBg = LK.getAsset('monster', {
- anchorX: 0,
+ anchorX: 0.5,
anchorY: 0.5,
- x: 624,
+ x: 2048 / 2,
y: 100,
width: 800,
height: 40,
tint: 0x222222
});
timerBarBg.alpha = 0.5;
game.addChild(timerBarBg);
-// GUI: Timer bar
+// GUI: Timer bar (centered at top)
timerBar = LK.getAsset('monster', {
- anchorX: 0,
+ anchorX: 0.5,
anchorY: 0.5,
- x: 624,
+ x: 2048 / 2,
y: 100,
width: 800,
height: 40,
tint: 0x3ecf4c
});
game.addChild(timerBar);
-// GUI: Timer text
-timerText = new Text2(timerMax + "", {
+// GUI: Timer text (centered above bar)
+timerText = new Text2("0", {
size: 90,
fill: "#fff"
});
-timerText.anchor.set(0.5, 0.5);
-timerText.x = 2048 - 200;
-timerText.y = 100 + 20;
+timerText.anchor.set(0.5, 1);
+timerText.x = 2048 / 2;
+timerText.y = 100 - 10;
game.addChild(timerText);
// Stage labels
var stageLabels = [{
label: "Very easy",
@@ -313,16 +314,16 @@
size: 60,
fill: "#888"
});
st.anchor.set(0.5, 0);
- st.x = 2048 - 200;
- st.y = timerText.y + 60 + i * stageYOffset;
+ st.x = 2048 / 2;
+ st.y = timerText.y + 20 + i * stageYOffset;
game.addChild(st);
stageTexts.push(st);
}
function updateStageDisplay() {
- // Find which stage we're in based on elapsed time
- var elapsed = timerMax - timer;
+ // Find which stage we're in based on timer counting up
+ var elapsed = timer;
var idx = 0;
for (var i = 0; i < stageLabels.length; ++i) {
if (elapsed >= stageLabels[i].min && elapsed < stageLabels[i].max) {
idx = i;
@@ -347,19 +348,16 @@
spawnMonster();
}
// Timer tick
function timerTick() {
- // Timer decreases faster as difficulty increases
+ // Timer increases faster as difficulty increases
var difficulty = 1 + Math.floor(LK.ticks / 60 / 10) * 0.1; // +10% every 10s
- timer -= 0.1 * difficulty;
- if (timer < 0) timer = 0;
+ timer += 0.1 * difficulty;
+ if (timer > 9999) timer = 9999;
updateTimerText();
updateTimerBar();
updateStageDisplay();
- if (timer <= 0) {
- // Game over
- LK.showGameOver();
- }
+ // No game over by timer running out, unless you want to set a max time
}
// Start timer interval
timerInterval = LK.setInterval(timerTick, 100);
// Game update
round shaped monster. his mouth is open and his tongue is out . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
make it angry and blue
make it cocky and white
make it purple and suspicious
make it dark green and idiot
make it black and idioter
make it happy and cyan
skeletons, skull, death city, war, crime, illegal . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat