User prompt
Cambia la probabilidad del globo rosa a 1 de 75
User prompt
ahora crea un objeto que aparezca con un 35% de Probabilidad y que al dispararle, dispararemos dos balas a la vez
Code edit (1 edits merged)
Please save this source code
User prompt
Balloon Defender
Initial prompt
Crea un juego shoter donde le disparas globos y si llegan a una linea vertical pierdes
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Balloon = Container.expand(function (balloonType) {
var self = Container.call(this);
var balloonColors = ['redBalloon', 'blueBalloon', 'greenBalloon', 'yellowBalloon'];
var chosenType = balloonType || balloonColors[Math.floor(Math.random() * balloonColors.length)];
var balloonGraphics = self.attachAsset(chosenType, {
anchorX: 0.5,
anchorY: 0.5
});
// Set balloon properties based on type
if (chosenType === 'redBalloon') {
self.speed = 1.5;
self.points = 10;
} else if (chosenType === 'blueBalloon') {
self.speed = 2.0;
self.points = 15;
} else if (chosenType === 'greenBalloon') {
self.speed = 1.0;
self.points = 5;
} else {
self.speed = 2.5;
self.points = 20;
}
self.balloonType = chosenType;
self.popped = false;
self.update = function () {
if (!self.popped) {
self.y -= self.speed;
}
};
self.pop = function () {
if (!self.popped) {
self.popped = true;
LK.getSound('pop').play();
LK.setScore(LK.getScore() + self.points);
scoreTxt.setText(LK.getScore());
// Pop animation
tween(self, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
}
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.update = function () {
self.y -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var balloons = [];
var bullets = [];
var balloonSpawnTimer = 0;
var balloonSpawnRate = 120; // frames between spawns
var dangerLineY = 200;
var gameStarted = false;
// Create danger line
var dangerLine = game.addChild(LK.getAsset('dangerLine', {
anchorX: 0,
anchorY: 0.5,
x: 0,
y: dangerLineY
}));
// Score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 60;
// Instructions text
var instructionTxt = new Text2('TAP TO SHOOT\nPOP BALLOONS BEFORE THEY REACH THE RED LINE!', {
size: 60,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 0.5);
game.addChild(instructionTxt);
instructionTxt.x = 2048 / 2;
instructionTxt.y = 2732 / 2;
// Start game on first tap
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
game.removeChild(instructionTxt);
}
// Shoot bullet
var bullet = new Bullet();
bullet.x = x;
bullet.y = 2732 - 100;
bullet.lastY = bullet.y;
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
};
// Spawn balloon function
function spawnBalloon() {
var balloon = new Balloon();
balloon.x = Math.random() * (2048 - 160) + 80; // Keep within screen bounds
balloon.y = 2732 + 50; // Start below screen
balloon.lastY = balloon.y;
balloon.lastCrossedDangerLine = false;
balloons.push(balloon);
game.addChild(balloon);
}
game.update = function () {
if (!gameStarted) return;
// Spawn balloons
balloonSpawnTimer++;
if (balloonSpawnTimer >= balloonSpawnRate) {
spawnBalloon();
balloonSpawnTimer = 0;
// Increase difficulty over time
if (balloonSpawnRate > 30) {
balloonSpawnRate -= 0.5;
}
}
// Update and check balloons
for (var i = balloons.length - 1; i >= 0; i--) {
var balloon = balloons[i];
if (balloon.popped) continue;
// Check if balloon crossed danger line
var currentCrossedDangerLine = balloon.y <= dangerLineY;
if (!balloon.lastCrossedDangerLine && currentCrossedDangerLine) {
// Game over
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
balloon.lastCrossedDangerLine = currentCrossedDangerLine;
// Remove balloons that go off top of screen
if (balloon.lastY >= -100 && balloon.y < -100) {
balloon.destroy();
balloons.splice(i, 1);
continue;
}
balloon.lastY = balloon.y;
}
// Update and check bullets
for (var j = bullets.length - 1; j >= 0; j--) {
var bullet = bullets[j];
// Remove bullets that go off screen
if (bullet.lastY >= -50 && bullet.y < -50) {
bullet.destroy();
bullets.splice(j, 1);
continue;
}
// Check bullet-balloon collisions
for (var k = balloons.length - 1; k >= 0; k--) {
var balloon = balloons[k];
if (!balloon.popped && bullet.intersects(balloon)) {
balloon.pop();
bullet.destroy();
bullets.splice(j, 1);
balloons.splice(k, 1);
break;
}
}
if (bullets[j]) {
bullet.lastY = bullet.y;
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,196 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Balloon = Container.expand(function (balloonType) {
+ var self = Container.call(this);
+ var balloonColors = ['redBalloon', 'blueBalloon', 'greenBalloon', 'yellowBalloon'];
+ var chosenType = balloonType || balloonColors[Math.floor(Math.random() * balloonColors.length)];
+ var balloonGraphics = self.attachAsset(chosenType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Set balloon properties based on type
+ if (chosenType === 'redBalloon') {
+ self.speed = 1.5;
+ self.points = 10;
+ } else if (chosenType === 'blueBalloon') {
+ self.speed = 2.0;
+ self.points = 15;
+ } else if (chosenType === 'greenBalloon') {
+ self.speed = 1.0;
+ self.points = 5;
+ } else {
+ self.speed = 2.5;
+ self.points = 20;
+ }
+ self.balloonType = chosenType;
+ self.popped = false;
+ self.update = function () {
+ if (!self.popped) {
+ self.y -= self.speed;
+ }
+ };
+ self.pop = function () {
+ if (!self.popped) {
+ self.popped = true;
+ LK.getSound('pop').play();
+ LK.setScore(LK.getScore() + self.points);
+ scoreTxt.setText(LK.getScore());
+ // Pop animation
+ tween(self, {
+ scaleX: 1.5,
+ scaleY: 1.5,
+ alpha: 0
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ }
+ };
+ return self;
+});
+var Bullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 12;
+ self.update = function () {
+ self.y -= self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var balloons = [];
+var bullets = [];
+var balloonSpawnTimer = 0;
+var balloonSpawnRate = 120; // frames between spawns
+var dangerLineY = 200;
+var gameStarted = false;
+// Create danger line
+var dangerLine = game.addChild(LK.getAsset('dangerLine', {
+ anchorX: 0,
+ anchorY: 0.5,
+ x: 0,
+ y: dangerLineY
+}));
+// Score display
+var scoreTxt = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+scoreTxt.y = 60;
+// Instructions text
+var instructionTxt = new Text2('TAP TO SHOOT\nPOP BALLOONS BEFORE THEY REACH THE RED LINE!', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+instructionTxt.anchor.set(0.5, 0.5);
+game.addChild(instructionTxt);
+instructionTxt.x = 2048 / 2;
+instructionTxt.y = 2732 / 2;
+// Start game on first tap
+game.down = function (x, y, obj) {
+ if (!gameStarted) {
+ gameStarted = true;
+ game.removeChild(instructionTxt);
+ }
+ // Shoot bullet
+ var bullet = new Bullet();
+ bullet.x = x;
+ bullet.y = 2732 - 100;
+ bullet.lastY = bullet.y;
+ bullets.push(bullet);
+ game.addChild(bullet);
+ LK.getSound('shoot').play();
+};
+// Spawn balloon function
+function spawnBalloon() {
+ var balloon = new Balloon();
+ balloon.x = Math.random() * (2048 - 160) + 80; // Keep within screen bounds
+ balloon.y = 2732 + 50; // Start below screen
+ balloon.lastY = balloon.y;
+ balloon.lastCrossedDangerLine = false;
+ balloons.push(balloon);
+ game.addChild(balloon);
+}
+game.update = function () {
+ if (!gameStarted) return;
+ // Spawn balloons
+ balloonSpawnTimer++;
+ if (balloonSpawnTimer >= balloonSpawnRate) {
+ spawnBalloon();
+ balloonSpawnTimer = 0;
+ // Increase difficulty over time
+ if (balloonSpawnRate > 30) {
+ balloonSpawnRate -= 0.5;
+ }
+ }
+ // Update and check balloons
+ for (var i = balloons.length - 1; i >= 0; i--) {
+ var balloon = balloons[i];
+ if (balloon.popped) continue;
+ // Check if balloon crossed danger line
+ var currentCrossedDangerLine = balloon.y <= dangerLineY;
+ if (!balloon.lastCrossedDangerLine && currentCrossedDangerLine) {
+ // Game over
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ balloon.lastCrossedDangerLine = currentCrossedDangerLine;
+ // Remove balloons that go off top of screen
+ if (balloon.lastY >= -100 && balloon.y < -100) {
+ balloon.destroy();
+ balloons.splice(i, 1);
+ continue;
+ }
+ balloon.lastY = balloon.y;
+ }
+ // Update and check bullets
+ for (var j = bullets.length - 1; j >= 0; j--) {
+ var bullet = bullets[j];
+ // Remove bullets that go off screen
+ if (bullet.lastY >= -50 && bullet.y < -50) {
+ bullet.destroy();
+ bullets.splice(j, 1);
+ continue;
+ }
+ // Check bullet-balloon collisions
+ for (var k = balloons.length - 1; k >= 0; k--) {
+ var balloon = balloons[k];
+ if (!balloon.popped && bullet.intersects(balloon)) {
+ balloon.pop();
+ bullet.destroy();
+ bullets.splice(j, 1);
+ balloons.splice(k, 1);
+ break;
+ }
+ }
+ if (bullets[j]) {
+ bullet.lastY = bullet.y;
+ }
+ }
+};
\ No newline at end of file