User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'alpha')' in or related to this line: 'scoreTxt.alpha = 0;' Line Number: 132
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'setText')' in or related to this line: 'bestScoreTxt.setText('Best: ' + bestScore);' Line Number: 128
User prompt
Please fix the bug: 'storage.get is not a function' in or related to this line: 'var bestScore = storage.get('bestScore') || 0;' Line Number: 126 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Bir başlangıç ve bitiş menüsü yap
User prompt
Birazdaha boruları uzat tam tavana gelsin
User prompt
Boruların boyunu uzat tam tavana ve zemine denk gelsin
User prompt
Borular arasındaki mesafeyi biraz daha artır ve kalınlaşma uygula
User prompt
Borular arasındaki mesafeyi artır
User prompt
Kuş arasından geçmiyor onu düzelt
User prompt
Stünlar arasındaki boşluğu artır ve tam olsun
User prompt
Bir Flappy bird oyunu yap
Code edit (1 edits merged)
Please save this source code
User prompt
Perfect Ring Drop
Initial prompt
İşaret parmağını bir delikten geçir o delikte vajina olsun
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Bird = Container.expand(function () { var self = Container.call(this); var birdSprite = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.velocityY = 0; self.gravity = 0.8; self.flapStrength = -12; self.isDead = false; self.lastY = 0; self.flap = function () { if (!self.isDead) { self.velocityY = self.flapStrength; LK.getSound('flap').play(); } }; self.update = function () { if (!self.isDead) { self.lastY = self.y; self.velocityY += self.gravity; self.y += self.velocityY; // Rotate bird based on velocity birdSprite.rotation = Math.max(-0.5, Math.min(0.5, self.velocityY * 0.1)); // Check ground collision if (self.y > groundY - 40) { self.y = groundY - 40; self.die(); } // Check ceiling collision if (self.y < 40) { self.y = 40; self.velocityY = 0; } } }; self.die = function () { if (!self.isDead) { self.isDead = true; LK.getSound('hit').play(); LK.setTimeout(function () { LK.showGameOver(); }, 1000); } }; return self; }); var Pipe = Container.expand(function (pipeX, gapY) { var self = Container.call(this); var topPipe = self.attachAsset('pipe', { anchorX: 0.5, anchorY: 1.0, y: gapY - 150 }); var bottomPipe = self.attachAsset('pipe', { anchorX: 0.5, anchorY: 0.0, y: gapY + 150 }); self.x = pipeX; self.speed = -4; self.scored = false; self.lastX = pipeX; self.update = function () { self.lastX = self.x; self.x += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Game variables var bird; var pipes = []; var groundY = 2632; var pipeSpawnTimer = 0; var pipeSpawnInterval = 90; var gameStarted = false; // Create ground var ground = game.addChild(LK.getAsset('ground', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: groundY + 50 })); // Create bird bird = new Bird(); bird.x = 300; bird.y = 1366; game.addChild(bird); // Create score display var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); scoreTxt.y = 100; LK.gui.top.addChild(scoreTxt); // Create instructions var instructionTxt = new Text2('Tap to flap!', { size: 60, fill: 0xFFFFFF }); instructionTxt.anchor.set(0.5, 0); instructionTxt.y = 300; LK.gui.top.addChild(instructionTxt); function spawnPipe() { var gapY = 800 + Math.random() * 1200; var pipe = new Pipe(2200, gapY); pipes.push(pipe); game.addChild(pipe); } function checkCollisions() { if (bird.isDead) return; for (var i = 0; i < pipes.length; i++) { var pipe = pipes[i]; // Check if bird passes through pipe gap for scoring if (!pipe.scored && pipe.lastX > bird.x && pipe.x <= bird.x) { pipe.scored = true; LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore().toString()); LK.getSound('score').play(); } // Check collision with pipes if (bird.x + 30 > pipe.x - 60 && bird.x - 30 < pipe.x + 60) { // Check top pipe collision if (bird.y - 30 < pipe.children[0].y + 400) { bird.die(); return; } // Check bottom pipe collision if (bird.y + 30 > pipe.children[1].y - 400) { bird.die(); return; } } } } function cleanupPipes() { for (var i = pipes.length - 1; i >= 0; i--) { if (pipes[i].x < -200) { pipes[i].destroy(); pipes.splice(i, 1); } } } game.down = function (x, y, obj) { if (!gameStarted) { gameStarted = true; instructionTxt.alpha = 0; } bird.flap(); }; game.update = function () { if (!gameStarted) return; // Spawn pipes pipeSpawnTimer++; if (pipeSpawnTimer >= pipeSpawnInterval) { spawnPipe(); pipeSpawnTimer = 0; } // Check collisions and scoring checkCollisions(); // Clean up off-screen pipes cleanupPipes(); };
===================================================================
--- original.js
+++ change.js
@@ -5,76 +5,77 @@
/****
* Classes
****/
-var Peg = Container.expand(function (pegX, pegY) {
+var Bird = Container.expand(function () {
var self = Container.call(this);
- var pegBody = self.attachAsset('peg', {
+ var birdSprite = self.attachAsset('bird', {
anchorX: 0.5,
- anchorY: 1.0
- });
- var pegTop = self.attachAsset('pegTop', {
- anchorX: 0.5,
- anchorY: 0.5,
- y: -90
- });
- self.x = pegX;
- self.y = pegY;
- self.hasRing = false;
- return self;
-});
-var Ring = Container.expand(function () {
- var self = Container.call(this);
- var ringOuter = self.attachAsset('ring', {
- anchorX: 0.5,
anchorY: 0.5
});
- var ringInner = self.attachAsset('ringHole', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.velocityX = 0;
self.velocityY = 0;
- self.gravity = 0.5;
- self.bounceReduction = 0.7;
- self.isBeingDragged = false;
- self.isDropped = false;
- self.isScored = false;
+ self.gravity = 0.8;
+ self.flapStrength = -12;
+ self.isDead = false;
self.lastY = 0;
+ self.flap = function () {
+ if (!self.isDead) {
+ self.velocityY = self.flapStrength;
+ LK.getSound('flap').play();
+ }
+ };
self.update = function () {
- if (self.isDropped && !self.isBeingDragged) {
+ if (!self.isDead) {
self.lastY = self.y;
- // Apply gravity
self.velocityY += self.gravity;
- // Update position
- self.x += self.velocityX;
self.y += self.velocityY;
- // Ground collision
- if (self.y > groundY - 60) {
- self.y = groundY - 60;
- self.velocityY *= -self.bounceReduction;
- self.velocityX *= 0.9;
- if (Math.abs(self.velocityY) > 2) {
- LK.getSound('bounce').play();
- }
+ // Rotate bird based on velocity
+ birdSprite.rotation = Math.max(-0.5, Math.min(0.5, self.velocityY * 0.1));
+ // Check ground collision
+ if (self.y > groundY - 40) {
+ self.y = groundY - 40;
+ self.die();
}
- // Side boundaries
- if (self.x < 60) {
- self.x = 60;
- self.velocityX *= -self.bounceReduction;
- } else if (self.x > 2048 - 60) {
- self.x = 2048 - 60;
- self.velocityX *= -self.bounceReduction;
- }
- // Check if ring settles (very low velocity)
- if (Math.abs(self.velocityX) < 0.5 && Math.abs(self.velocityY) < 0.5 && self.y > groundY - 70) {
- self.velocityX = 0;
+ // Check ceiling collision
+ if (self.y < 40) {
+ self.y = 40;
self.velocityY = 0;
}
}
};
+ self.die = function () {
+ if (!self.isDead) {
+ self.isDead = true;
+ LK.getSound('hit').play();
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 1000);
+ }
+ };
return self;
});
+var Pipe = Container.expand(function (pipeX, gapY) {
+ var self = Container.call(this);
+ var topPipe = self.attachAsset('pipe', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ y: gapY - 150
+ });
+ var bottomPipe = self.attachAsset('pipe', {
+ anchorX: 0.5,
+ anchorY: 0.0,
+ y: gapY + 150
+ });
+ self.x = pipeX;
+ self.speed = -4;
+ self.scored = false;
+ self.lastX = pipeX;
+ self.update = function () {
+ self.lastX = self.x;
+ self.x += self.speed;
+ };
+ return self;
+});
/****
* Initialize Game
****/
@@ -85,178 +86,98 @@
/****
* Game Code
****/
// Game variables
-var rings = [];
-var pegs = [];
-var currentRing = null;
-var dragStartX = 0;
-var dragStartY = 0;
-var isDragging = false;
-var ringDropped = false;
-var ringCount = 5;
-var ringsUsed = 0;
-var groundY = 2600;
-var pegPositions = [{
- x: 400,
- y: groundY
-}, {
- x: 800,
- y: groundY
-}, {
- x: 1200,
- y: groundY
-}, {
- x: 1600,
- y: groundY
-}];
+var bird;
+var pipes = [];
+var groundY = 2632;
+var pipeSpawnTimer = 0;
+var pipeSpawnInterval = 90;
+var gameStarted = false;
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
- y: groundY + 25
+ y: groundY + 50
}));
-// Create pegs
-for (var i = 0; i < pegPositions.length; i++) {
- var peg = new Peg(pegPositions[i].x, pegPositions[i].y);
- pegs.push(peg);
- game.addChild(peg);
-}
+// Create bird
+bird = new Bird();
+bird.x = 300;
+bird.y = 1366;
+game.addChild(bird);
// Create score display
-var scoreTxt = new Text2('Score: 0', {
- size: 80,
+var scoreTxt = new Text2('0', {
+ size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
+scoreTxt.y = 100;
LK.gui.top.addChild(scoreTxt);
-// Create rings counter
-var ringsTxt = new Text2('Rings: ' + ringCount, {
+// Create instructions
+var instructionTxt = new Text2('Tap to flap!', {
size: 60,
fill: 0xFFFFFF
});
-ringsTxt.anchor.set(1, 0);
-ringsTxt.x = -50;
-ringsTxt.y = 100;
-LK.gui.topRight.addChild(ringsTxt);
-// Create instructions
-var instructionTxt = new Text2('Drag to aim, release to drop!', {
- size: 50,
- fill: 0xFFFFFF
-});
instructionTxt.anchor.set(0.5, 0);
-instructionTxt.y = 200;
+instructionTxt.y = 300;
LK.gui.top.addChild(instructionTxt);
-function createNewRing() {
- if (ringsUsed >= ringCount) {
- // Check if all rings are settled
- var allSettled = true;
- for (var i = 0; i < rings.length; i++) {
- if (Math.abs(rings[i].velocityX) > 0.1 || Math.abs(rings[i].velocityY) > 0.1) {
- allSettled = false;
- break;
+function spawnPipe() {
+ var gapY = 800 + Math.random() * 1200;
+ var pipe = new Pipe(2200, gapY);
+ pipes.push(pipe);
+ game.addChild(pipe);
+}
+function checkCollisions() {
+ if (bird.isDead) return;
+ for (var i = 0; i < pipes.length; i++) {
+ var pipe = pipes[i];
+ // Check if bird passes through pipe gap for scoring
+ if (!pipe.scored && pipe.lastX > bird.x && pipe.x <= bird.x) {
+ pipe.scored = true;
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore().toString());
+ LK.getSound('score').play();
+ }
+ // Check collision with pipes
+ if (bird.x + 30 > pipe.x - 60 && bird.x - 30 < pipe.x + 60) {
+ // Check top pipe collision
+ if (bird.y - 30 < pipe.children[0].y + 400) {
+ bird.die();
+ return;
}
+ // Check bottom pipe collision
+ if (bird.y + 30 > pipe.children[1].y - 400) {
+ bird.die();
+ return;
+ }
}
- if (allSettled) {
- LK.setTimeout(function () {
- if (LK.getScore() >= pegs.length * 100) {
- LK.showYouWin();
- } else {
- LK.showGameOver();
- }
- }, 1000);
- }
- return;
}
- currentRing = new Ring();
- currentRing.x = 1024;
- currentRing.y = 400;
- rings.push(currentRing);
- game.addChild(currentRing);
- ringDropped = false;
}
-function checkRingScoring() {
- for (var r = 0; r < rings.length; r++) {
- var ring = rings[r];
- if (ring.isScored) continue;
- for (var p = 0; p < pegs.length; p++) {
- var peg = pegs[p];
- if (peg.hasRing) continue;
- var dx = ring.x - peg.x;
- var dy = ring.y - (peg.y - 50);
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < 40 && Math.abs(ring.velocityX) < 1 && Math.abs(ring.velocityY) < 1) {
- // Ring successfully landed on peg
- ring.isScored = true;
- peg.hasRing = true;
- ring.x = peg.x;
- ring.y = peg.y - 50;
- ring.velocityX = 0;
- ring.velocityY = 0;
- LK.setScore(LK.getScore() + 100);
- scoreTxt.setText('Score: ' + LK.getScore());
- LK.getSound('score').play();
- // Visual feedback
- tween(ring, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: 200,
- onFinish: function onFinish() {
- tween(ring, {
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 200
- });
- }
- });
- break;
- }
+function cleanupPipes() {
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ if (pipes[i].x < -200) {
+ pipes[i].destroy();
+ pipes.splice(i, 1);
}
}
}
-// Initialize first ring
-createNewRing();
game.down = function (x, y, obj) {
- if (currentRing && !ringDropped) {
- var ringPos = currentRing.parent.toGlobal(currentRing.position);
- var gamePos = game.toLocal(ringPos);
- var dx = x - gamePos.x;
- var dy = y - gamePos.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < 80) {
- isDragging = true;
- currentRing.isBeingDragged = true;
- dragStartX = x;
- dragStartY = y;
- }
+ if (!gameStarted) {
+ gameStarted = true;
+ instructionTxt.alpha = 0;
}
+ bird.flap();
};
-game.move = function (x, y, obj) {
- if (isDragging && currentRing && !ringDropped) {
- currentRing.x = x;
- currentRing.y = y;
- }
-};
-game.up = function (x, y, obj) {
- if (isDragging && currentRing && !ringDropped) {
- isDragging = false;
- currentRing.isBeingDragged = false;
- currentRing.isDropped = true;
- ringDropped = true;
- // Calculate velocity based on drag
- var velocityMultiplier = 0.3;
- currentRing.velocityX = (x - dragStartX) * velocityMultiplier;
- currentRing.velocityY = (y - dragStartY) * velocityMultiplier;
- LK.getSound('drop').play();
- ringsUsed++;
- ringsTxt.setText('Rings: ' + (ringCount - ringsUsed));
- // Create next ring after a delay
- LK.setTimeout(function () {
- createNewRing();
- }, 500);
- }
-};
game.update = function () {
- checkRingScoring();
+ if (!gameStarted) return;
+ // Spawn pipes
+ pipeSpawnTimer++;
+ if (pipeSpawnTimer >= pipeSpawnInterval) {
+ spawnPipe();
+ pipeSpawnTimer = 0;
+ }
+ // Check collisions and scoring
+ checkCollisions();
+ // Clean up off-screen pipes
+ cleanupPipes();
};
\ No newline at end of file