/****
* 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);
handleObjectTap();
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 = 3500;
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);
}
var handleObjectTap = function handleObjectTap() {
if (isGameActive && gameStarted) {
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(); /****
* 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);
handleObjectTap();
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 = 3500;
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);
}
var handleObjectTap = function handleObjectTap() {
if (isGameActive && gameStarted) {
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();