User prompt
pero que solo el objeto se le pueda dar click y suba el contador y no toda la pantalla
User prompt
pero haz que solo caundo le des al objeto suba el contador y si fallas el click que se tome como un error y que solo el objeto tenga colision y no toda la pantalla
User prompt
haz mas largo el tiempo en el que aparecen los objetos pero manten lo demas
Code edit (1 edits merged)
Please save this source code
User prompt
Quick Tap Challenge
Initial prompt
El juego funciona así: hay un solo objeto en pantalla que aparece en posiciones aleatorias. Cuando aparece, el jugador tiene poco tiempo para tocarlo. Si el jugador lo toca, gana un punto y el tiempo antes de que desaparezca se reduce un poco para aumentar la dificultad. Si el jugador no toca el objeto a tiempo, se cuenta como un fallo. Al llegar a 3 fallos, debe aparecer una pantalla de “Game Over”.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var TapObject = Container.expand(function () {
var self = Container.call(this);
var objectGraphics = self.attachAsset('tapObject', {
anchorX: 0.5,
anchorY: 0.5
});
self.isActive = true;
self.wasClicked = false;
self.down = function (x, y, obj) {
if (self.isActive && !self.wasClicked) {
self.wasClicked = true;
self.isActive = false;
LK.getSound('tap').play();
LK.effects.flashObject(self, 0x00ff00, 200);
return true;
}
return false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var currentTapObject = null;
var score = 0;
var missedCount = 0;
var timeWindow = 2000;
var minTimeWindow = 400;
var currentTimer = null;
var isGameActive = true;
var gameStarted = false;
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var missesContainer = new Container();
missesContainer.x = 100;
missesContainer.y = 100;
game.addChild(missesContainer);
var missIndicators = [];
function updateMissIndicators() {
for (var i = 0; i < missIndicators.length; i++) {
missIndicators[i].destroy();
}
missIndicators = [];
for (var i = 0; i < missedCount; i++) {
var missIndicator = LK.getAsset('tapObject', {
anchorX: 0.5,
anchorY: 0.5
});
missIndicator.tint = 0x808080;
missIndicator.scaleX = 0.6;
missIndicator.scaleY = 0.6;
missIndicator.x = i * 150;
missIndicator.y = 0;
missesContainer.addChild(missIndicator);
missIndicators.push(missIndicator);
}
}
function spawnNewObject() {
if (currentTapObject !== null) {
currentTapObject.destroy();
}
var randomX = Math.random() * 1800 + 124;
var randomY = Math.random() * 2400 + 200;
currentTapObject = game.addChild(new TapObject());
currentTapObject.x = randomX;
currentTapObject.y = randomY;
currentTapObject.wasClicked = false;
currentTapObject.isActive = true;
if (currentTimer !== null) {
LK.clearTimeout(currentTimer);
}
currentTimer = LK.setTimeout(function () {
if (currentTapObject !== null && currentTapObject.isActive) {
missedCount += 1;
updateMissIndicators();
LK.getSound('miss').play();
if (missedCount >= 3) {
isGameActive = false;
if (currentTapObject !== null) {
currentTapObject.destroy();
currentTapObject = null;
}
LK.showGameOver();
} else {
spawnNewObject();
}
}
}, timeWindow);
}
game.down = function (x, y, obj) {
if (!isGameActive || !gameStarted) {
return;
}
if (currentTapObject !== null) {
var wasHit = currentTapObject.down(x, y, obj);
if (wasHit) {
score += 1;
scoreTxt.setText(score);
LK.setScore(score);
timeWindow = Math.max(minTimeWindow, timeWindow - 50);
LK.clearTimeout(currentTimer);
spawnNewObject();
}
}
};
game.update = function () {
if (!gameStarted && isGameActive) {
gameStarted = true;
spawnNewObject();
LK.playMusic('bgmusic');
}
};
updateMissIndicators(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,133 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var TapObject = Container.expand(function () {
+ var self = Container.call(this);
+ var objectGraphics = self.attachAsset('tapObject', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.isActive = true;
+ self.wasClicked = false;
+ self.down = function (x, y, obj) {
+ if (self.isActive && !self.wasClicked) {
+ self.wasClicked = true;
+ self.isActive = false;
+ LK.getSound('tap').play();
+ LK.effects.flashObject(self, 0x00ff00, 200);
+ return true;
+ }
+ return false;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a2e
+});
+
+/****
+* Game Code
+****/
+var currentTapObject = null;
+var score = 0;
+var missedCount = 0;
+var timeWindow = 2000;
+var minTimeWindow = 400;
+var currentTimer = null;
+var isGameActive = true;
+var gameStarted = false;
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var missesContainer = new Container();
+missesContainer.x = 100;
+missesContainer.y = 100;
+game.addChild(missesContainer);
+var missIndicators = [];
+function updateMissIndicators() {
+ for (var i = 0; i < missIndicators.length; i++) {
+ missIndicators[i].destroy();
+ }
+ missIndicators = [];
+ for (var i = 0; i < missedCount; i++) {
+ var missIndicator = LK.getAsset('tapObject', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ missIndicator.tint = 0x808080;
+ missIndicator.scaleX = 0.6;
+ missIndicator.scaleY = 0.6;
+ missIndicator.x = i * 150;
+ missIndicator.y = 0;
+ missesContainer.addChild(missIndicator);
+ missIndicators.push(missIndicator);
+ }
+}
+function spawnNewObject() {
+ if (currentTapObject !== null) {
+ currentTapObject.destroy();
+ }
+ var randomX = Math.random() * 1800 + 124;
+ var randomY = Math.random() * 2400 + 200;
+ currentTapObject = game.addChild(new TapObject());
+ currentTapObject.x = randomX;
+ currentTapObject.y = randomY;
+ currentTapObject.wasClicked = false;
+ currentTapObject.isActive = true;
+ if (currentTimer !== null) {
+ LK.clearTimeout(currentTimer);
+ }
+ currentTimer = LK.setTimeout(function () {
+ if (currentTapObject !== null && currentTapObject.isActive) {
+ missedCount += 1;
+ updateMissIndicators();
+ LK.getSound('miss').play();
+ if (missedCount >= 3) {
+ isGameActive = false;
+ if (currentTapObject !== null) {
+ currentTapObject.destroy();
+ currentTapObject = null;
+ }
+ LK.showGameOver();
+ } else {
+ spawnNewObject();
+ }
+ }
+ }, timeWindow);
+}
+game.down = function (x, y, obj) {
+ if (!isGameActive || !gameStarted) {
+ return;
+ }
+ if (currentTapObject !== null) {
+ var wasHit = currentTapObject.down(x, y, obj);
+ if (wasHit) {
+ score += 1;
+ scoreTxt.setText(score);
+ LK.setScore(score);
+ timeWindow = Math.max(minTimeWindow, timeWindow - 50);
+ LK.clearTimeout(currentTimer);
+ spawnNewObject();
+ }
+ }
+};
+game.update = function () {
+ if (!gameStarted && isGameActive) {
+ gameStarted = true;
+ spawnNewObject();
+ LK.playMusic('bgmusic');
+ }
+};
+updateMissIndicators();
\ No newline at end of file