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 }); 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 heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 1.0 }); 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 }); return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerupGraphics = self.attachAsset('powerup', { 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 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 (invisible touch areas) var leftButton = game.addChild(new Container()); leftButton.x = 0; leftButton.y = 2200; leftButton.width = 200; leftButton.height = 532; var rightButton = game.addChild(new Container()); rightButton.x = 200; rightButton.y = 2200; rightButton.width = 200; rightButton.height = 532; var jumpButton = game.addChild(new Container()); jumpButton.x = 1648; jumpButton.y = 2200; jumpButton.width = 400; jumpButton.height = 532; var shootButton = game.addChild(new Container()); shootButton.x = 1400; shootButton.y = 2200; shootButton.width = 248; shootButton.height = 532; leftButton.down = function () { leftPressed = true; }; leftButton.up = function () { leftPressed = false; }; rightButton.down = function () { rightPressed = true; }; rightButton.up = function () { rightPressed = false; }; jumpButton.down = function () { hero.jump(); }; shootButton.down = function () { hero.shoot(); }; 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
@@ -1,6 +1,455 @@
-/****
+/****
+* 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
+ });
+ 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 heroGraphics = self.attachAsset('hero', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ 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
+ });
+ return self;
+});
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerupGraphics = self.attachAsset('powerup', {
+ 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 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: 0x000000
-});
\ No newline at end of file
+ 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 (invisible touch areas)
+var leftButton = game.addChild(new Container());
+leftButton.x = 0;
+leftButton.y = 2200;
+leftButton.width = 200;
+leftButton.height = 532;
+var rightButton = game.addChild(new Container());
+rightButton.x = 200;
+rightButton.y = 2200;
+rightButton.width = 200;
+rightButton.height = 532;
+var jumpButton = game.addChild(new Container());
+jumpButton.x = 1648;
+jumpButton.y = 2200;
+jumpButton.width = 400;
+jumpButton.height = 532;
+var shootButton = game.addChild(new Container());
+shootButton.x = 1400;
+shootButton.y = 2200;
+shootButton.width = 248;
+shootButton.height = 532;
+leftButton.down = function () {
+ leftPressed = true;
+};
+leftButton.up = function () {
+ leftPressed = false;
+};
+rightButton.down = function () {
+ rightPressed = true;
+};
+rightButton.up = function () {
+ rightPressed = false;
+};
+jumpButton.down = function () {
+ hero.jump();
+};
+shootButton.down = function () {
+ hero.shoot();
+};
+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);
+ }
+ }
+};
\ No newline at end of file