User prompt
sineklere vurmak için ekrana mouse ile kontrol edilen bir sineklik yerleştirelim
User prompt
sinekler random hareket etsin ve ekranda en fazla 5 saniye kalsın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Fly Swatter
Initial prompt
bir oyun yapalım bu oyunda amaç sinek avlamak olsun
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Fly = Container.expand(function () {
var self = Container.call(this);
var flyGraphics = self.attachAsset('fly', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2 + Math.random() * 3;
self.directionX = (Math.random() - 0.5) * 2;
self.directionY = (Math.random() - 0.5) * 2;
self.timeAlive = 0;
self.maxLifetime = 2000 + Math.random() * 3000; // 2-5 seconds max
self.buzzTimer = 0;
self.isSwatted = false;
// Normalize direction
var length = Math.sqrt(self.directionX * self.directionX + self.directionY * self.directionY);
if (length > 0) {
self.directionX /= length;
self.directionY /= length;
}
self.update = function () {
if (self.isSwatted) return;
self.timeAlive += 16.67; // ~60fps
// Change direction randomly - more frequent and erratic
if (Math.random() < 0.05) {
self.directionX += (Math.random() - 0.5) * 0.8;
self.directionY += (Math.random() - 0.5) * 0.8;
// Normalize direction to prevent flies from moving too fast
var length = Math.sqrt(self.directionX * self.directionX + self.directionY * self.directionY);
if (length > 1) {
self.directionX /= length;
self.directionY /= length;
}
}
// Add random sudden direction changes for more realistic fly movement
if (Math.random() < 0.01) {
self.directionX = (Math.random() - 0.5) * 2;
self.directionY = (Math.random() - 0.5) * 2;
}
// Add speed variation for more random movement
var speedMultiplier = 0.7 + Math.random() * 0.6; // Random speed between 70% and 130%
// Move fly
self.x += self.directionX * self.speed * speedMultiplier;
self.y += self.directionY * self.speed * speedMultiplier;
// Bounce off walls
if (self.x < 50 || self.x > 1998) {
self.directionX *= -1;
self.x = Math.max(50, Math.min(1998, self.x));
}
if (self.y < 50 || self.y > 2682) {
self.directionY *= -1;
self.y = Math.max(50, Math.min(2682, self.y));
}
// Buzzing sound effect
self.buzzTimer += 16.67;
if (self.buzzTimer > 1000 + Math.random() * 2000) {
LK.getSound('buzz').play();
self.buzzTimer = 0;
}
// Slight rotation for buzzing effect
flyGraphics.rotation += 0.1;
// Check if lifetime expired
if (self.timeAlive > self.maxLifetime) {
self.escape();
}
};
self.escape = function () {
if (!self.isSwatted) {
missedFlies++;
LK.getSound('miss').play();
}
self.destroy();
for (var i = flies.length - 1; i >= 0; i--) {
if (flies[i] === self) {
flies.splice(i, 1);
break;
}
}
};
self.swat = function () {
if (self.isSwatted) return;
self.isSwatted = true;
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
// Visual feedback
tween(flyGraphics, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
self.destroy();
for (var i = flies.length - 1; i >= 0; i--) {
if (flies[i] === self) {
flies.splice(i, 1);
break;
}
}
}
});
};
self.down = function (x, y, obj) {
// Flies no longer handle their own swatting - this is now handled by the swatter
};
return self;
});
var Swatter = Container.expand(function () {
var self = Container.call(this);
// Create swatter head
var swatterHead = self.attachAsset('swatter', {
anchorX: 0.5,
anchorY: 0.5
});
// Create swatter handle
var swatterHandle = self.attachAsset('swatterHandle', {
anchorX: 0.5,
anchorY: 1
});
// Position handle below the swatter head
swatterHandle.x = 0;
swatterHandle.y = 60;
// Swatting animation
self.swat = function () {
// Quick scale animation for swatting effect
tween(swatterHead, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 100,
onFinish: function onFinish() {
tween(swatterHead, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xf0f8ff
});
/****
* Game Code
****/
var flies = [];
var spawnTimer = 0;
var spawnInterval = 2000; // Start with 2 seconds between spawns
var missedFlies = 0;
var maxMissedFlies = 10;
var gameDifficulty = 1;
// Score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0x333333
});
scoreTxt.setText(LK.getScore());
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Missed flies counter
var missedTxt = new Text2('Missed: 0/' + maxMissedFlies, {
size: 80,
fill: 0xCC0000
});
missedTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(missedTxt);
function spawnFly() {
var fly = new Fly();
// Spawn at random edge of screen
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top
fly.x = Math.random() * 2048;
fly.y = 50;
break;
case 1:
// Right
fly.x = 1998;
fly.y = Math.random() * 2732;
break;
case 2:
// Bottom
fly.x = Math.random() * 2048;
fly.y = 2682;
break;
case 3:
// Left
fly.x = 50;
fly.y = Math.random() * 2732;
break;
}
flies.push(fly);
game.addChild(fly);
}
function increaseDifficulty() {
gameDifficulty += 0.1;
spawnInterval = Math.max(800, 2000 / gameDifficulty); // Minimum 0.8 seconds
// Increase fly speed for new flies
for (var i = 0; i < flies.length; i++) {
flies[i].speed = Math.min(flies[i].speed * 1.05, 8);
}
}
game.update = function () {
// Update missed flies display
missedTxt.setText('Missed: ' + missedFlies + '/' + maxMissedFlies);
// Check game over condition
if (missedFlies >= maxMissedFlies) {
LK.showGameOver();
return;
}
// Spawn new flies
spawnTimer += 16.67;
if (spawnTimer >= spawnInterval) {
spawnFly();
spawnTimer = 0;
}
// Increase difficulty every 10 seconds
if (LK.ticks % 600 === 0) {
increaseDifficulty();
}
// Limit number of flies on screen
if (flies.length > 15) {
var oldestFly = flies[0];
oldestFly.escape();
}
};
// Create swatter that follows mouse
var swatter = new Swatter();
game.addChild(swatter);
// Mouse move handler to move swatter
game.move = function (x, y, obj) {
swatter.x = x;
swatter.y = y;
};
// Mouse down handler for swatting
game.down = function (x, y, obj) {
swatter.swat();
// Check if we hit any flies
for (var i = flies.length - 1; i >= 0; i--) {
var fly = flies[i];
var distance = Math.sqrt((fly.x - x) * (fly.x - x) + (fly.y - y) * (fly.y - y));
if (distance < 80) {
// Hit radius
fly.swat();
LK.getSound('swat').play();
break;
}
}
};
// Initial fly spawn
spawnFly(); ===================================================================
--- original.js
+++ change.js
@@ -107,27 +107,42 @@
}
});
};
self.down = function (x, y, obj) {
- self.swat();
- LK.getSound('swat').play();
- // Show swatter effect
- var swatter = LK.getAsset('swatter', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.8
- });
- game.addChild(swatter);
- swatter.x = self.x;
- swatter.y = self.y;
- tween(swatter, {
- scaleX: 1.5,
- scaleY: 1.5,
- alpha: 0
+ // Flies no longer handle their own swatting - this is now handled by the swatter
+ };
+ return self;
+});
+var Swatter = Container.expand(function () {
+ var self = Container.call(this);
+ // Create swatter head
+ var swatterHead = self.attachAsset('swatter', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create swatter handle
+ var swatterHandle = self.attachAsset('swatterHandle', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ // Position handle below the swatter head
+ swatterHandle.x = 0;
+ swatterHandle.y = 60;
+ // Swatting animation
+ self.swat = function () {
+ // Quick scale animation for swatting effect
+ tween(swatterHead, {
+ scaleX: 1.3,
+ scaleY: 1.3
}, {
- duration: 300,
+ duration: 100,
onFinish: function onFinish() {
- swatter.destroy();
+ tween(swatterHead, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100
+ });
}
});
};
return self;
@@ -224,6 +239,29 @@
var oldestFly = flies[0];
oldestFly.escape();
}
};
+// Create swatter that follows mouse
+var swatter = new Swatter();
+game.addChild(swatter);
+// Mouse move handler to move swatter
+game.move = function (x, y, obj) {
+ swatter.x = x;
+ swatter.y = y;
+};
+// Mouse down handler for swatting
+game.down = function (x, y, obj) {
+ swatter.swat();
+ // Check if we hit any flies
+ for (var i = flies.length - 1; i >= 0; i--) {
+ var fly = flies[i];
+ var distance = Math.sqrt((fly.x - x) * (fly.x - x) + (fly.y - y) * (fly.y - y));
+ if (distance < 80) {
+ // Hit radius
+ fly.swat();
+ LK.getSound('swat').play();
+ break;
+ }
+ }
+};
// Initial fly spawn
spawnFly();
\ No newline at end of file
2 boyutlu ve renkli bir plastik sineklik
level complete background. In-Game asset. 2d. High contrast. No shadows
crushed fly In-Game asset. 2d. High contrast. No shadows
arkaplan için geniş bir zemin gerçekçi bir salon genellikle pencere kapı koltuk gibi şeyler olsun. In-Game asset. 2d. High contrast. No shadows
arkaplan için gerçekçi bir oda içinde çalışma masası bilgisayar pencere kapı gibi şeyler olsun. yüksek çözünürlüklü ve gerçekçi olması gerekiyor In-Game asset. 2d. High contrast. No shadows
gerçekçi bir orman ambiyansı tam ortasında büyük bir böcek yuvası olan ve yeşil tonlarında. In-Game asset. 2d. High contrast. No shadows
ezilmiş bir böcek. In-Game asset. 2d. High contrast. No shadows
next level button. In-Game asset. 2d. High contrast. No shadows