User prompt
No me cambiaron nada sigue igual
User prompt
Está mal
User prompt
Que haya un botón de moverse
User prompt
Que haya botones para moverse y para saltar y pegar
User prompt
Que tenga botones de moverse y de a y b para saltar y pegar
Code edit (1 edits merged)
Please save this source code
User prompt
Messi vs Ronaldo: Epic Soccer Duel
Initial prompt
Quiero que hagas un juego de peleas entre Messi y Ronaldo
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var AttackEffect = Container.expand(function () { var self = Container.call(this); var effectGraphics = self.attachAsset('attack_effect', { anchorX: 0.5, anchorY: 0.5 }); self.lifetime = 20; // Scale and fade animation tween(effectGraphics, { scaleX: 2, scaleY: 2, alpha: 0 }, { duration: 300 }); self.update = function () { self.lifetime--; }; return self; }); var ControlButton = Container.expand(function (label, x, y) { var self = Container.call(this); var buttonBg = self.attachAsset('button_bg', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(label, { size: 40, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.x = x; self.y = y; self.isPressed = false; self.setPressed = function (pressed) { self.isPressed = pressed; buttonBg.tint = pressed ? 0x888888 : 0xFFFFFF; }; return self; }); var HealthBar = Container.expand(function (isPlayer1) { var self = Container.call(this); var bgGraphics = self.attachAsset('health_bg', { anchorX: isPlayer1 ? 0 : 1, anchorY: 0 }); var fillGraphics = self.attachAsset('health_fill', { anchorX: isPlayer1 ? 0 : 1, anchorY: 0 }); self.updateHealth = function (health, maxHealth) { var healthPercent = health / maxHealth; fillGraphics.scaleX = healthPercent; // Change color based on health if (healthPercent > 0.6) { fillGraphics.tint = 0x00ff00; // Green } else if (healthPercent > 0.3) { fillGraphics.tint = 0xffff00; // Yellow } else { fillGraphics.tint = 0xff0000; // Red } }; return self; }); var Player = Container.expand(function (playerType) { var self = Container.call(this); self.playerType = playerType; self.maxHealth = 100; self.health = 100; self.power = 0; self.isBlocking = false; self.attackCooldown = 0; self.specialCooldown = 0; self.moveSpeed = 8; self.isJumping = false; self.jumpSpeed = 0; self.groundY = 2200; self.gravity = 1.2; var playerGraphics = self.attachAsset(playerType, { anchorX: 0.5, anchorY: 1.0 }); self.takeDamage = function (damage) { if (self.isBlocking) { damage = damage * 0.3; // Reduce damage when blocking } self.health -= damage; if (self.health < 0) self.health = 0; // Flash red when taking damage LK.effects.flashObject(self, 0xff0000, 300); // Screen shake on heavy damage if (damage > 15) { LK.effects.flashScreen(0xff0000, 200); } }; self.attack = function () { if (self.attackCooldown > 0) return false; self.attackCooldown = 30; // 0.5 second cooldown // Attack animation tween(playerGraphics, { scaleX: 1.2, scaleY: 0.9 }, { duration: 150, onFinish: function onFinish() { tween(playerGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 150 }); } }); LK.getSound('punch').play(); return true; }; self.specialAttack = function () { if (self.specialCooldown > 0 || self.power < 50) return false; self.specialCooldown = 120; // 2 second cooldown self.power -= 50; // Special attack animation tween(playerGraphics, { rotation: Math.PI * 2 }, { duration: 500, onFinish: function onFinish() { playerGraphics.rotation = 0; } }); LK.getSound('kick').play(); return true; }; self.block = function (blocking) { self.isBlocking = blocking; playerGraphics.tint = blocking ? 0x8888ff : 0xffffff; }; self.addPower = function (amount) { self.power += amount; if (self.power > 100) self.power = 100; }; self.moveLeft = function () { self.x -= self.moveSpeed; if (self.x < 75) self.x = 75; // Keep within bounds }; self.moveRight = function () { self.x += self.moveSpeed; if (self.x > 1973) self.x = 1973; // Keep within bounds }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.jumpSpeed = -20; // Negative for upward movement } }; self.update = function () { if (self.attackCooldown > 0) self.attackCooldown--; if (self.specialCooldown > 0) self.specialCooldown--; // Handle jumping physics if (self.isJumping) { self.y += self.jumpSpeed; self.jumpSpeed += self.gravity; // Check if landed if (self.y >= self.groundY) { self.y = self.groundY; self.isJumping = false; self.jumpSpeed = 0; } } }; return self; }); var SoccerBall = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('soccer_ball', { anchorX: 0.5, anchorY: 0.5 }); self.collected = false; self.lifetime = 300; // 5 seconds // Floating animation tween(self, { y: self.y - 20 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { y: self.y + 20 }, { duration: 1000, easing: tween.easeInOut }); } }); self.update = function () { self.lifetime--; if (self.lifetime <= 0) { self.collected = true; } // Fade out in last second if (self.lifetime < 60) { ballGraphics.alpha = self.lifetime / 60; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228b22 }); /**** * Game Code ****/ var gameState = 'playing'; // 'playing', 'gameover' var player1, player2; var soccerBalls = []; var attackEffects = []; var player1HealthBar, player2HealthBar; var powerBar1, powerBar2; var ballSpawnTimer = 0; // Create players player1 = game.addChild(new Player('messi')); player1.x = 400; player1.y = 2200; player2 = game.addChild(new Player('ronaldo')); player2.x = 1650; player2.y = 2200; // Create health bars player1HealthBar = new HealthBar(true); player1HealthBar.x = 50; player1HealthBar.y = 50; LK.gui.topLeft.addChild(player1HealthBar); player2HealthBar = new HealthBar(false); player2HealthBar.x = LK.gui.width - 50; player2HealthBar.y = 50; LK.gui.topLeft.addChild(player2HealthBar); // Create power bars (smaller, below health bars) var powerBg1 = LK.getAsset('health_bg', { scaleX: 0.5, scaleY: 0.7 }); var powerFill1 = LK.getAsset('health_fill', { scaleX: 0, scaleY: 0.7 }); powerFill1.tint = 0x0088ff; powerBar1 = new Container(); powerBar1.addChild(powerBg1); powerBar1.addChild(powerFill1); powerBar1.x = 50; powerBar1.y = 90; LK.gui.topLeft.addChild(powerBar1); var powerBg2 = LK.getAsset('health_bg', { scaleX: -0.5, scaleY: 0.7, anchorX: 1 }); var powerFill2 = LK.getAsset('health_fill', { scaleX: 0, scaleY: 0.7, anchorX: 1 }); powerFill2.tint = 0x0088ff; powerBar2 = new Container(); powerBar2.addChild(powerBg2); powerBar2.addChild(powerFill2); powerBar2.x = LK.gui.width - 50; powerBar2.y = 90; LK.gui.topLeft.addChild(powerBar2); // Game title var titleText = new Text2('MESSI vs RONALDO', { size: 80, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0); LK.gui.top.addChild(titleText); // Instructions var instructText = new Text2('TAP: Attack | HOLD: Block | SWIPE: Special', { size: 40, fill: 0xFFFFFF }); instructText.anchor.set(0.5, 1); instructText.y = LK.gui.height - 50; LK.gui.bottom.addChild(instructText); // Touch controls var isHolding = false; var holdTimer = 0; var touchStartTime = 0; // Control buttons var player1Controls = { left: new ControlButton('←', 150, LK.gui.height - 150), right: new ControlButton('→', 280, LK.gui.height - 150), jump: new ControlButton('A', 150, LK.gui.height - 280), attack: new ControlButton('B', 280, LK.gui.height - 280) }; var player2Controls = { left: new ControlButton('←', LK.gui.width - 280, LK.gui.height - 150), right: new ControlButton('→', LK.gui.width - 150, LK.gui.height - 150), jump: new ControlButton('A', LK.gui.width - 280, LK.gui.height - 280), attack: new ControlButton('B', LK.gui.width - 150, LK.gui.height - 280) }; // Add control buttons to GUI LK.gui.bottomLeft.addChild(player1Controls.left); LK.gui.bottomLeft.addChild(player1Controls.right); LK.gui.bottomLeft.addChild(player1Controls.jump); LK.gui.bottomLeft.addChild(player1Controls.attack); LK.gui.bottomRight.addChild(player2Controls.left); LK.gui.bottomRight.addChild(player2Controls.right); LK.gui.bottomRight.addChild(player2Controls.jump); LK.gui.bottomRight.addChild(player2Controls.attack); // Control states var controlStates = { p1Left: false, p1Right: false, p1Jump: false, p1Attack: false, p2Left: false, p2Right: false, p2Jump: false, p2Attack: false }; function spawnSoccerBall() { var ball = new SoccerBall(); ball.x = 1024; // Center of field ball.y = 1500 + Math.random() * 400; soccerBalls.push(ball); game.addChild(ball); } function createAttackEffect(x, y) { var effect = new AttackEffect(); effect.x = x; effect.y = y; attackEffects.push(effect); game.addChild(effect); } function checkCollisions() { // Player attacks var distance = Math.abs(player1.x - player2.x); if (distance < 200) { // Close enough for combat // Player 1 can hit Player 2 if (player1.attackCooldown === 29) { // Just attacked player2.takeDamage(15); createAttackEffect(player2.x, player2.y - 100); } // Player 2 can hit Player 1 if (player2.attackCooldown === 29) { // Just attacked player1.takeDamage(15); createAttackEffect(player1.x, player1.y - 100); } } // Special attacks have longer range if (distance < 300) { if (player1.specialCooldown === 119) { // Just used special player2.takeDamage(30); createAttackEffect(player2.x, player2.y - 100); } if (player2.specialCooldown === 119) { // Just used special player1.takeDamage(30); createAttackEffect(player1.x, player1.y - 100); } } // Soccer ball collection for (var i = soccerBalls.length - 1; i >= 0; i--) { var ball = soccerBalls[i]; if (ball.intersects(player1)) { player1.addPower(25); ball.collected = true; LK.getSound('powerup').play(); } else if (ball.intersects(player2)) { player2.addPower(25); ball.collected = true; LK.getSound('powerup').play(); } } } game.down = function (x, y, obj) { if (gameState !== 'playing') return; // Check Player 1 controls if (player1Controls.left.intersects({ x: x, y: y, width: 1, height: 1 })) { controlStates.p1Left = true; player1Controls.left.setPressed(true); } if (player1Controls.right.intersects({ x: x, y: y, width: 1, height: 1 })) { controlStates.p1Right = true; player1Controls.right.setPressed(true); } if (player1Controls.jump.intersects({ x: x, y: y, width: 1, height: 1 })) { controlStates.p1Jump = true; player1Controls.jump.setPressed(true); player1.jump(); } if (player1Controls.attack.intersects({ x: x, y: y, width: 1, height: 1 })) { controlStates.p1Attack = true; player1Controls.attack.setPressed(true); player1.attack(); } // Check Player 2 controls if (player2Controls.left.intersects({ x: x, y: y, width: 1, height: 1 })) { controlStates.p2Left = true; player2Controls.left.setPressed(true); } if (player2Controls.right.intersects({ x: x, y: y, width: 1, height: 1 })) { controlStates.p2Right = true; player2Controls.right.setPressed(true); } if (player2Controls.jump.intersects({ x: x, y: y, width: 1, height: 1 })) { controlStates.p2Jump = true; player2Controls.jump.setPressed(true); player2.jump(); } if (player2Controls.attack.intersects({ x: x, y: y, width: 1, height: 1 })) { controlStates.p2Attack = true; player2Controls.attack.setPressed(true); player2.attack(); } }; game.up = function (x, y, obj) { if (gameState !== 'playing') return; // Reset all control states and button appearances controlStates.p1Left = false; controlStates.p1Right = false; controlStates.p1Jump = false; controlStates.p1Attack = false; controlStates.p2Left = false; controlStates.p2Right = false; controlStates.p2Jump = false; controlStates.p2Attack = false; player1Controls.left.setPressed(false); player1Controls.right.setPressed(false); player1Controls.jump.setPressed(false); player1Controls.attack.setPressed(false); player2Controls.left.setPressed(false); player2Controls.right.setPressed(false); player2Controls.jump.setPressed(false); player2Controls.attack.setPressed(false); isHolding = false; holdTimer = 0; }; game.update = function () { if (gameState !== 'playing') return; // Handle continuous movement if (controlStates.p1Left) { player1.moveLeft(); } if (controlStates.p1Right) { player1.moveRight(); } if (controlStates.p2Left) { player2.moveLeft(); } if (controlStates.p2Right) { player2.moveRight(); } // Update players player1.update(); player2.update(); // Update UI player1HealthBar.updateHealth(player1.health, player1.maxHealth); player2HealthBar.updateHealth(player2.health, player2.maxHealth); powerFill1.scaleX = player1.power / 100 * 0.5; powerFill2.scaleX = -(player2.power / 100) * 0.5; // Spawn soccer balls ballSpawnTimer++; if (ballSpawnTimer > 300) { // Every 5 seconds spawnSoccerBall(); ballSpawnTimer = 0; } // Update soccer balls for (var i = soccerBalls.length - 1; i >= 0; i--) { var ball = soccerBalls[i]; ball.update(); if (ball.collected || ball.lifetime <= 0) { ball.destroy(); soccerBalls.splice(i, 1); } } // Update attack effects for (var j = attackEffects.length - 1; j >= 0; j--) { var effect = attackEffects[j]; effect.update(); if (effect.lifetime <= 0) { effect.destroy(); attackEffects.splice(j, 1); } } // Check collisions checkCollisions(); // Check win conditions if (player1.health <= 0) { gameState = 'gameover'; LK.setScore(2); // Player 2 wins LK.showGameOver(); } else if (player2.health <= 0) { gameState = 'gameover'; LK.setScore(1); // Player 1 wins LK.showYouWin(); } // Update hold timer for blocking if (isHolding) { holdTimer++; } };
===================================================================
--- original.js
+++ change.js
@@ -25,8 +25,29 @@
self.lifetime--;
};
return self;
});
+var ControlButton = Container.expand(function (label, x, y) {
+ var self = Container.call(this);
+ var buttonBg = self.attachAsset('button_bg', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2(label, {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.x = x;
+ self.y = y;
+ self.isPressed = false;
+ self.setPressed = function (pressed) {
+ self.isPressed = pressed;
+ buttonBg.tint = pressed ? 0x888888 : 0xFFFFFF;
+ };
+ return self;
+});
var HealthBar = Container.expand(function (isPlayer1) {
var self = Container.call(this);
var bgGraphics = self.attachAsset('health_bg', {
anchorX: isPlayer1 ? 0 : 1,
@@ -58,8 +79,13 @@
self.power = 0;
self.isBlocking = false;
self.attackCooldown = 0;
self.specialCooldown = 0;
+ self.moveSpeed = 8;
+ self.isJumping = false;
+ self.jumpSpeed = 0;
+ self.groundY = 2200;
+ self.gravity = 1.2;
var playerGraphics = self.attachAsset(playerType, {
anchorX: 0.5,
anchorY: 1.0
});
@@ -120,11 +146,36 @@
self.addPower = function (amount) {
self.power += amount;
if (self.power > 100) self.power = 100;
};
+ self.moveLeft = function () {
+ self.x -= self.moveSpeed;
+ if (self.x < 75) self.x = 75; // Keep within bounds
+ };
+ self.moveRight = function () {
+ self.x += self.moveSpeed;
+ if (self.x > 1973) self.x = 1973; // Keep within bounds
+ };
+ self.jump = function () {
+ if (!self.isJumping) {
+ self.isJumping = true;
+ self.jumpSpeed = -20; // Negative for upward movement
+ }
+ };
self.update = function () {
if (self.attackCooldown > 0) self.attackCooldown--;
if (self.specialCooldown > 0) self.specialCooldown--;
+ // Handle jumping physics
+ if (self.isJumping) {
+ self.y += self.jumpSpeed;
+ self.jumpSpeed += self.gravity;
+ // Check if landed
+ if (self.y >= self.groundY) {
+ self.y = self.groundY;
+ self.isJumping = false;
+ self.jumpSpeed = 0;
+ }
+ }
};
return self;
});
var SoccerBall = Container.expand(function () {
@@ -247,8 +298,41 @@
// Touch controls
var isHolding = false;
var holdTimer = 0;
var touchStartTime = 0;
+// Control buttons
+var player1Controls = {
+ left: new ControlButton('←', 150, LK.gui.height - 150),
+ right: new ControlButton('→', 280, LK.gui.height - 150),
+ jump: new ControlButton('A', 150, LK.gui.height - 280),
+ attack: new ControlButton('B', 280, LK.gui.height - 280)
+};
+var player2Controls = {
+ left: new ControlButton('←', LK.gui.width - 280, LK.gui.height - 150),
+ right: new ControlButton('→', LK.gui.width - 150, LK.gui.height - 150),
+ jump: new ControlButton('A', LK.gui.width - 280, LK.gui.height - 280),
+ attack: new ControlButton('B', LK.gui.width - 150, LK.gui.height - 280)
+};
+// Add control buttons to GUI
+LK.gui.bottomLeft.addChild(player1Controls.left);
+LK.gui.bottomLeft.addChild(player1Controls.right);
+LK.gui.bottomLeft.addChild(player1Controls.jump);
+LK.gui.bottomLeft.addChild(player1Controls.attack);
+LK.gui.bottomRight.addChild(player2Controls.left);
+LK.gui.bottomRight.addChild(player2Controls.right);
+LK.gui.bottomRight.addChild(player2Controls.jump);
+LK.gui.bottomRight.addChild(player2Controls.attack);
+// Control states
+var controlStates = {
+ p1Left: false,
+ p1Right: false,
+ p1Jump: false,
+ p1Attack: false,
+ p2Left: false,
+ p2Right: false,
+ p2Jump: false,
+ p2Attack: false
+};
function spawnSoccerBall() {
var ball = new SoccerBall();
ball.x = 1024; // Center of field
ball.y = 1500 + Math.random() * 400;
@@ -308,43 +392,124 @@
}
}
game.down = function (x, y, obj) {
if (gameState !== 'playing') return;
- isHolding = true;
- holdTimer = 0;
- touchStartTime = LK.ticks;
- // Determine which side was touched for player control
- if (x < 1024) {
- // Left side - Player 1 controls
- if (!player1.attack()) {
- player1.block(true);
- }
- } else {
- // Right side - Player 2 controls
- if (!player2.attack()) {
- player2.block(true);
- }
+ // Check Player 1 controls
+ if (player1Controls.left.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ controlStates.p1Left = true;
+ player1Controls.left.setPressed(true);
}
+ if (player1Controls.right.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ controlStates.p1Right = true;
+ player1Controls.right.setPressed(true);
+ }
+ if (player1Controls.jump.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ controlStates.p1Jump = true;
+ player1Controls.jump.setPressed(true);
+ player1.jump();
+ }
+ if (player1Controls.attack.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ controlStates.p1Attack = true;
+ player1Controls.attack.setPressed(true);
+ player1.attack();
+ }
+ // Check Player 2 controls
+ if (player2Controls.left.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ controlStates.p2Left = true;
+ player2Controls.left.setPressed(true);
+ }
+ if (player2Controls.right.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ controlStates.p2Right = true;
+ player2Controls.right.setPressed(true);
+ }
+ if (player2Controls.jump.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ controlStates.p2Jump = true;
+ player2Controls.jump.setPressed(true);
+ player2.jump();
+ }
+ if (player2Controls.attack.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ controlStates.p2Attack = true;
+ player2Controls.attack.setPressed(true);
+ player2.attack();
+ }
};
game.up = function (x, y, obj) {
if (gameState !== 'playing') return;
- var touchDuration = LK.ticks - touchStartTime;
- // Stop blocking
- player1.block(false);
- player2.block(false);
- // Check for swipe (quick touch)
- if (touchDuration < 10) {
- if (x < 1024) {
- player1.specialAttack();
- } else {
- player2.specialAttack();
- }
- }
+ // Reset all control states and button appearances
+ controlStates.p1Left = false;
+ controlStates.p1Right = false;
+ controlStates.p1Jump = false;
+ controlStates.p1Attack = false;
+ controlStates.p2Left = false;
+ controlStates.p2Right = false;
+ controlStates.p2Jump = false;
+ controlStates.p2Attack = false;
+ player1Controls.left.setPressed(false);
+ player1Controls.right.setPressed(false);
+ player1Controls.jump.setPressed(false);
+ player1Controls.attack.setPressed(false);
+ player2Controls.left.setPressed(false);
+ player2Controls.right.setPressed(false);
+ player2Controls.jump.setPressed(false);
+ player2Controls.attack.setPressed(false);
isHolding = false;
holdTimer = 0;
};
game.update = function () {
if (gameState !== 'playing') return;
+ // Handle continuous movement
+ if (controlStates.p1Left) {
+ player1.moveLeft();
+ }
+ if (controlStates.p1Right) {
+ player1.moveRight();
+ }
+ if (controlStates.p2Left) {
+ player2.moveLeft();
+ }
+ if (controlStates.p2Right) {
+ player2.moveRight();
+ }
// Update players
player1.update();
player2.update();
// Update UI
Un tipo con barba y pelo mediano que tenga una camiseta con rayas blancas y celestes. In-Game asset. High contrast. No shadows. 2d
Has a una persona igual a Cristiano Ronaldo. In-Game asset. 2d. High contrast. No shadows
Un balón normal. In-Game asset. 2d. High contrast. No shadows
Que sea redondo y que adentro tenga la letra a y que sea el fondo azul