User prompt
LK.init.music('1') PLAY
User prompt
MUSİC PLAY!
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'isActive')' in or related to this line: 'if (!c.isActive) {' Line Number: 344
User prompt
the problem is that the bonus section does not come and the diamonds do not come in the bonus section and finally the energy does not end and the money to get the energy must be 100 and there is no place to get it
User prompt
Very nice, now let's make a level system for this. At the end of each level, there will be a bonus level. There will be a level where you will try to get all the diamonds that appear in 10 seconds and you will buy food with the money because there will be energy and the name of the game is now Goat Clicking.
User prompt
replace hello with click
Code edit (1 edits merged)
Please save this source code
User prompt
Merhaba Match
Initial prompt
merhaba
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Decoy character class var DecoyChar = Container.expand(function () { var self = Container.call(this); var _char = self.attachAsset('decoyChar', { anchorX: 0.5, anchorY: 0.5 }); // Add "X" text centered var txt = new Text2('X', { size: 90, fill: 0xFFFFFF }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = 0; self.addChild(txt); self.isMerhaba = false; self.isActive = true; // Tap handler self.down = function (x, y, obj) { if (!self.isActive) return; self.isActive = false; handleDecoyTap(self); }; return self; }); // Merhaba character class var MerhabaChar = Container.expand(function () { var self = Container.call(this); var _char2 = self.attachAsset('merhabaChar', { anchorX: 0.5, anchorY: 0.5 }); // Add "Click" text centered var txt = new Text2('Click', { size: 70, fill: 0xFFFFFF }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = 0; self.addChild(txt); self.isMerhaba = true; self.isActive = true; // Tap handler self.down = function (x, y, obj) { if (!self.isActive) return; self.isActive = false; handleMerhabaTap(self); }; return self; }); // Tap effect class var TapEffect = Container.expand(function () { var self = Container.call(this); var eff = self.attachAsset('tapEffect', { anchorX: 0.5, anchorY: 0.5 }); eff.alpha = 0.5; self.eff = eff; self.play = function (x, y) { self.x = x; self.y = y; self.visible = true; eff.scaleX = 1; eff.scaleY = 1; eff.alpha = 0.5; tween(eff, { scaleX: 2, scaleY: 2, alpha: 0 }, { duration: 350, easing: tween.easeOut, onFinish: function onFinish() { self.visible = false; } }); }; self.visible = false; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222831 }); /**** * Game Code ****/ // Game variables // Friendly "Merhaba" character: green ellipse with "Merhaba" text // Decoy character: red ellipse with "X" text // Life icon: small yellow ellipse // Tap effect: white ellipse // Sound for correct tap // Sound for wrong tap // Sound for losing a life // Sound for new spawn var score = 0; var lives = 3; var maxLives = 3; var activeChars = []; var charLifetime = 1200; // ms, will decrease as score increases var minCharLifetime = 500; // ms var spawnInterval = 900; // ms, will decrease as score increases var minSpawnInterval = 350; // ms var lastSpawnTime = 0; var isGameOver = false; var tapEffect; // Score display var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Lives display var lifeIcons = []; function updateLivesDisplay() { // Remove old icons for (var i = 0; i < lifeIcons.length; i++) { if (lifeIcons[i].parent) lifeIcons[i].parent.removeChild(lifeIcons[i]); } lifeIcons = []; // Place at top right, with margin var margin = 30; for (var i = 0; i < lives; i++) { var icon = LK.getAsset('lifeIcon', { anchorX: 0.5, anchorY: 0.5 }); icon.x = -(i * 70) - 60; icon.y = 60; LK.gui.topRight.addChild(icon); lifeIcons.push(icon); } } updateLivesDisplay(); // Tap effect instance tapEffect = new TapEffect(); game.addChild(tapEffect); // Helper: get random position for character, avoiding top left 100x100 function getRandomCharPos() { var margin = 180; var x = margin + Math.random() * (2048 - 2 * margin); var y = margin + Math.random() * (2732 - 2 * margin); // Avoid top left 100x100 if (x < 100 && y < 100) x = 100 + margin; return { x: x, y: y }; } // Helper: spawn a character (merhaba or decoy) function spawnChar() { if (isGameOver) return; var isMerhaba = Math.random() < 0.7; // 70% chance merhaba, 30% decoy var _char3; if (isMerhaba) { _char3 = new MerhabaChar(); } else { _char3 = new DecoyChar(); } var pos = getRandomCharPos(); _char3.x = pos.x; _char3.y = pos.y; _char3.scaleX = 0.7; _char3.scaleY = 0.7; _char3.alpha = 0; // Animate in tween(_char3, { scaleX: 1, scaleY: 1, alpha: 1 }, { duration: 180, easing: tween.easeOut }); game.addChild(_char3); activeChars.push({ obj: _char3, isMerhaba: isMerhaba, spawnTime: Date.now(), isActive: true }); LK.getSound('spawn').play(); } // Helper: handle tap on Merhaba function handleMerhabaTap(charObj) { if (isGameOver) return; // Find in activeChars for (var i = 0; i < activeChars.length; i++) { var c = activeChars[i]; if (c.obj === charObj && c.isActive) { c.isActive = false; // Score up score += 1; LK.setScore(score); scoreTxt.setText(score); // Tap effect tapEffect.play(charObj.x, charObj.y); // Animate out tween(charObj, { scaleX: 1.3, scaleY: 1.3, alpha: 0 }, { duration: 180, easing: tween.easeIn, onFinish: function onFinish() { charObj.destroy(); } }); LK.getSound('goodTap').play(); // Remove from activeChars activeChars.splice(i, 1); // Speed up game updateDifficulty(); return; } } } // Helper: handle tap on Decoy function handleDecoyTap(charObj) { if (isGameOver) return; // Find in activeChars for (var i = 0; i < activeChars.length; i++) { var c = activeChars[i]; if (c.obj === charObj && c.isActive) { c.isActive = false; // Lose a life loseLife(charObj.x, charObj.y); // Animate out tween(charObj, { scaleX: 0.7, scaleY: 0.7, alpha: 0 }, { duration: 180, easing: tween.easeIn, onFinish: function onFinish() { charObj.destroy(); } }); LK.getSound('badTap').play(); // Remove from activeChars activeChars.splice(i, 1); return; } } } // Helper: lose a life function loseLife(x, y) { if (isGameOver) return; lives -= 1; updateLivesDisplay(); LK.getSound('loseLife').play(); // Flash screen LK.effects.flashScreen(0xff0000, 300); if (lives <= 0) { endGame(); } } // Helper: update difficulty as score increases function updateDifficulty() { // Decrease charLifetime and spawnInterval as score increases var speedup = Math.floor(score / 5); charLifetime = Math.max(minCharLifetime, 1200 - speedup * 70); spawnInterval = Math.max(minSpawnInterval, 900 - speedup * 40); } // Helper: end game function endGame() { isGameOver = true; // Remove all active chars for (var i = 0; i < activeChars.length; i++) { if (activeChars[i].obj && activeChars[i].obj.parent) { activeChars[i].obj.destroy(); } } activeChars = []; // Show game over LK.showGameOver(); } // Game tap handler (for missed taps) game.down = function (x, y, obj) { // If tap is not on any character, do nothing // (Characters handle their own tap events) }; // Main update loop game.update = function () { if (isGameOver) return; var now = Date.now(); // Spawn new char if enough time has passed if (activeChars.length < 2 && now - lastSpawnTime > spawnInterval) { spawnChar(); lastSpawnTime = now; } // Remove expired chars for (var i = activeChars.length - 1; i >= 0; i--) { var c = activeChars[i]; if (!c || !c.isActive) continue; if (now - c.spawnTime > charLifetime) { // If it's a Merhaba, missing it costs a life if (c.isMerhaba) { loseLife(c.obj.x, c.obj.y); // Animate out tween(c.obj, { scaleX: 0.7, scaleY: 0.7, alpha: 0 }, { duration: 180, easing: tween.easeIn, onFinish: function (obj) { if (obj && obj.parent) obj.destroy(); }.bind(null, c.obj) }); } else { // Decoy just disappears tween(c.obj, { scaleX: 0.7, scaleY: 0.7, alpha: 0 }, { duration: 180, easing: tween.easeIn, onFinish: function (obj) { if (obj && obj.parent) obj.destroy(); }.bind(null, c.obj) }); } c.isActive = false; activeChars.splice(i, 1); } } }; // Reset game state on new game LK.on('gameStart', function () { score = 0; lives = maxLives; isGameOver = false; activeChars = []; charLifetime = 1200; spawnInterval = 900; lastSpawnTime = 0; scoreTxt.setText(score); updateLivesDisplay(); // Remove all children except tapEffect var toRemove = []; for (var i = 0; i < game.children.length; i++) { var ch = game.children[i]; if (ch !== tapEffect) toRemove.push(ch); } for (var i = 0; i < toRemove.length; i++) { if (toRemove[i].parent) toRemove[i].parent.removeChild(toRemove[i]); } tapEffect.visible = false; });
===================================================================
--- original.js
+++ change.js
@@ -31,25 +31,8 @@
handleDecoyTap(self);
};
return self;
});
-// Diamond class for bonus level
-var Diamond = Container.expand(function () {
- var self = Container.call(this);
- var diamondAsset = self.attachAsset('lifeIcon', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- diamondAsset.tint = 0x00FFFF;
- self.isActive = true;
- self.down = function (x, y, obj) {
- if (!self.isActive) return;
- self.isActive = false;
- handleDiamondTap(self);
- };
- return self;
-});
-// Start bonus level
// Merhaba character class
var MerhabaChar = Container.expand(function () {
var self = Container.call(this);
var _char2 = self.attachAsset('merhabaChar', {
@@ -116,113 +99,17 @@
/****
* Game Code
****/
-// Sound for new spawn
-// Sound for losing a life
-// Sound for wrong tap
-// Sound for correct tap
-// Tap effect: white ellipse
-// Life icon: small yellow ellipse
-// Decoy character: red ellipse with "X" text
-// Friendly "Merhaba" character: green ellipse with "Merhaba" text
// Game variables
-// Goat Clicking - Level, Bonus, Energy, and Money System
-// Start bonus level
-function startBonusLevel() {
- isBonusLevel = true;
- bonusDiamonds = [];
- bonusDiamondsCollected = 0;
- bonusTimeLeft = bonusDuration;
- // Remove all normal chars
- for (var i = 0; i < activeChars.length; i++) {
- if (activeChars[i].obj && activeChars[i].obj.parent) {
- activeChars[i].obj.destroy();
- }
- }
- activeChars = [];
- // Spawn diamonds
- for (var d = 0; d < 7; d++) {
- var diamond = new Diamond();
- var pos = getRandomCharPos();
- diamond.x = pos.x;
- diamond.y = pos.y;
- diamond.scaleX = 1.1;
- diamond.scaleY = 1.1;
- game.addChild(diamond);
- bonusDiamonds.push(diamond);
- }
- // Show bonus timer
- if (!bonusTimerTxt) {
- bonusTimerTxt = new Text2('10.0', {
- size: 100,
- fill: 0x00FFFF
- });
- bonusTimerTxt.anchor.set(0.5, 0);
- bonusTimerTxt.y = 400;
- LK.gui.top.addChild(bonusTimerTxt);
- }
- bonusTimerTxt.visible = true;
- bonusTimerTxt.setText((bonusTimeLeft / 1000).toFixed(1));
- // Start timer
- if (bonusTimer) LK.clearInterval(bonusTimer);
- bonusTimer = LK.setInterval(function () {
- bonusTimeLeft -= 100;
- if (bonusTimeLeft <= 0) {
- endBonusLevel();
- } else {
- bonusTimerTxt.setText((bonusTimeLeft / 1000).toFixed(1));
- }
- }, 100);
-}
-// Handle diamond tap
-function handleDiamondTap(diamondObj) {
- bonusDiamondsCollected += 1;
- money += 1;
- updateMoneyDisplay();
- // Animate out
- tween(diamondObj, {
- scaleX: 1.5,
- scaleY: 1.5,
- alpha: 0
- }, {
- duration: 180,
- easing: tween.easeIn,
- onFinish: function onFinish() {
- diamondObj.destroy();
- }
- });
- // Remove from bonusDiamonds
- for (var i = 0; i < bonusDiamonds.length; i++) {
- if (bonusDiamonds[i] === diamondObj) {
- bonusDiamonds.splice(i, 1);
- break;
- }
- }
- // If all collected, end bonus level early
- if (bonusDiamonds.length === 0) {
- endBonusLevel();
- }
-}
-// End bonus level
-function endBonusLevel() {
- isBonusLevel = false;
- if (bonusTimer) {
- LK.clearInterval(bonusTimer);
- bonusTimer = null;
- }
- if (bonusTimerTxt) {
- bonusTimerTxt.visible = false;
- }
- // Remove all diamonds
- for (var i = 0; i < bonusDiamonds.length; i++) {
- if (bonusDiamonds[i].parent) bonusDiamonds[i].destroy();
- }
- bonusDiamonds = [];
- // Resume normal game
- lastSpawnTime = Date.now();
-}
-var bonusTimerTxt = null;
+// Friendly "Merhaba" character: green ellipse with "Merhaba" text
+// Decoy character: red ellipse with "X" text
+// Life icon: small yellow ellipse
+// Tap effect: white ellipse
+// Sound for correct tap
+// Sound for wrong tap
+// Sound for losing a life
+// Sound for new spawn
var score = 0;
var lives = 3;
var maxLives = 3;
var activeChars = [];
@@ -232,93 +119,15 @@
var minSpawnInterval = 350; // ms
var lastSpawnTime = 0;
var isGameOver = false;
var tapEffect;
-// Level, bonus, energy, and money system
-var level = 1;
-var isBonusLevel = false;
-var bonusDiamonds = [];
-var bonusDiamondsCollected = 0;
-var bonusTimer = null;
-var bonusTimeLeft = 0;
-var bonusDuration = 10000; // 10 seconds
-var energy = 5;
-var maxEnergy = 5;
-var money = 0;
-var foodCost = 100;
-// Add food purchase button to GUI
-var foodBtn = new Text2('Buy Food (+1 Energy)', {
- size: 60,
- fill: 0xFFD700
-});
-foodBtn.anchor.set(0.5, 0);
-foodBtn.y = 340;
-foodBtn.x = 0;
-foodBtn.interactive = true;
-foodBtn.buttonMode = true;
-LK.gui.top.addChild(foodBtn);
-foodBtn.visible = true;
-foodBtn.down = function (x, y, obj) {
- buyFood();
-};
-// Helper: update level display (to be called after level up)
-function updateLevelDisplay() {
- if (!levelTxt) return;
- levelTxt.setText("Level " + level);
-}
-// Helper: update energy display
-function updateEnergyDisplay() {
- if (!energyTxt) return;
- energyTxt.setText("Energy: " + energy + "/" + maxEnergy);
-}
-// Helper: update money display
-function updateMoneyDisplay() {
- if (!moneyTxt) return;
- moneyTxt.setText("Money: $" + money);
-}
-// Helper: buy food (restores energy)
-function buyFood() {
- if (money >= foodCost && energy < maxEnergy) {
- money -= foodCost;
- energy = Math.min(maxEnergy, energy + 1);
- updateMoneyDisplay();
- updateEnergyDisplay();
- }
-}
// Score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
-// Level display
-var levelTxt = new Text2('Level 1', {
- size: 70,
- fill: 0xFFD700
-});
-levelTxt.anchor.set(0.5, 0);
-levelTxt.y = 110;
-LK.gui.top.addChild(levelTxt);
-// Energy display
-var energyTxt = new Text2('Energy: 5/5', {
- size: 60,
- fill: 0x00FF00
-});
-energyTxt.anchor.set(0.5, 0);
-energyTxt.y = 200;
-LK.gui.top.addChild(energyTxt);
-// Money display
-var moneyTxt = new Text2('Money: $0', {
- size: 60,
- fill: 0x00BFFF
-});
-moneyTxt.anchor.set(0.5, 0);
-moneyTxt.y = 270;
-LK.gui.top.addChild(moneyTxt);
-updateLevelDisplay();
-updateEnergyDisplay();
-updateMoneyDisplay();
// Lives display
var lifeIcons = [];
function updateLivesDisplay() {
// Remove old icons
@@ -400,17 +209,8 @@
// Score up
score += 1;
LK.setScore(score);
scoreTxt.setText(score);
- // Decrease energy on every successful tap
- if (energy > 0) {
- energy -= 1;
- updateEnergyDisplay();
- if (energy === 0) {
- endGame();
- return;
- }
- }
// Tap effect
tapEffect.play(charObj.x, charObj.y);
// Animate out
tween(charObj, {
@@ -428,18 +228,8 @@
// Remove from activeChars
activeChars.splice(i, 1);
// Speed up game
updateDifficulty();
- // Level up and bonus level trigger
- if (!isBonusLevel && score > 0 && score % 10 === 0) {
- level += 1;
- updateLevelDisplay();
- // Delay bonus level start to allow last animation to finish
- LK.setTimeout(function () {
- startBonusLevel();
- }, 200);
- return;
- }
return;
}
}
}
@@ -511,9 +301,8 @@
};
// Main update loop
game.update = function () {
if (isGameOver) return;
- if (isBonusLevel) return; // Pause normal gameplay during bonus
var now = Date.now();
// Spawn new char if enough time has passed
if (activeChars.length < 2 && now - lastSpawnTime > spawnInterval) {
spawnChar();
@@ -521,9 +310,9 @@
}
// Remove expired chars
for (var i = activeChars.length - 1; i >= 0; i--) {
var c = activeChars[i];
- if (!c.isActive) continue;
+ if (!c || !c.isActive) continue;
if (now - c.spawnTime > charLifetime) {
// If it's a Merhaba, missing it costs a life
if (c.isMerhaba) {
loseLife(c.obj.x, c.obj.y);
@@ -566,19 +355,10 @@
activeChars = [];
charLifetime = 1200;
spawnInterval = 900;
lastSpawnTime = 0;
- level = 1;
- isBonusLevel = false;
- bonusDiamonds = [];
- bonusDiamondsCollected = 0;
- energy = maxEnergy;
- money = 0;
scoreTxt.setText(score);
updateLivesDisplay();
- updateLevelDisplay();
- updateEnergyDisplay();
- updateMoneyDisplay();
// Remove all children except tapEffect
var toRemove = [];
for (var i = 0; i < game.children.length; i++) {
var ch = game.children[i];
@@ -587,12 +367,5 @@
for (var i = 0; i < toRemove.length; i++) {
if (toRemove[i].parent) toRemove[i].parent.removeChild(toRemove[i]);
}
tapEffect.visible = false;
- if (bonusTimer) {
- LK.clearInterval(bonusTimer);
- bonusTimer = null;
- }
- if (bonusTimerTxt) {
- bonusTimerTxt.visible = false;
- }
});
\ No newline at end of file
goat. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
evil heart. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
goat's hand. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat