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;
if (!chosenType) {
// 1 in 75 chance for power-up balloon
if (Math.random() < 1 / 75) {
chosenType = 'powerUpBalloon';
} else {
chosenType = 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 if (chosenType === 'powerUpBalloon') {
self.speed = 1.2;
self.points = 25;
self.isPowerUp = true;
} 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;
if (self.isPowerUp) {
LK.getSound('powerup').play();
// Activate double bullets for 5 seconds
doubleBulletsActive = true;
doubleBulletsTimer = 300; // 5 seconds at 60fps
} else {
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;
var doubleBulletsActive = false;
var doubleBulletsTimer = 0;
// 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(s)
if (doubleBulletsActive) {
// Shoot two bullets slightly apart
var bullet1 = new Bullet();
bullet1.x = x - 30;
bullet1.y = 2732 - 100;
bullet1.lastY = bullet1.y;
bullets.push(bullet1);
game.addChild(bullet1);
var bullet2 = new Bullet();
bullet2.x = x + 30;
bullet2.y = 2732 - 100;
bullet2.lastY = bullet2.y;
bullets.push(bullet2);
game.addChild(bullet2);
} else {
// Shoot single 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;
// Update double bullets timer
if (doubleBulletsActive) {
doubleBulletsTimer--;
if (doubleBulletsTimer <= 0) {
doubleBulletsActive = false;
}
}
// 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
@@ -10,10 +10,10 @@
var self = Container.call(this);
var balloonColors = ['redBalloon', 'blueBalloon', 'greenBalloon', 'yellowBalloon'];
var chosenType = balloonType;
if (!chosenType) {
- // 35% chance for power-up balloon
- if (Math.random() < 0.35) {
+ // 1 in 75 chance for power-up balloon
+ if (Math.random() < 1 / 75) {
chosenType = 'powerUpBalloon';
} else {
chosenType = balloonColors[Math.floor(Math.random() * balloonColors.length)];
}