User prompt
No suena la musica
User prompt
Ponle musica y sonidos
User prompt
Haz que tengas que matar a todos los enemigos y recolectar todas las monedas para pasar el nivel
User prompt
Añade un triple salto
User prompt
Haz que sea posible el nivel
User prompt
Pon unas texturas mas bonitas y de caricaturas
User prompt
Pon controles de movimiento
Code edit (1 edits merged)
Please save this source code
User prompt
Platform Hero Adventure
Initial prompt
Crea un juego de plataformeo con enemigos
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 1.0 }); var leftEye = self.attachAsset('enemyEye', { anchorX: 0.5, anchorY: 0.5, x: -10, y: -35 }); var rightEye = self.attachAsset('enemyEye', { anchorX: 0.5, anchorY: 0.5, x: 10, y: -35 }); var spike1 = self.attachAsset('enemySpike', { anchorX: 0.5, anchorY: 1.0, x: -15, y: -45 }); var spike2 = self.attachAsset('enemySpike', { anchorX: 0.5, anchorY: 1.0, x: 0, y: -50 }); var spike3 = self.attachAsset('enemySpike', { anchorX: 0.5, anchorY: 1.0, x: 15, y: -45 }); self.velocityX = 3; self.direction = 1; self.startX = 0; self.patrolDistance = 200; self.update = function () { self.x += self.velocityX * self.direction; // Patrol behavior if (Math.abs(self.x - self.startX) > self.patrolDistance) { self.direction *= -1; } // Check collision with hero if (self.intersects(hero)) { // Check if hero jumped on enemy if (hero.velocityY > 0 && hero.y < self.y - 25) { self.defeat(); hero.velocityY = -15; // Bounce } else { hero.die(); } } // Check collision with projectiles for (var i = projectiles.length - 1; i >= 0; i--) { var projectile = projectiles[i]; if (self.intersects(projectile)) { self.defeat(); projectile.destroy(); projectiles.splice(i, 1); break; } } }; self.defeat = function () { LK.setScore(LK.getScore() + 100); scoreText.setText(LK.getScore()); LK.getSound('defeat').play(); // Remove from enemies array for (var i = enemies.length - 1; i >= 0; i--) { if (enemies[i] === self) { enemies.splice(i, 1); break; } } self.destroy(); }; return self; }); var Hero = Container.expand(function () { var self = Container.call(this); var heroBody = self.attachAsset('heroBody', { anchorX: 0.5, anchorY: 1.0 }); var heroHead = self.attachAsset('heroHead', { anchorX: 0.5, anchorY: 1.0, x: 0, y: -45 }); var heroGraphics = heroBody; self.velocityX = 0; self.velocityY = 0; self.speed = 8; self.jumpPower = -25; self.gravity = 1; self.onGround = false; self.facingRight = true; self.update = function () { // Apply gravity self.velocityY += self.gravity; // Apply velocity self.x += self.velocityX; self.y += self.velocityY; // Apply friction self.velocityX *= 0.8; // Check platform collisions self.onGround = false; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; if (self.intersects(platform)) { // Landing on top of platform if (self.velocityY > 0 && self.y - 60 < platform.y) { self.y = platform.y; self.velocityY = 0; self.onGround = true; } } } // Keep hero on screen horizontally if (self.x < 30) self.x = 30; if (self.x > 2018) self.x = 2018; // Check if fallen off screen if (self.y > 2800) { self.die(); } // Update sprite direction if (self.velocityX > 1 && !self.facingRight) { heroGraphics.scaleX = 1; self.facingRight = true; } else if (self.velocityX < -1 && self.facingRight) { heroGraphics.scaleX = -1; self.facingRight = false; } }; self.jump = function () { if (self.onGround) { self.velocityY = self.jumpPower; self.onGround = false; LK.getSound('jump').play(); } }; self.moveLeft = function () { self.velocityX = -self.speed; }; self.moveRight = function () { self.velocityX = self.speed; }; self.shoot = function () { var newProjectile = new Projectile(); newProjectile.x = self.x; newProjectile.y = self.y - 30; newProjectile.velocityX = self.facingRight ? 15 : -15; projectiles.push(newProjectile); game.addChild(newProjectile); }; self.die = function () { lives--; if (lives <= 0) { LK.showGameOver(); } else { self.respawn(); } }; self.respawn = function () { self.x = 200; self.y = 2000; self.velocityX = 0; self.velocityY = 0; }; return self; }); var Platform = Container.expand(function (width, height) { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5, width: width || 300, height: height || 40 }); var leftEdge = self.attachAsset('platformEdge', { anchorX: 1.0, anchorY: 0.5, x: -(width || 300) / 2, y: 0 }); var rightEdge = self.attachAsset('platformEdge', { anchorX: 0.0, anchorY: 0.5, x: (width || 300) / 2, y: 0 }); var grass = self.attachAsset('platformGrass', { anchorX: 0.5, anchorY: 1.0, width: width || 300, x: 0, y: -(height || 40) / 2 }); return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerupGlow = self.attachAsset('powerupGlow', { anchorX: 0.5, anchorY: 0.5 }); var powerupGraphics = self.attachAsset('powerup', { anchorX: 0.5, anchorY: 0.5 }); var powerupCore = self.attachAsset('powerupCore', { anchorX: 0.5, anchorY: 0.5 }); self.bobOffset = 0; self.startY = 0; self.update = function () { // Bobbing animation self.bobOffset += 0.1; self.y = self.startY + Math.sin(self.bobOffset) * 10; // Check collision with hero if (self.intersects(hero)) { self.collect(); } }; self.collect = function () { LK.setScore(LK.getScore() + 50); scoreText.setText(LK.getScore()); LK.getSound('collect').play(); // Remove from powerups array for (var i = powerups.length - 1; i >= 0; i--) { if (powerups[i] === self) { powerups.splice(i, 1); break; } } self.destroy(); }; return self; }); var Projectile = Container.expand(function () { var self = Container.call(this); var projectileGlow = self.attachAsset('projectileGlow', { anchorX: 0.5, anchorY: 0.5 }); var projectileGraphics = self.attachAsset('projectile', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.gravity = 0.5; self.update = function () { self.velocityY += self.gravity; self.x += self.velocityX; self.y += self.velocityY; // Remove if off screen if (self.x < -50 || self.x > 2098 || self.y > 2800) { // Remove from projectiles array for (var i = projectiles.length - 1; i >= 0; i--) { if (projectiles[i] === self) { projectiles.splice(i, 1); break; } } self.destroy(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Game variables var hero; var platforms = []; var enemies = []; var powerups = []; var projectiles = []; var lives = 3; // UI Elements var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0, 0); scoreText.x = 150; scoreText.y = 50; LK.gui.topLeft.addChild(scoreText); var livesText = new Text2('Lives: 3', { size: 60, fill: 0xFFFFFF }); livesText.anchor.set(1, 0); LK.gui.topRight.addChild(livesText); // Create hero hero = game.addChild(new Hero()); hero.x = 200; hero.y = 2000; // Create platforms var platformData = [{ x: 150, y: 2200, width: 300 }, { x: 600, y: 2100, width: 200 }, { x: 1000, y: 2000, width: 250 }, { x: 1400, y: 1900, width: 300 }, { x: 1800, y: 1800, width: 200 }, { x: 300, y: 1700, width: 200 }, { x: 700, y: 1600, width: 300 }, { x: 1200, y: 1500, width: 250 }, { x: 1600, y: 1400, width: 200 }, { x: 400, y: 1300, width: 300 }, { x: 900, y: 1200, width: 200 }, { x: 1300, y: 1100, width: 250 }, { x: 500, y: 1000, width: 300 }, { x: 1000, y: 900, width: 400 }]; for (var i = 0; i < platformData.length; i++) { var pData = platformData[i]; var platform = game.addChild(new Platform(pData.width, 40)); platform.x = pData.x; platform.y = pData.y; platforms.push(platform); } // Create enemies var enemyData = [{ x: 600, y: 2060, startX: 600 }, { x: 1000, y: 1960, startX: 1000 }, { x: 1400, y: 1860, startX: 1400 }, { x: 700, y: 1560, startX: 700 }, { x: 1200, y: 1460, startX: 1200 }, { x: 500, y: 960, startX: 500 }]; for (var i = 0; i < enemyData.length; i++) { var eData = enemyData[i]; var enemy = game.addChild(new Enemy()); enemy.x = eData.x; enemy.y = eData.y; enemy.startX = eData.startX; enemies.push(enemy); } // Create power-ups var powerupData = [{ x: 1000, y: 1950 }, { x: 1800, y: 1750 }, { x: 300, y: 1650 }, { x: 1200, y: 1450 }, { x: 900, y: 1150 }, { x: 1000, y: 850 }]; for (var i = 0; i < powerupData.length; i++) { var pData = powerupData[i]; var powerup = game.addChild(new PowerUp()); powerup.x = pData.x; powerup.y = pData.y; powerup.startY = pData.y; powerups.push(powerup); } // Touch controls var leftPressed = false; var rightPressed = false; // Control buttons with visual indicators var leftButton = game.addChild(new Container()); var leftButtonBorder = leftButton.attachAsset('controlButtonBorder', { anchorX: 0.5, anchorY: 0.5 }); var leftButtonGraphics = leftButton.attachAsset('controlButton', { anchorX: 0.5, anchorY: 0.5 }); leftButton.x = 150; leftButton.y = 2550; var rightButton = game.addChild(new Container()); var rightButtonBorder = rightButton.attachAsset('controlButtonBorder', { anchorX: 0.5, anchorY: 0.5 }); var rightButtonGraphics = rightButton.attachAsset('controlButton', { anchorX: 0.5, anchorY: 0.5 }); rightButton.x = 350; rightButton.y = 2550; var jumpButton = game.addChild(new Container()); var jumpButtonBorder = jumpButton.attachAsset('jumpButtonBorder', { anchorX: 0.5, anchorY: 0.5 }); var jumpButtonGraphics = jumpButton.attachAsset('jumpButton', { anchorX: 0.5, anchorY: 0.5 }); jumpButton.x = 1848; jumpButton.y = 2550; var shootButton = game.addChild(new Container()); var shootButtonBorder = shootButton.attachAsset('shootButtonBorder', { anchorX: 0.5, anchorY: 0.5 }); var shootButtonGraphics = shootButton.attachAsset('shootButton', { anchorX: 0.5, anchorY: 0.5 }); shootButton.x = 1524; shootButton.y = 2550; // Add button labels var leftLabel = new Text2('<', { size: 80, fill: 0xFFFFFF }); leftLabel.anchor.set(0.5, 0.5); leftLabel.x = 0; leftLabel.y = 0; leftButton.addChild(leftLabel); var rightLabel = new Text2('>', { size: 80, fill: 0xFFFFFF }); rightLabel.anchor.set(0.5, 0.5); rightLabel.x = 0; rightLabel.y = 0; rightButton.addChild(rightLabel); var jumpLabel = new Text2('JUMP', { size: 40, fill: 0xFFFFFF }); jumpLabel.anchor.set(0.5, 0.5); jumpLabel.x = 0; jumpLabel.y = 0; jumpButton.addChild(jumpLabel); var shootLabel = new Text2('SHOOT', { size: 30, fill: 0xFFFFFF }); shootLabel.anchor.set(0.5, 0.5); shootLabel.x = 0; shootLabel.y = 0; shootButton.addChild(shootLabel); leftButton.down = function () { leftPressed = true; leftButtonGraphics.alpha = 0.5; }; leftButton.up = function () { leftPressed = false; leftButtonGraphics.alpha = 1.0; }; rightButton.down = function () { rightPressed = true; rightButtonGraphics.alpha = 0.5; }; rightButton.up = function () { rightPressed = false; rightButtonGraphics.alpha = 1.0; }; jumpButton.down = function () { hero.jump(); jumpButtonGraphics.alpha = 0.5; }; jumpButton.up = function () { jumpButtonGraphics.alpha = 1.0; }; shootButton.down = function () { hero.shoot(); shootButtonGraphics.alpha = 0.5; }; shootButton.up = function () { shootButtonGraphics.alpha = 1.0; }; game.update = function () { // Handle continuous movement if (leftPressed) { hero.moveLeft(); } if (rightPressed) { hero.moveRight(); } // Update lives display livesText.setText('Lives: ' + lives); // Check win condition (reach top platform) if (hero.y < 950 && hero.intersects(platforms[platforms.length - 1])) { LK.showYouWin(); } // Clean up destroyed projectiles for (var i = projectiles.length - 1; i >= 0; i--) { if (!projectiles[i].parent) { projectiles.splice(i, 1); } } // Clean up destroyed enemies for (var i = enemies.length - 1; i >= 0; i--) { if (!enemies[i].parent) { enemies.splice(i, 1); } } // Clean up destroyed powerups for (var i = powerups.length - 1; i >= 0; i--) { if (!powerups[i].parent) { powerups.splice(i, 1); } } };
===================================================================
--- original.js
+++ change.js
@@ -11,8 +11,38 @@
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 1.0
});
+ var leftEye = self.attachAsset('enemyEye', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -10,
+ y: -35
+ });
+ var rightEye = self.attachAsset('enemyEye', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 10,
+ y: -35
+ });
+ var spike1 = self.attachAsset('enemySpike', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ x: -15,
+ y: -45
+ });
+ var spike2 = self.attachAsset('enemySpike', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ x: 0,
+ y: -50
+ });
+ var spike3 = self.attachAsset('enemySpike', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ x: 15,
+ y: -45
+ });
self.velocityX = 3;
self.direction = 1;
self.startX = 0;
self.patrolDistance = 200;
@@ -59,12 +89,19 @@
return self;
});
var Hero = Container.expand(function () {
var self = Container.call(this);
- var heroGraphics = self.attachAsset('hero', {
+ var heroBody = self.attachAsset('heroBody', {
anchorX: 0.5,
anchorY: 1.0
});
+ var heroHead = self.attachAsset('heroHead', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ x: 0,
+ y: -45
+ });
+ var heroGraphics = heroBody;
self.velocityX = 0;
self.velocityY = 0;
self.speed = 8;
self.jumpPower = -25;
@@ -152,16 +189,43 @@
anchorY: 0.5,
width: width || 300,
height: height || 40
});
+ var leftEdge = self.attachAsset('platformEdge', {
+ anchorX: 1.0,
+ anchorY: 0.5,
+ x: -(width || 300) / 2,
+ y: 0
+ });
+ var rightEdge = self.attachAsset('platformEdge', {
+ anchorX: 0.0,
+ anchorY: 0.5,
+ x: (width || 300) / 2,
+ y: 0
+ });
+ var grass = self.attachAsset('platformGrass', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ width: width || 300,
+ x: 0,
+ y: -(height || 40) / 2
+ });
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
+ var powerupGlow = self.attachAsset('powerupGlow', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
var powerupGraphics = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
+ var powerupCore = self.attachAsset('powerupCore', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.bobOffset = 0;
self.startY = 0;
self.update = function () {
// Bobbing animation
@@ -188,8 +252,12 @@
return self;
});
var Projectile = Container.expand(function () {
var self = Container.call(this);
+ var projectileGlow = self.attachAsset('projectileGlow', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
var projectileGraphics = self.attachAsset('projectile', {
anchorX: 0.5,
anchorY: 0.5
});
@@ -382,29 +450,45 @@
var leftPressed = false;
var rightPressed = false;
// Control buttons with visual indicators
var leftButton = game.addChild(new Container());
+var leftButtonBorder = leftButton.attachAsset('controlButtonBorder', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
var leftButtonGraphics = leftButton.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5
});
leftButton.x = 150;
leftButton.y = 2550;
var rightButton = game.addChild(new Container());
+var rightButtonBorder = rightButton.attachAsset('controlButtonBorder', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
var rightButtonGraphics = rightButton.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5
});
rightButton.x = 350;
rightButton.y = 2550;
var jumpButton = game.addChild(new Container());
+var jumpButtonBorder = jumpButton.attachAsset('jumpButtonBorder', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
var jumpButtonGraphics = jumpButton.attachAsset('jumpButton', {
anchorX: 0.5,
anchorY: 0.5
});
jumpButton.x = 1848;
jumpButton.y = 2550;
var shootButton = game.addChild(new Container());
+var shootButtonBorder = shootButton.attachAsset('shootButtonBorder', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
var shootButtonGraphics = shootButton.attachAsset('shootButton', {
anchorX: 0.5,
anchorY: 0.5
});