User prompt
arka paln gri olsun
User prompt
kaçan sayısı 10000 olsun
User prompt
kaçan sayısı 10 olsun
User prompt
süre olmasın
User prompt
tween leri sil
User prompt
Please fix the bug: 'ReferenceError: tween is not defined' in or related to this line: 'tween(m, {' Line Number: 261 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'ReferenceError: tween is not defined' in or related to this line: 'tween(m, {' Line Number: 261 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Raketle Sivrisinek Avı
Initial prompt
elimizde bir raket olsun o raketle duvardaki sivrisinekleri vurak
/****
* Classes
****/
//var tween = LK.import("@upit/tween.v1");
// Mosquito class: represents a single mosquito
var Mosquito = Container.expand(function () {
var self = Container.call(this);
// Attach mosquito asset (ellipse, small, dark color)
var mosquitoGfx = self.attachAsset('mosquito', {
anchorX: 0.5,
anchorY: 0.5
});
// Mosquito speed (pixels per tick)
self.speed = 6 + Math.random() * 4; // 6-10 px/tick
// Direction in radians (random)
self.direction = Math.random() * Math.PI * 2;
// Time until next direction change
self.changeDirTimer = 30 + Math.floor(Math.random() * 60);
// Mark as alive
self.alive = true;
// Update method: called every tick
self.update = function () {
// Move mosquito
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
// Bounce off walls (game area: 0,0 to 2048,2732)
var margin = mosquitoGfx.width / 2 + 10;
if (self.x < margin) {
self.x = margin;
self.direction = Math.PI - self.direction + (Math.random() - 0.5) * 0.5;
}
if (self.x > 2048 - margin) {
self.x = 2048 - margin;
self.direction = Math.PI - self.direction + (Math.random() - 0.5) * 0.5;
}
if (self.y < margin + 100) {
// leave top 100px for menu
self.y = margin + 100;
self.direction = -self.direction + (Math.random() - 0.5) * 0.5;
}
if (self.y > 2732 - margin) {
self.y = 2732 - margin;
self.direction = -self.direction + (Math.random() - 0.5) * 0.5;
}
// Change direction randomly
self.changeDirTimer--;
if (self.changeDirTimer <= 0) {
self.direction += (Math.random() - 0.5) * Math.PI / 1.5;
self.changeDirTimer = 30 + Math.floor(Math.random() * 60);
}
};
// When hit, play animation and destroy
self.squash = function (_onFinish) {
self.alive = false;
// Animate: scale up and fade out
tween(self, {
scaleX: 1.7,
scaleY: 0.5,
alpha: 0
}, {
duration: 250,
easing: tween.easeOut,
onFinish: function onFinish() {
if (_onFinish) {
_onFinish();
}
}
});
};
return self;
});
// Racket class: represents the player's racket
var Racket = Container.expand(function () {
var self = Container.call(this);
// Attach racket asset (rectangle, bright color)
var racketGfx = self.attachAsset('racket', {
anchorX: 0.5,
anchorY: 0.5
});
// Optionally, add a little shadow for visibility
racketGfx.alpha = 0.95;
// Racket size for collision
self.radius = racketGfx.width * 0.5;
// For touch feedback
self.flash = function () {
tween(racketGfx, {
tint: 0xffff00
}, {
duration: 80,
onFinish: function onFinish() {
tween(racketGfx, {
tint: 0xffffff
}, {
duration: 120
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xf7f7e8 // Light wall color
});
/****
* Game Code
****/
// --- Game Variables ---
// Tween plugin for smooth animations
// --- Asset Initialization ---
var mosquitoes = [];
var racket = null;
var score = 0;
var scoreTxt = null;
var timeLeft = 30; // seconds
var timerInterval = null;
var maxMosquitoes = 5;
var mosquitoesEscaped = 0;
var maxEscaped = 3;
var gameActive = true;
var dragNode = null;
// --- UI Elements ---
// Score text
scoreTxt = new Text2('0', {
size: 120,
fill: "#222"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Timer text
var timerTxt = new Text2('30', {
size: 100,
fill: "#b00"
});
timerTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timerTxt);
// Missed mosquitoes text
var missedTxt = new Text2('', {
size: 80,
fill: "#b00"
});
missedTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(missedTxt);
// --- Helper Functions ---
function spawnMosquito() {
if (!gameActive) {
return;
}
var m = new Mosquito();
// Random position, not too close to top (menu)
var margin = 80;
m.x = margin + Math.random() * (2048 - 2 * margin);
m.y = 150 + Math.random() * (2732 - 250);
mosquitoes.push(m);
game.addChild(m);
}
function updateScore() {
scoreTxt.setText(score);
}
function updateTimer() {
timerTxt.setText(timeLeft);
}
function updateMissed() {
if (mosquitoesEscaped > 0) {
missedTxt.setText('Kaçan: ' + mosquitoesEscaped + '/' + maxEscaped);
} else {
missedTxt.setText('');
}
}
function endGame(win) {
gameActive = false;
// Show win or game over
if (win) {
LK.showYouWin();
} else {
LK.showGameOver();
}
}
// --- Racket Setup ---
racket = new Racket();
game.addChild(racket);
// Start racket in center, lower half
racket.x = 2048 / 2;
racket.y = 2732 * 0.7;
// --- Touch/Drag Controls ---
game.down = function (x, y, obj) {
// Don't allow drag in top left 100x100
if (x < 100 && y < 100) {
return;
}
dragNode = racket;
// Move racket instantly to touch
racket.x = x;
racket.y = y;
};
game.move = function (x, y, obj) {
if (!gameActive) {
return;
}
if (dragNode) {
// Clamp racket inside game area (leave top 100px)
var rw = racket.width * 0.5;
var rh = racket.height * 0.5;
var nx = Math.max(rw, Math.min(2048 - rw, x));
var ny = Math.max(100 + rh, Math.min(2732 - rh, y));
racket.x = nx;
racket.y = ny;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// --- Main Game Loop ---
game.update = function () {
if (!gameActive) {
return;
}
// Update mosquitoes
for (var i = mosquitoes.length - 1; i >= 0; i--) {
var m = mosquitoes[i];
if (!m.alive) {
continue;
}
m.update();
// Check collision with racket
var dx = m.x - racket.x;
var dy = m.y - racket.y;
var dist = Math.sqrt(dx * dx + dy * dy);
var hitRadius = m.width * 0.5 + racket.width * 0.5 * 0.7;
if (dist < hitRadius) {
// Hit!
m.squash(function () {
m.destroy();
});
mosquitoes.splice(i, 1);
score += 1;
updateScore();
racket.flash();
// Win condition
if (score >= 15) {
endGame(true);
return;
}
continue;
}
// If mosquito is at edge for too long, count as escaped
var margin = m.width / 2 + 10;
if (m.x <= margin + 2 || m.x >= 2048 - margin - 2 || m.y <= margin + 102 || m.y >= 2732 - margin - 2) {
// Escaped!
m.alive = false;
tween(m, {
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
m.destroy();
}
});
mosquitoes.splice(i, 1);
mosquitoesEscaped += 1;
updateMissed();
// Lose condition
if (mosquitoesEscaped >= maxEscaped) {
endGame(false);
return;
}
}
}
// Spawn new mosquitoes if needed
if (mosquitoes.length < maxMosquitoes && gameActive) {
if (Math.random() < 0.04) {
// ~1 every 25 frames
spawnMosquito();
}
}
};
// --- Timer ---
function startTimer() {
timeLeft = 30;
updateTimer();
if (timerInterval) {
LK.clearInterval(timerInterval);
}
timerInterval = LK.setInterval(function () {
if (!gameActive) {
LK.clearInterval(timerInterval);
return;
}
timeLeft--;
updateTimer();
if (timeLeft <= 0) {
endGame(false);
LK.clearInterval(timerInterval);
}
}, 1000);
}
// --- Game Start ---
score = 0;
mosquitoesEscaped = 0;
updateScore();
updateMissed();
updateTimer();
for (var i = 0; i < maxMosquitoes; i++) {
spawnMosquito();
}
startTimer(); ===================================================================
--- original.js
+++ change.js
@@ -1,12 +1,8 @@
/****
-* Plugins
-****/
-var tween = LK.import("@upit/tween.v1");
-
-/****
* Classes
****/
+//var tween = LK.import("@upit/tween.v1");
// Mosquito class: represents a single mosquito
var Mosquito = Container.expand(function () {
var self = Container.call(this);
// Attach mosquito asset (ellipse, small, dark color)
@@ -64,9 +60,11 @@
}, {
duration: 250,
easing: tween.easeOut,
onFinish: function onFinish() {
- if (_onFinish) _onFinish();
+ if (_onFinish) {
+ _onFinish();
+ }
}
});
};
return self;
@@ -148,9 +146,11 @@
missedTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(missedTxt);
// --- Helper Functions ---
function spawnMosquito() {
- if (!gameActive) return;
+ if (!gameActive) {
+ return;
+ }
var m = new Mosquito();
// Random position, not too close to top (menu)
var margin = 80;
m.x = margin + Math.random() * (2048 - 2 * margin);
@@ -188,16 +188,20 @@
racket.y = 2732 * 0.7;
// --- Touch/Drag Controls ---
game.down = function (x, y, obj) {
// Don't allow drag in top left 100x100
- if (x < 100 && y < 100) return;
+ if (x < 100 && y < 100) {
+ return;
+ }
dragNode = racket;
// Move racket instantly to touch
racket.x = x;
racket.y = y;
};
game.move = function (x, y, obj) {
- if (!gameActive) return;
+ if (!gameActive) {
+ return;
+ }
if (dragNode) {
// Clamp racket inside game area (leave top 100px)
var rw = racket.width * 0.5;
var rh = racket.height * 0.5;
@@ -211,13 +215,17 @@
dragNode = null;
};
// --- Main Game Loop ---
game.update = function () {
- if (!gameActive) return;
+ if (!gameActive) {
+ return;
+ }
// Update mosquitoes
for (var i = mosquitoes.length - 1; i >= 0; i--) {
var m = mosquitoes[i];
- if (!m.alive) continue;
+ if (!m.alive) {
+ continue;
+ }
m.update();
// Check collision with racket
var dx = m.x - racket.x;
var dy = m.y - racket.y;
@@ -273,9 +281,11 @@
// --- Timer ---
function startTimer() {
timeLeft = 30;
updateTimer();
- if (timerInterval) LK.clearInterval(timerInterval);
+ if (timerInterval) {
+ LK.clearInterval(timerInterval);
+ }
timerInterval = LK.setInterval(function () {
if (!gameActive) {
LK.clearInterval(timerInterval);
return;
sivrisinek. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
racket sivriseinek için . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
arı. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat