User prompt
Nesneler bazen yön değiştirebilir
User prompt
Nesne sayısı sıfır olamaz
User prompt
Nesneler sürekli çağrılır
User prompt
İlk başta aynı anda 5 nesne ekrandadır zamanla artarak maksimum 15 tane nesne aynı anda olur
User prompt
Nesnelerin sıklığı yavaş yavaş artar
User prompt
Nesnelerin hızları bazen yavaşlar bazen ise hızlanır bütün nesnelerin hızları birbirinden bağımsızdır
User prompt
Bu nesneler aynı anda sağdan sola, soldan sağa, yukarıdan aşağıya ve aşağıdan yukarıya doğru gelebildim
User prompt
Yeni bir varlık ekle ve bu varlığa tıklayınca puanı eksilt
User prompt
Yukarıdan varlıklar gelecek şekilde ayarla ve gelen varlıklara tıklayınca puanın gelmesini sağla
Code edit (1 edits merged)
Please save this source code
User prompt
Tap Score Frenzy
Initial prompt
public int score = 0; public void OnClick() { score++; scoreText.text = score.ToString(); }
/****
* Classes
****/
// BadFallingObject class: represents a clickable object that decreases score
var BadFallingObject = Container.expand(function () {
var self = Container.call(this);
// Attach a red ellipse asset, centered
var obj = self.attachAsset('badFallingEllipse', {
anchorX: 0.5,
anchorY: 0.5
});
// Direction: 0=down, 1=up, 2=left, 3=right
self.direction = 0;
self.speed = 8 + Math.random() * 8;
// Track last positions for off-screen detection
self.lastX = self.x;
self.lastY = self.y;
// Handle tap/click on the object
self.down = function (x, y, objEvent) {
if (!self._destroyed) {
score -= 1;
if (score < 0) score = 0;
updateScore();
self.destroy();
}
};
// Called every frame
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
// Randomly accelerate or decelerate speed a little, but clamp to min/max
if (Math.random() < 0.15) {
// 15% chance per frame to change speed
var delta = (Math.random() - 0.5) * 1.2; // -0.6 to +0.6
self.speed += delta;
if (self.speed < 3) self.speed = 3;
if (self.speed > 20) self.speed = 20;
}
// Randomly change direction with a small chance
if (Math.random() < 0.03) {
// Pick a new direction different from current
var newDir = Math.floor(Math.random() * 4);
if (newDir !== self.direction) {
self.direction = newDir;
}
}
if (self.direction === 0) {
// down
self.y += self.speed;
if (self.lastY <= 2732 && self.y > 2732) {
self.destroy();
}
} else if (self.direction === 1) {
// up
self.y -= self.speed;
if (self.lastY >= -100 && self.y < -100) {
self.destroy();
}
} else if (self.direction === 2) {
// left
self.x -= self.speed;
if (self.lastX >= -100 && self.x < -100) {
self.destroy();
}
} else if (self.direction === 3) {
// right
self.x += self.speed;
if (self.lastX <= 2048 + 100 && self.x > 2048 + 100) {
self.destroy();
}
}
};
return self;
});
// FallingObject class: represents a clickable object moving in any direction
var FallingObject = Container.expand(function () {
var self = Container.call(this);
// Attach a simple ellipse asset, centered
var obj = self.attachAsset('fallingEllipse', {
anchorX: 0.5,
anchorY: 0.5
});
// Direction: 0=down, 1=up, 2=left, 3=right
self.direction = 0;
self.speed = 8 + Math.random() * 8;
// Track last positions for off-screen detection
self.lastX = self.x;
self.lastY = self.y;
// Handle tap/click on the object
self.down = function (x, y, objEvent) {
if (!self._destroyed) {
score += 1;
updateScore();
self.destroy();
}
};
// Called every frame
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
// Randomly accelerate or decelerate speed a little, but clamp to min/max
if (Math.random() < 0.15) {
// 15% chance per frame to change speed
var delta = (Math.random() - 0.5) * 1.2; // -0.6 to +0.6
self.speed += delta;
if (self.speed < 3) self.speed = 3;
if (self.speed > 20) self.speed = 20;
}
// Randomly change direction with a small chance
if (Math.random() < 0.03) {
// Pick a new direction different from current
var newDir = Math.floor(Math.random() * 4);
if (newDir !== self.direction) {
self.direction = newDir;
}
}
if (self.direction === 0) {
// down
self.y += self.speed;
if (self.lastY <= 2732 && self.y > 2732) {
self.destroy();
}
} else if (self.direction === 1) {
// up
self.y -= self.speed;
if (self.lastY >= -100 && self.y < -100) {
self.destroy();
}
} else if (self.direction === 2) {
// left
self.x -= self.speed;
if (self.lastX >= -100 && self.x < -100) {
self.destroy();
}
} else if (self.direction === 3) {
// right
self.x += self.speed;
if (self.lastX <= 2048 + 100 && self.x > 2048 + 100) {
self.destroy();
}
}
};
return self;
});
/****
* Initialize Game
****/
// Asset for falling objects (ellipse, visually distinct)
// No custom assets needed for this minimal tap game. The score will be displayed using Text2.
// No plugins needed for this minimal tap game.
// No custom classes needed for this minimal tap game.
var game = new LK.Game({
backgroundColor: 0x000000 // Black background for contrast
});
/****
* Game Code
****/
// Set a visually appealing background color (optional, can be changed)
game.setBackgroundColor(0x1a1a1a);
// Create the score text, large and centered at the top
var scoreTxt = new Text2('0', {
size: 200,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0); // Center horizontally, top edge
LK.gui.top.addChild(scoreTxt);
// Initialize score variable
var score = 0;
// Function to update score display
function updateScore() {
scoreTxt.setText(score);
}
// Handle tap/click/touch anywhere on the game area
game.down = function (x, y, obj) {
// Ignore taps in the top-left 100x100 area (reserved for menu)
if (x < 100 && y < 100) return;
score += 1;
updateScore();
};
// Optionally, update the score at start
updateScore();
// Array to keep track of falling objects
var fallingObjects = [];
// Spawn a new falling object from a random direction
function spawnFallingObject() {
// 25% chance to spawn a bad object, 75% normal
var isBad = Math.random() < 0.25;
var obj;
if (isBad) {
obj = new BadFallingObject();
} else {
obj = new FallingObject();
}
// Pick a random direction: 0=down, 1=up, 2=left, 3=right
var dir = Math.floor(Math.random() * 4);
obj.direction = dir;
// Set initial position based on direction
if (dir === 0) {
// down (from top)
obj.x = 120 + Math.random() * (2048 - 240);
obj.y = -100;
} else if (dir === 1) {
// up (from bottom)
obj.x = 120 + Math.random() * (2048 - 240);
obj.y = 2732 + 100;
} else if (dir === 2) {
// left (from right)
obj.x = 2048 + 100;
obj.y = 120 + Math.random() * (2732 - 240);
} else if (dir === 3) {
// right (from left)
obj.x = -100;
obj.y = 120 + Math.random() * (2732 - 240);
}
fallingObjects.push(obj);
game.addChild(obj);
}
// Game update: move objects, remove destroyed ones, spawn new ones
game.update = function () {
// Update all falling objects
for (var i = fallingObjects.length - 1; i >= 0; i--) {
var obj = fallingObjects[i];
if (obj._destroyed) {
fallingObjects.splice(i, 1);
continue;
}
if (typeof obj.update === "function") obj.update();
}
// Spawn a new object every 40 frames (~1.5 per second)
if (LK.ticks % 40 === 0) {
spawnFallingObject();
}
};
// Remove tap-to-score-anywhere, now only objects are clickable
game.down = function (x, y, obj) {
// Do nothing here; objects handle their own tap
};
// Asset for falling objects (ellipse, visually distinct) ===================================================================
--- original.js
+++ change.js
@@ -35,8 +35,16 @@
self.speed += delta;
if (self.speed < 3) self.speed = 3;
if (self.speed > 20) self.speed = 20;
}
+ // Randomly change direction with a small chance
+ if (Math.random() < 0.03) {
+ // Pick a new direction different from current
+ var newDir = Math.floor(Math.random() * 4);
+ if (newDir !== self.direction) {
+ self.direction = newDir;
+ }
+ }
if (self.direction === 0) {
// down
self.y += self.speed;
if (self.lastY <= 2732 && self.y > 2732) {
@@ -97,8 +105,16 @@
self.speed += delta;
if (self.speed < 3) self.speed = 3;
if (self.speed > 20) self.speed = 20;
}
+ // Randomly change direction with a small chance
+ if (Math.random() < 0.03) {
+ // Pick a new direction different from current
+ var newDir = Math.floor(Math.random() * 4);
+ if (newDir !== self.direction) {
+ self.direction = newDir;
+ }
+ }
if (self.direction === 0) {
// down
self.y += self.speed;
if (self.lastY <= 2732 && self.y > 2732) {
@@ -157,18 +173,17 @@
scoreTxt.setText(score);
}
// Handle tap/click/touch anywhere on the game area
game.down = function (x, y, obj) {
- // Do nothing here; objects handle their own tap
+ // Ignore taps in the top-left 100x100 area (reserved for menu)
+ if (x < 100 && y < 100) return;
+ score += 1;
+ updateScore();
};
// Optionally, update the score at start
updateScore();
// Array to keep track of falling objects
var fallingObjects = [];
-// Spawn 5 objects at the start
-for (var i = 0; i < 5; i++) {
- spawnFallingObject();
-}
// Spawn a new falling object from a random direction
function spawnFallingObject() {
// 25% chance to spawn a bad object, 75% normal
var isBad = Math.random() < 0.25;
@@ -207,49 +222,17 @@
// Update all falling objects
for (var i = fallingObjects.length - 1; i >= 0; i--) {
var obj = fallingObjects[i];
if (obj._destroyed) {
- // Only remove if more than 1 object will remain
- if (fallingObjects.length > 1) {
- fallingObjects.splice(i, 1);
- continue;
- } else {
- // If this is the last object, do not remove it
- obj._destroyed = false; // Prevent further removal attempts
- }
+ fallingObjects.splice(i, 1);
+ continue;
}
if (typeof obj.update === "function") obj.update();
}
- // Gradually decrease the spawn interval to increase spawn frequency over time
- if (typeof spawnInterval === "undefined") {
- var spawnInterval = 40; // initial interval (frames)
- var minSpawnInterval = 10; // minimum interval (max frequency)
- var spawnIntervalDecreaseRate = 0.01; // decrease per frame
- var spawnIntervalAccumulator = 0;
- var maxObjects = 5; // Start with 5 objects
- var maxObjectsIncreaseRate = 1 / (60 * 10); // Increase maxObjects by 1 every 10 seconds (at 60fps)
- var maxObjectsAccumulator = 0;
+ // Spawn a new object every 40 frames (~1.5 per second)
+ if (LK.ticks % 40 === 0) {
+ spawnFallingObject();
}
- // Increase maxObjects over time, up to 15
- if (maxObjects < 15) {
- maxObjectsAccumulator += maxObjectsIncreaseRate;
- if (maxObjectsAccumulator >= 1) {
- maxObjects += 1;
- if (maxObjects > 15) maxObjects = 15;
- maxObjectsAccumulator = 0;
- }
- }
- spawnIntervalAccumulator += 1;
- if (spawnIntervalAccumulator >= spawnInterval) {
- // Only spawn if we have less than maxObjects on screen
- if (fallingObjects.length < maxObjects) {
- spawnFallingObject();
- }
- spawnIntervalAccumulator = 0;
- // Decrease interval, but clamp to minSpawnInterval
- spawnInterval -= spawnIntervalDecreaseRate;
- if (spawnInterval < minSpawnInterval) spawnInterval = minSpawnInterval;
- }
};
// Remove tap-to-score-anywhere, now only objects are clickable
game.down = function (x, y, obj) {
// Do nothing here; objects handle their own tap