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 monsterMax = 6; // max monsters on screen var timerMax = 20; // seconds to start var timer = timerMax; // current timer (seconds) 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 > 99) timer = 99; updateTimerText(); } // Helper: update timer text function updateTimerText() { timerText.setText(timer > 0 ? Math.ceil(timer) + "" : "0"); } // 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 timerBarBg = LK.getAsset('monster', { anchorX: 0, anchorY: 0.5, x: 624, y: 100, width: 800, height: 40, tint: 0x222222 }); timerBarBg.alpha = 0.5; game.addChild(timerBarBg); // GUI: Timer bar timerBar = LK.getAsset('monster', { anchorX: 0, anchorY: 0.5, x: 624, y: 100, width: 800, height: 40, tint: 0x3ecf4c }); game.addChild(timerBar); // GUI: Timer text timerText = new Text2(timerMax + "", { size: 90, fill: "#fff" }); timerText.anchor.set(0.5, 0.5); timerText.x = 2048 / 2; timerText.y = 100 + 20; game.addChild(timerText); // 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 -= 0.1; if (timer < 0) timer = 0; updateTimerText(); updateTimerBar(); if (timer <= 0) { // Game over LK.showGameOver(); } } // Start timer interval timerInterval = LK.setInterval(timerTick, 100); // Game update game.update = function () { // 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(); });
===================================================================
--- original.js
+++ change.js
@@ -8,23 +8,61 @@
****/
// 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 () {
- // Speed: 2-6 px/tick
- self.speed = 2 + Math.random() * 4;
+ // 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
@@ -67,9 +105,10 @@
x: 0,
y: 0,
scaleX: 1,
scaleY: 1,
- alpha: 1
+ alpha: 1,
+ tint: self.type === "fast" ? 0x3e8ecf : self.type === "slow" ? 0xcfb53e : 0xff4444
});
self.addChild(hit);
// Animate hit effect
tween(hit, {
@@ -92,9 +131,15 @@
self.destroy();
}
});
// Add time and score
- addTime(2); // +2 seconds per monster
+ 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) {
@@ -191,8 +236,9 @@
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
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