User prompt
oyuncu bir sineği öldürmeden diğer bir sinek çıkmayacak,oyuncu ilk çıkan sineği öldürdükten hemen sonra diğer sinek çıkacak
User prompt
bütün sineklerin hızını biraz daha arttır
User prompt
sineklerin hızını arttır
Code edit (1 edits merged)
Please save this source code
User prompt
Froggy Fly Catcher
Initial prompt
bir platformun üstünde duran ana karakterimiz olan kurbağa,üstünde uçuşan sinekleri dilini uzatarak yakalamaya çalışıyor
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.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 = 6; self.directionX = (Math.random() - 0.5) * 2; self.directionY = (Math.random() - 0.5) * 2; self.update = function () { self.x += self.speed * self.directionX; self.y += self.speed * self.directionY; // Bounce off edges if (self.x < 50 || self.x > 2048 - 50) self.directionX *= -1; if (self.y < 50 || self.y > 2732 - 50) self.directionY *= -1; }; return self; }); var Frog = Container.expand(function () { var self = Container.call(this); var frogGraphics = self.attachAsset('frog', { anchorX: 0.5, anchorY: 0.5 }); self.canShoot = true; self.tongue = null; self.shootTongue = function (targetX, targetY) { if (!self.canShoot) return; self.canShoot = false; self.tongue = self.addChild(LK.getAsset('tongue', { anchorX: 0.5, anchorY: 1.0 })); // Position tongue at the mouth self.tongue.x = 0; self.tongue.y = -self.height / 2; // Assuming tongue comes from top of frog head // Calculate distance and angle var dx = targetX - self.x; var dy = targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); var angle = Math.atan2(dy, dx) + Math.PI / 2; // Add PI/2 because tongue asset is vertical self.tongue.rotation = angle; self.tongue.height = 0; // Start tongue retracted // Extend tongue tween(self.tongue, { height: distance }, { duration: 300, onFinish: function onFinish() { // Retract tongue tween(self.tongue, { height: 0 }, { duration: 300, onFinish: function onFinish() { self.removeChild(self.tongue); self.tongue = null; self.canShoot = true; } }); } }); }; return self; }); //Library for using the camera (the background becomes the user's camera video feed) and the microphone. It can access face coordinates for interactive play, as well detect microphone volume / voice interactions // var facekit = LK.import('@upit/facekit.v1'); //Classes can only be defined here. You cannot create inline classes in the games code. var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xADD8E6 // Light blue background }); /**** * Game Code ****/ //Storage library which should be used for persistent game data //Minimalistic tween library which should be used for animations over time, including tinting / colouring an object, scaling, rotating, or changing any game object property. //Only include the plugins you need to create the game. //We have access to the following plugins. (Note that the variable names used are mandetory for each plugin) // Initialize music // Initialize assets used in this game. Scale them according to what is needed for the game. // or via static code analysis based on their usage in the code. // Assets are automatically created and loaded either dynamically during gameplay /* Supported Types: 1. Shape: - Simple geometric figures with these properties: * width: (required) pixel width of the shape. * height: (required) pixel height of the shape. * color: (required) color of the shape. * shape: (required) type of shape. Valid options: 'box', 'ellipse'. 2. Image: - Imported images with these properties: * width: (required) pixel resolution width. * height: (required) pixel resolution height. * id: (required) identifier for the image. * flipX: (optional) horizontal flip. Valid values: 0 (no flip), 1 (flip). * flipY: (optional) vertical flip. Valid values: 0 (no flip), 1 (flip). * orientation: (optional) rotation in multiples of 90 degrees, clockwise. Valid values: - 0: No rotation. - 1: Rotate 90 degrees. - 2: Rotate 180 degrees. - 3: Rotate 270 degrees. Note: Width and height remain unchanged upon flipping. 3. Sound: - Sound effects with these properties: * id: (required) identifier for the sound. * volume: (optional) custom volume. Valid values are a float from 0 to 1. 4. Music: - In contract to sound effects, only one music can be played at a time - Music is using the same API to initilize just like sound. - Music loops by default - Music with these config options: * id: (required) identifier for the sound. * volume: (optional) custom volume. Valid values are a float from 0 to 1. * start: (optional) a float from 0 to 1 used for cropping and indicates the start of the cropping * end: (optional) a float from 0 to 1 used for cropping and indicates the end of the cropping */ //Note game dimensions are 2048x2732 game.setBackgroundColor(0xADD8E6); var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.setText(LK.getScore()); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var platform = game.addChild(new Platform()); platform.x = 2048 / 2; platform.y = 2732 - platform.height / 2 - 50; // Position platform near the bottom var frog = game.addChild(new Frog()); frog.x = platform.x; frog.y = platform.y - platform.height / 2 - frog.height / 2 + 20; // Position frog on the platform var flies = []; var flySpawnTimer; var catchSound = LK.getSound('catchFly'); var missSound = LK.getSound('miss'); function spawnFly() { var newFly = new Fly(); newFly.x = Math.random() * (2048 - 100) + 50; newFly.y = Math.random() * (2732 - 300) + 50; // Avoid spawning too close to the platform newFly.lastIntersecting = false; flies.push(newFly); game.addChild(newFly); } // Start spawning flies LK.clearInterval(flySpawnTimer); // Stop the initial fly spawn timer spawnFly(); // Spawn the first fly immediately game.down = function (x, y, obj) { // Shoot tongue towards touch location frog.shootTongue(x, y); }; game.update = function () { // Update and check for collisions between tongue and flies if (frog.tongue) { for (var i = flies.length - 1; i >= 0; i--) { var fly = flies[i]; // Check if fly is in the game area and not pending destruction if (fly.parent === game) { var currentIntersecting = frog.tongue.intersects(fly); if (!fly.lastIntersecting && currentIntersecting) { // Fly caught! LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); catchSound.play(); // Remove fly fly.destroy(); flies.splice(i, 1); spawnFly(); // Spawn a new fly after a successful catch // Increase speed slightly for challenge Fly.prototype.speed += 0.3; continue; // Skip further checks for this fly } fly.lastIntersecting = currentIntersecting; } } } // Update all flies for (var i = flies.length - 1; i >= 0; i--) { var fly = flies[i]; if (fly.update) { fly.update(); } } }; // Play background music LK.playMusic('bgMusic');
===================================================================
--- original.js
+++ change.js
@@ -164,9 +164,10 @@
flies.push(newFly);
game.addChild(newFly);
}
// Start spawning flies
-flySpawnTimer = LK.setInterval(spawnFly, 2000); // Spawn a new fly every 2 seconds
+LK.clearInterval(flySpawnTimer); // Stop the initial fly spawn timer
+spawnFly(); // Spawn the first fly immediately
game.down = function (x, y, obj) {
// Shoot tongue towards touch location
frog.shootTongue(x, y);
};
@@ -185,8 +186,9 @@
catchSound.play();
// Remove fly
fly.destroy();
flies.splice(i, 1);
+ spawnFly(); // Spawn a new fly after a successful catch
// Increase speed slightly for challenge
Fly.prototype.speed += 0.3;
continue; // Skip further checks for this fly
}