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 }); // Set initial speed (pixels per frame) self.speedY = 8 + Math.random() * 8; // Track lastY for off-screen detection 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.lastY = self.y; self.y += self.speedY; // Remove if off the bottom of the screen if (self.lastY <= 2732 && self.y > 2732) { self.destroy(); } }; return self; }); // FallingObject class: represents a clickable object falling from the top 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 }); // Set initial speed (pixels per frame) self.speedY = 8 + Math.random() * 8; // randomize speed a bit // Track lastY for off-screen detection self.lastY = self.y; // Handle tap/click on the object self.down = function (x, y, objEvent) { // Only count if not already destroyed if (!self._destroyed) { score += 1; updateScore(); self.destroy(); } }; // Called every frame self.update = function () { self.lastY = self.y; self.y += self.speedY; // Remove if off the bottom of the screen if (self.lastY <= 2732 && self.y > 2732) { 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 at a random X position 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(); } // Random X, avoid left 100px and right 100px margins obj.x = 120 + Math.random() * (2048 - 240); obj.y = -100; // Start just above the screen 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
@@ -1,7 +1,39 @@
/****
* 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
+ });
+ // Set initial speed (pixels per frame)
+ self.speedY = 8 + Math.random() * 8;
+ // Track lastY for off-screen detection
+ 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.lastY = self.y;
+ self.y += self.speedY;
+ // Remove if off the bottom of the screen
+ if (self.lastY <= 2732 && self.y > 2732) {
+ self.destroy();
+ }
+ };
+ return self;
+});
// FallingObject class: represents a clickable object falling from the top
var FallingObject = Container.expand(function () {
var self = Container.call(this);
// Attach a simple ellipse asset, centered
@@ -75,9 +107,16 @@
// Array to keep track of falling objects
var fallingObjects = [];
// Spawn a new falling object at a random X position
function spawnFallingObject() {
- var obj = new FallingObject();
+ // 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();
+ }
// Random X, avoid left 100px and right 100px margins
obj.x = 120 + Math.random() * (2048 - 240);
obj.y = -100; // Start just above the screen
fallingObjects.push(obj);