User prompt
mas grande
User prompt
que los tubos esten muy abajo
User prompt
los tubos de arriba que esten boca abajo
User prompt
pon el pajaro mas grande
User prompt
Generate the first version of the source code of my game: Flappy Wings.
User prompt
Flappy Wings
Initial prompt
dame un script para hacer un juego tipo flappy bird
/****
* Classes
****/
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = 0;
self.gravity = 0.8;
self.flapStrength = -12;
self.lastY = 0;
self.flap = function () {
self.velocity = self.flapStrength;
LK.getSound('flap').play();
};
self.update = function () {
self.lastY = self.y;
self.velocity += self.gravity;
self.y += self.velocity;
// Rotate bird based on velocity
birdGraphics.rotation = Math.max(-0.5, Math.min(0.5, self.velocity * 0.05));
// Check ground collision
if (self.y > 2732 - 150) {
gameOver();
}
// Check ceiling collision
if (self.y < 50) {
gameOver();
}
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
self.gapSize = 300;
self.speed = -4;
self.scored = false;
self.lastX = 0;
// Create top pipe
self.topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1
});
// Create bottom pipe
self.bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0
});
self.setGapPosition = function (gapY) {
self.topPipe.y = gapY - self.gapSize / 2;
self.bottomPipe.y = gapY + self.gapSize / 2;
};
self.update = function () {
self.lastX = self.x;
self.x += self.speed;
// Check if pipe passed bird (for scoring)
if (!self.scored && self.lastX > bird.x && self.x <= bird.x) {
self.scored = true;
score++;
scoreTxt.setText(score);
LK.setScore(score);
LK.getSound('score').play();
}
// Remove pipe when off screen
if (self.x < -100) {
self.destroy();
for (var i = pipes.length - 1; i >= 0; i--) {
if (pipes[i] === self) {
pipes.splice(i, 1);
break;
}
}
}
};
self.checkCollision = function (bird) {
var birdBounds = {
x: bird.x - 30,
y: bird.y - 30,
width: 60,
height: 60
};
var topPipeBounds = {
x: self.x - 60,
y: self.topPipe.y - 600,
width: 120,
height: 600
};
var bottomPipeBounds = {
x: self.x - 60,
y: self.bottomPipe.y,
width: 120,
height: 600
};
return self.intersectsBounds(birdBounds, topPipeBounds) || self.intersectsBounds(birdBounds, bottomPipeBounds);
};
self.intersectsBounds = function (rect1, rect2) {
return rect1.x < rect2.x + rect2.width && rect1.x + rect1.width > rect2.x && rect1.y < rect2.y + rect2.height && rect1.y + rect1.height > rect2.y;
};
return self;
});
/****
* Initialize Game
****/
// Game variables
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
// Initialize assets for Flappy Wings
var bird;
var pipes = [];
var ground;
var score = 0;
var scoreTxt;
var gameStarted = false;
var gameEnded = false;
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 90; // frames between pipe spawns
// Create bird
bird = game.addChild(new Bird());
bird.x = 400;
bird.y = 1366; // Center vertically
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}));
ground.x = 0;
ground.y = 2732 - 100;
// Create score display
scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 100;
// Game over function
function gameOver() {
if (!gameEnded) {
gameEnded = true;
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
}
}
// Spawn pipe function
function spawnPipe() {
var pipe = game.addChild(new Pipe());
pipe.x = 2048 + 60; // Start off screen
// Random gap position (avoid too high or too low)
var minGapY = 200;
var maxGapY = 2732 - 300;
var gapY = minGapY + Math.random() * (maxGapY - minGapY);
pipe.setGapPosition(gapY);
pipes.push(pipe);
}
// Touch/tap controls
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
}
if (!gameEnded) {
bird.flap();
}
};
// Main game loop
game.update = function () {
if (!gameStarted || gameEnded) {
return;
}
// Update bird
bird.update();
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
}
// Update pipes and check collisions
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
pipe.update();
// Check collision with bird
if (pipe.checkCollision(bird)) {
gameOver();
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,197 @@
-/****
+/****
+* Classes
+****/
+var Bird = Container.expand(function () {
+ var self = Container.call(this);
+ var birdGraphics = self.attachAsset('bird', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocity = 0;
+ self.gravity = 0.8;
+ self.flapStrength = -12;
+ self.lastY = 0;
+ self.flap = function () {
+ self.velocity = self.flapStrength;
+ LK.getSound('flap').play();
+ };
+ self.update = function () {
+ self.lastY = self.y;
+ self.velocity += self.gravity;
+ self.y += self.velocity;
+ // Rotate bird based on velocity
+ birdGraphics.rotation = Math.max(-0.5, Math.min(0.5, self.velocity * 0.05));
+ // Check ground collision
+ if (self.y > 2732 - 150) {
+ gameOver();
+ }
+ // Check ceiling collision
+ if (self.y < 50) {
+ gameOver();
+ }
+ };
+ return self;
+});
+var Pipe = Container.expand(function () {
+ var self = Container.call(this);
+ self.gapSize = 300;
+ self.speed = -4;
+ self.scored = false;
+ self.lastX = 0;
+ // Create top pipe
+ self.topPipe = self.attachAsset('pipe', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ // Create bottom pipe
+ self.bottomPipe = self.attachAsset('pipe', {
+ anchorX: 0.5,
+ anchorY: 0
+ });
+ self.setGapPosition = function (gapY) {
+ self.topPipe.y = gapY - self.gapSize / 2;
+ self.bottomPipe.y = gapY + self.gapSize / 2;
+ };
+ self.update = function () {
+ self.lastX = self.x;
+ self.x += self.speed;
+ // Check if pipe passed bird (for scoring)
+ if (!self.scored && self.lastX > bird.x && self.x <= bird.x) {
+ self.scored = true;
+ score++;
+ scoreTxt.setText(score);
+ LK.setScore(score);
+ LK.getSound('score').play();
+ }
+ // Remove pipe when off screen
+ if (self.x < -100) {
+ self.destroy();
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ if (pipes[i] === self) {
+ pipes.splice(i, 1);
+ break;
+ }
+ }
+ }
+ };
+ self.checkCollision = function (bird) {
+ var birdBounds = {
+ x: bird.x - 30,
+ y: bird.y - 30,
+ width: 60,
+ height: 60
+ };
+ var topPipeBounds = {
+ x: self.x - 60,
+ y: self.topPipe.y - 600,
+ width: 120,
+ height: 600
+ };
+ var bottomPipeBounds = {
+ x: self.x - 60,
+ y: self.bottomPipe.y,
+ width: 120,
+ height: 600
+ };
+ return self.intersectsBounds(birdBounds, topPipeBounds) || self.intersectsBounds(birdBounds, bottomPipeBounds);
+ };
+ self.intersectsBounds = function (rect1, rect2) {
+ return rect1.x < rect2.x + rect2.width && rect1.x + rect1.width > rect2.x && rect1.y < rect2.y + rect2.height && rect1.y + rect1.height > rect2.y;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
+// Game variables
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Game variables
+// Initialize assets for Flappy Wings
+var bird;
+var pipes = [];
+var ground;
+var score = 0;
+var scoreTxt;
+var gameStarted = false;
+var gameEnded = false;
+var pipeSpawnTimer = 0;
+var pipeSpawnInterval = 90; // frames between pipe spawns
+// Create bird
+bird = game.addChild(new Bird());
+bird.x = 400;
+bird.y = 1366; // Center vertically
+// Create ground
+ground = game.addChild(LK.getAsset('ground', {
+ anchorX: 0,
+ anchorY: 0
+}));
+ground.x = 0;
+ground.y = 2732 - 100;
+// Create score display
+scoreTxt = new Text2('0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+scoreTxt.y = 100;
+// Game over function
+function gameOver() {
+ if (!gameEnded) {
+ gameEnded = true;
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 500);
+ }
+}
+// Spawn pipe function
+function spawnPipe() {
+ var pipe = game.addChild(new Pipe());
+ pipe.x = 2048 + 60; // Start off screen
+ // Random gap position (avoid too high or too low)
+ var minGapY = 200;
+ var maxGapY = 2732 - 300;
+ var gapY = minGapY + Math.random() * (maxGapY - minGapY);
+ pipe.setGapPosition(gapY);
+ pipes.push(pipe);
+}
+// Touch/tap controls
+game.down = function (x, y, obj) {
+ if (!gameStarted) {
+ gameStarted = true;
+ }
+ if (!gameEnded) {
+ bird.flap();
+ }
+};
+// Main game loop
+game.update = function () {
+ if (!gameStarted || gameEnded) {
+ return;
+ }
+ // Update bird
+ bird.update();
+ // Spawn pipes
+ pipeSpawnTimer++;
+ if (pipeSpawnTimer >= pipeSpawnInterval) {
+ spawnPipe();
+ pipeSpawnTimer = 0;
+ }
+ // Update pipes and check collisions
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ var pipe = pipes[i];
+ pipe.update();
+ // Check collision with bird
+ if (pipe.checkCollision(bird)) {
+ gameOver();
+ }
+ }
+};
\ No newline at end of file