User prompt
Agrega dos botones para mover de izquierda a derecha
User prompt
Que el segundo jugador ya no se pueda controlar por tactil
User prompt
Establece un límite de velocidad para que los personajes no se teletransporte
User prompt
Que el segundo jugador sea controlado por la IA
User prompt
Que el jugador pueda saltar dos veces en el aire
User prompt
El jugador solo puede saltar una vez, arreglalo
User prompt
Arregla el salto, el jugador no puede volver a saltar al aterrizar
User prompt
Agrega un botón en pantalla para saltar y otro para golpear, solo para el jugador 1
Code edit (1 edits merged)
Please save this source code
User prompt
Battle Arena Smash
Initial prompt
Hoy quiero crear un juego estilo súper smash bros
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Fighter = Container.expand(function (playerNumber, color) { var self = Container.call(this); var fighterGraphics = self.attachAsset(playerNumber === 1 ? 'player1' : 'player2', { anchorX: 0.5, anchorY: 1.0 }); self.playerNumber = playerNumber; self.velocityX = 0; self.velocityY = 0; self.onGround = false; self.jumpsRemaining = 2; // Allow double jump self.health = 0; self.maxHealth = 100; self.moveSpeed = 8; self.jumpPower = 25; self.knockbackResistance = 1.0; self.lastHitTime = 0; self.invulnerable = false; self.takeDamage = function (damage, knockbackX, knockbackY) { if (self.invulnerable) return; self.health += damage; self.velocityX += knockbackX * (1 + self.health / 50) / self.knockbackResistance; self.velocityY += knockbackY * (1 + self.health / 50) / self.knockbackResistance; // Flash effect when hit LK.effects.flashObject(self, 0xff0000, 300); self.invulnerable = true; LK.setTimeout(function () { self.invulnerable = false; }, 500); LK.getSound('hit').play(); }; self.attack = function (targetX, targetY) { var attackRange = 150; var damage = 15; var baseKnockback = 12; for (var i = 0; i < fighters.length; i++) { var target = fighters[i]; if (target === self) continue; var distance = Math.sqrt(Math.pow(target.x - self.x, 2) + Math.pow(target.y - self.y, 2)); if (distance <= attackRange) { var angle = Math.atan2(target.y - self.y, target.x - self.x); var knockbackX = Math.cos(angle) * baseKnockback; var knockbackY = Math.sin(angle) * baseKnockback - 5; // Slight upward angle target.takeDamage(damage, knockbackX, knockbackY); } } }; self.update = function () { // Apply gravity if (!self.onGround) { self.velocityY += 1.2; } // Apply friction self.velocityX *= 0.85; if (self.onGround) { self.velocityX *= 0.75; } // Limit velocities to prevent teleportation var maxVelocityX = 20; var maxVelocityY = 30; if (self.velocityX > maxVelocityX) { self.velocityX = maxVelocityX; } if (self.velocityX < -maxVelocityX) { self.velocityX = -maxVelocityX; } if (self.velocityY > maxVelocityY) { self.velocityY = maxVelocityY; } if (self.velocityY < -maxVelocityY) { self.velocityY = -maxVelocityY; } // Update position self.x += self.velocityX; self.y += self.velocityY; // Platform collision var wasOnGround = self.onGround; self.onGround = false; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; if (self.x > platform.x - platform.width / 2 && self.x < platform.x + platform.width / 2 && self.y > platform.y - platform.height && self.y < platform.y + 10 && self.velocityY >= 0) { self.y = platform.y - platform.height; self.velocityY = 0; self.onGround = true; self.jumpsRemaining = 2; // Reset jumps when landing break; } } // Check if fallen off screen if (self.y > 2900) { self.respawn(); } // Screen boundaries (horizontal bouncing) if (self.x < 60) { self.x = 60; self.velocityX = Math.abs(self.velocityX) * 0.5; } if (self.x > 1988) { self.x = 1988; self.velocityX = -Math.abs(self.velocityX) * 0.5; } }; self.respawn = function () { self.x = self.playerNumber === 1 ? 400 : 1648; self.y = 1000; self.velocityX = 0; self.velocityY = 0; self.health = 0; self.jumpsRemaining = 2; // Reset jumps on respawn if (self.playerNumber === 1) { player2Wins++; } else { player1Wins++; } updateScoreDisplay(); if (player1Wins >= 3 || player2Wins >= 3) { if (player1Wins >= 3) { LK.setScore(100); } LK.showGameOver(); } }; return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerupGraphics = self.attachAsset('powerup', { anchorX: 0.5, anchorY: 0.5 }); self.lifeTime = 0; self.maxLifeTime = 600; // 10 seconds at 60fps self.collected = false; self.update = function () { self.lifeTime++; self.rotation += 0.05; // Bounce effect self.y += Math.sin(self.lifeTime * 0.1) * 0.5; if (self.lifeTime > self.maxLifeTime) { self.destroy(); for (var i = powerups.length - 1; i >= 0; i--) { if (powerups[i] === self) { powerups.splice(i, 1); break; } } } // Check collection by players if (!self.collected) { for (var i = 0; i < fighters.length; i++) { var fighter = fighters[i]; var distance = Math.sqrt(Math.pow(fighter.x - self.x, 2) + Math.pow(fighter.y - self.y, 2)); if (distance < 80) { self.collected = true; fighter.knockbackResistance = 0.5; // Temporary power boost LK.setTimeout(function () { fighter.knockbackResistance = 1.0; }, 5000); LK.getSound('powerup').play(); LK.effects.flashObject(fighter, 0xffd700, 500); self.destroy(); for (var j = powerups.length - 1; j >= 0; j--) { if (powerups[j] === self) { powerups.splice(j, 1); break; } } break; } } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Game variables var fighters = []; var platforms = []; var powerups = []; var player1Wins = 0; var player2Wins = 0; var draggedFighter = null; var lastTapTime = 0; var powerupSpawnTimer = 0; // Create platforms var mainPlatform = game.addChild(LK.getAsset('mainPlatform', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1400 })); platforms.push(mainPlatform); var leftPlatform = game.addChild(LK.getAsset('platform', { anchorX: 0.5, anchorY: 0.5, x: 400, y: 1100 })); platforms.push(leftPlatform); var rightPlatform = game.addChild(LK.getAsset('platform', { anchorX: 0.5, anchorY: 0.5, x: 1648, y: 1100 })); platforms.push(rightPlatform); var topPlatform = game.addChild(LK.getAsset('platform', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 800 })); platforms.push(topPlatform); // Create fighters var player1 = game.addChild(new Fighter(1)); player1.x = 400; player1.y = 1000; fighters.push(player1); var player2 = game.addChild(new Fighter(2)); player2.x = 1648; player2.y = 1000; fighters.push(player2); // UI Elements var scoreText = new Text2('Player 1: 0 | Player 2: 0', { size: 80, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); var instructionText = new Text2('Drag to move, Tap to attack', { size: 60, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 1); LK.gui.bottom.addChild(instructionText); // Create jump button for player 1 var jumpButton = new Text2('JUMP', { size: 80, fill: 0xFFFFFF }); jumpButton.anchor.set(0, 1); jumpButton.x = 100; jumpButton.y = -20; LK.gui.bottomLeft.addChild(jumpButton); // Create left movement button for player 1 var leftButton = new Text2('◀', { size: 100, fill: 0xFFFFFF }); leftButton.anchor.set(0, 0.5); leftButton.x = 50; leftButton.y = 0; LK.gui.left.addChild(leftButton); // Create right movement button for player 1 var rightButton = new Text2('▶', { size: 100, fill: 0xFFFFFF }); rightButton.anchor.set(1, 0.5); rightButton.x = -50; rightButton.y = 0; LK.gui.right.addChild(rightButton); // Create attack button for player 1 var attackButton = new Text2('ATTACK', { size: 80, fill: 0xFFFFFF }); attackButton.anchor.set(1, 1); attackButton.x = -100; attackButton.y = -20; LK.gui.bottomRight.addChild(attackButton); function updateScoreDisplay() { scoreText.setText('Player 1: ' + player1Wins + ' | Player 2: ' + player2Wins); } // Jump button event handler jumpButton.down = function (x, y, obj) { if (player1.jumpsRemaining > 0) { player1.velocityY = -player1.jumpPower; player1.jumpsRemaining--; player1.onGround = false; } }; // Left button event handler leftButton.down = function (x, y, obj) { player1.velocityX -= player1.moveSpeed; }; // Right button event handler rightButton.down = function (x, y, obj) { player1.velocityX += player1.moveSpeed; }; // Attack button event handler attackButton.down = function (x, y, obj) { player1.attack(player1.x, player1.y); }; function spawnPowerUp() { if (powerups.length < 2) { var powerup = game.addChild(new PowerUp()); var spawnPlatform = platforms[Math.floor(Math.random() * platforms.length)]; powerup.x = spawnPlatform.x + (Math.random() - 0.5) * (spawnPlatform.width - 100); powerup.y = spawnPlatform.y - spawnPlatform.height - 100; powerups.push(powerup); } } // Game controls game.down = function (x, y, obj) { var currentTime = LK.ticks; var tapSpeed = 20; // frames between taps for double tap // Find closest fighter to touch point (only player 1) var closestFighter = null; var closestDistance = Infinity; for (var i = 0; i < fighters.length; i++) { var fighter = fighters[i]; // Only allow touch control for player 1 if (fighter.playerNumber === 2) continue; var distance = Math.sqrt(Math.pow(fighter.x - x, 2) + Math.pow(fighter.y - y, 2)); if (distance < closestDistance && distance < 200) { closestDistance = distance; closestFighter = fighter; } } if (closestFighter) { // Check for double tap (attack) if (currentTime - lastTapTime < tapSpeed) { closestFighter.attack(x, y); draggedFighter = null; } else { draggedFighter = closestFighter; } lastTapTime = currentTime; } }; game.move = function (x, y, obj) { if (draggedFighter && draggedFighter.playerNumber === 1) { var deltaX = x - draggedFighter.x; var deltaY = y - draggedFighter.y; // Move fighter towards touch point draggedFighter.velocityX += deltaX * 0.3; // Jump if dragging upward and has jumps remaining if (deltaY < -50 && draggedFighter.jumpsRemaining > 0) { draggedFighter.velocityY = -draggedFighter.jumpPower; draggedFighter.jumpsRemaining--; draggedFighter.onGround = false; } } }; game.up = function (x, y, obj) { draggedFighter = null; }; // AI variables for player 2 var aiDecisionTimer = 0; var aiAction = 'idle'; var aiTargetX = player2.x; var aiCooldown = 0; game.update = function () { // Spawn power-ups occasionally powerupSpawnTimer++; if (powerupSpawnTimer > 300) { // Every 5 seconds if (Math.random() < 0.3) { spawnPowerUp(); } powerupSpawnTimer = 0; } // AI for player 2 aiDecisionTimer++; if (aiCooldown > 0) { aiCooldown--; } // Make AI decisions every 30 frames (half second) if (aiDecisionTimer > 30) { aiDecisionTimer = 0; // Calculate distance to player 1 var distanceToPlayer1 = Math.sqrt(Math.pow(player1.x - player2.x, 2) + Math.pow(player1.y - player2.y, 2)); // Check for nearby powerups var nearestPowerup = null; var nearestPowerupDistance = Infinity; for (var i = 0; i < powerups.length; i++) { var powerup = powerups[i]; var distance = Math.sqrt(Math.pow(powerup.x - player2.x, 2) + Math.pow(powerup.y - player2.y, 2)); if (distance < nearestPowerupDistance) { nearestPowerupDistance = distance; nearestPowerup = powerup; } } // AI decision making if (aiCooldown === 0) { if (distanceToPlayer1 < 200 && Math.random() < 0.7) { // Attack if close to player 1 aiAction = 'attack'; aiCooldown = 60; // Attack cooldown } else if (nearestPowerup && nearestPowerupDistance < 300 && Math.random() < 0.5) { // Go for powerup if nearby aiAction = 'moveToPowerup'; aiTargetX = nearestPowerup.x; } else if (distanceToPlayer1 > 400 && Math.random() < 0.6) { // Move towards player 1 if far away aiAction = 'moveToPlayer'; aiTargetX = player1.x; } else if (Math.random() < 0.3) { // Random movement aiAction = 'randomMove'; aiTargetX = 400 + Math.random() * 1248; // Random X within screen bounds } else { aiAction = 'idle'; } } } // Execute AI actions if (aiAction === 'attack') { player2.attack(player1.x, player1.y); aiAction = 'idle'; } else if (aiAction === 'moveToPowerup' || aiAction === 'moveToPlayer' || aiAction === 'randomMove') { // Move towards target var deltaX = aiTargetX - player2.x; if (Math.abs(deltaX) > 50) { player2.velocityX += deltaX * 0.2; } // Jump if target is above or if stuck if (aiAction === 'moveToPlayer' && player1.y < player2.y - 100 || Math.abs(player2.velocityX) < 1 && player2.onGround && Math.random() < 0.1) { if (player2.jumpsRemaining > 0) { player2.velocityY = -player2.jumpPower; player2.jumpsRemaining--; player2.onGround = false; } } // Reset action if close enough to target if (Math.abs(deltaX) < 100) { aiAction = 'idle'; } } // AI emergency jump if falling off platform if (player2.y > 1500 && player2.jumpsRemaining > 0) { player2.velocityY = -player2.jumpPower; player2.jumpsRemaining--; player2.onGround = false; } // Update all fighters for (var i = 0; i < fighters.length; i++) { fighters[i].update(); } // Update all powerups for (var i = powerups.length - 1; i >= 0; i--) { if (powerups[i] && !powerups[i].destroyed) { powerups[i].update(); } } };
===================================================================
--- original.js
+++ change.js
@@ -259,8 +259,26 @@
jumpButton.anchor.set(0, 1);
jumpButton.x = 100;
jumpButton.y = -20;
LK.gui.bottomLeft.addChild(jumpButton);
+// Create left movement button for player 1
+var leftButton = new Text2('◀', {
+ size: 100,
+ fill: 0xFFFFFF
+});
+leftButton.anchor.set(0, 0.5);
+leftButton.x = 50;
+leftButton.y = 0;
+LK.gui.left.addChild(leftButton);
+// Create right movement button for player 1
+var rightButton = new Text2('▶', {
+ size: 100,
+ fill: 0xFFFFFF
+});
+rightButton.anchor.set(1, 0.5);
+rightButton.x = -50;
+rightButton.y = 0;
+LK.gui.right.addChild(rightButton);
// Create attack button for player 1
var attackButton = new Text2('ATTACK', {
size: 80,
fill: 0xFFFFFF
@@ -279,8 +297,16 @@
player1.jumpsRemaining--;
player1.onGround = false;
}
};
+// Left button event handler
+leftButton.down = function (x, y, obj) {
+ player1.velocityX -= player1.moveSpeed;
+};
+// Right button event handler
+rightButton.down = function (x, y, obj) {
+ player1.velocityX += player1.moveSpeed;
+};
// Attack button event handler
attackButton.down = function (x, y, obj) {
player1.attack(player1.x, player1.y);
};
Slime azul, pixelart. In-Game asset. 2d. High contrast. No shadows
Slime rojo, pixelart. In-Game asset. 2d. High contrast. No shadows
Slime amarillo, pixelart. In-Game asset. 2d. High contrast. No shadows
Slime verde, pixelart. In-Game asset. 2d. High contrast. No shadows
Montañas en atardecer pixelart. In-Game asset. 2d. High contrast. No shadows
Elimina la montaña
Burbuja azul, una , pixelart. In-Game asset. 2d. High contrast. No shadows
Esfera amarilla con la letra P , pixelart. In-Game asset. 2d. High contrast. No shadows
Flecha azul de Slime , pixelart. In-Game asset. 2d. High contrast. No shadows
Cámbiale el color a rojo , pixelart
Cámbiale el color a amarillo, pixelart
Cámbiale el color a verde, pixelart
Apaga las luces de la ventanas
Luciérnaga, pixelart. In-Game asset. 2d. High contrast. No shadows
Cabeza de girasol, pixelart. In-Game asset. 2d. High contrast. No shadows
Número 1 azul , pixelart. In-Game asset. 2d. High contrast. No shadows
Número 0 azul, pixelart. In-Game asset. 2d. High contrast. No shadows
Número 3 azul, pixelart. In-Game asset. 2d. High contrast. No shadows
Retro, pixelart