Code edit (8 edits merged)
Please save this source code
User prompt
haz que cuando el jugador este saltando o cayendo el boton de saltar se deshabilite, pero cuando vuelva a tocar el suelo el boton saltar se vuelva a habilitar
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
haz que el boton de saltar se vuelva a activar cuando el jugador vuelva a tocar el suelo
User prompt
has que al saltar, el boton de saltar se bloquee momentaneamente hasta que el jugador toque el suelo nuevamente
Code edit (1 edits merged)
Please save this source code
User prompt
haz que cuando el jugador salte, no pueda volver a saltar hasta que este en el suelo nuevamente
Code edit (9 edits merged)
Please save this source code
User prompt
coloca el boton de saltar por encima del boton derecha
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
al presionar el boton de saltar debera ejecutarse el jumpPower
Code edit (3 edits merged)
Please save this source code
User prompt
agrega un boton para saltar
Code edit (1 edits merged)
Please save this source code
User prompt
que el valor del salto sea mayor a la gravedad
User prompt
restale un poco el valor a la gravedad
User prompt
el boton de saltar no funciona, mejor crea una funcion que permita que al deslizar en la pantalla hacia arriba el jugador salte
User prompt
remplaza la textura del boton saltar por un triangulo apuntando hacia arriba
User prompt
al dar click sobre el boton saltar el jugador debe aumentar su valor vertical el 500
User prompt
al dar click sobre el boton saltar el jugador debe subir y luego volver a caer
User prompt
el boton de saltar no funciona, solucionalo
User prompt
coloca el boton de saltar en la parte inferior central
User prompt
permite que si el jugador esta tocando el suelo pueda saltar utilizando el boton de saltar
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.rotationSpeed = 0.1;
self.update = function () {
if (!self.collected) {
coinGraphics.rotation += self.rotationSpeed;
}
};
self.collect = function () {
if (!self.collected) {
self.collected = true;
LK.getSound('coin').play();
LK.setScore(LK.getScore() + 50);
coinsCollected++;
updateScoreDisplay();
updateCoinDisplay();
tween(self, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
}
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityX = 2;
self.speed = 2;
self.alive = true;
self.direction = 1;
self.update = function () {
if (!self.alive) {
return;
}
self.x += self.velocityX * self.direction;
// Reverse direction at platform edges
var onPlatform = false;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (self.y >= platform.y - 5 && self.y <= platform.y + platform.platformHeight + 5) {
if (self.x < platform.x || self.x > platform.x + platform.platformWidth) {
self.direction *= -1;
break;
}
onPlatform = true;
}
}
if (!onPlatform) {
self.direction *= -1;
}
};
self.defeat = function () {
self.alive = false;
LK.getSound('enemyHit').play();
LK.setScore(LK.getScore() + 100);
updateScoreDisplay();
tween(self, {
alpha: 0,
scaleX: 0,
scaleY: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
var Goal = Container.expand(function () {
var self = Container.call(this);
var goalGraphics = self.attachAsset('goal', {
anchorX: 0.5,
anchorY: 1.0
});
self.reached = false;
self.reachGoal = function () {
if (!self.reached) {
self.reached = true;
LK.setScore(LK.getScore() + 1000);
updateScoreDisplay();
LK.showYouWin();
}
};
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.onGround = false;
self.speed = 8;
self.jumpPower = -100;
self.gravity = 0.8;
self.maxFallSpeed = 20;
self.lives = 3;
self.invulnerable = false;
self.invulnerableTime = 0;
self.update = function () {
// Apply gravity
if (!self.onGround) {
self.velocityY += self.gravity;
if (self.velocityY > self.maxFallSpeed) {
self.velocityY = self.maxFallSpeed;
}
}
// Apply velocities
self.x += self.velocityX;
self.y += self.velocityY;
// Handle invulnerability
if (self.invulnerable) {
self.invulnerableTime--;
heroGraphics.alpha = Math.sin(self.invulnerableTime * 0.3) * 0.5 + 0.5;
if (self.invulnerableTime <= 0) {
self.invulnerable = false;
heroGraphics.alpha = 1;
}
}
// Reset ground state
self.onGround = false;
// Friction
self.velocityX *= 0.85;
};
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.takeDamage = function () {
if (!self.invulnerable) {
self.lives--;
self.invulnerable = true;
self.invulnerableTime = 120;
LK.effects.flashScreen(0xff0000, 500);
updateLivesDisplay();
if (self.lives <= 0) {
LK.showGameOver();
}
}
};
return self;
});
var Platform = Container.expand(function (width, height) {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0,
anchorY: 0,
width: width || 300,
height: height || 40
});
self.platformWidth = width || 300;
self.platformHeight = height || 40;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var hero;
var platforms = [];
var enemies = [];
var coins = [];
var goal;
var camera = {
x: 0,
y: 0
};
var levelWidth = 4000;
var coinsCollected = 0;
var totalCoins = 0;
// Button controls only
var leftPressed = false;
var rightPressed = false;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topLeft.addChild(scoreText);
scoreText.x = 120;
scoreText.y = 20;
var livesText = new Text2('Lives: 3', {
size: 60,
fill: 0xFFFFFF
});
livesText.anchor.set(1, 0);
LK.gui.topRight.addChild(livesText);
var coinText = new Text2('Coins: 0/0', {
size: 50,
fill: 0xFFFF00
});
coinText.anchor.set(0.5, 0);
LK.gui.top.addChild(coinText);
// Control buttons
var leftButton = new Text2('◀', {
size: 120,
fill: 0xFFFFFF
});
leftButton.anchor.set(0.5, 0.5);
LK.gui.bottomLeft.addChild(leftButton);
leftButton.x = 100;
leftButton.y = -150;
var rightButton = new Text2('▶', {
size: 120,
fill: 0xFFFFFF
});
rightButton.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(rightButton);
rightButton.x = -100;
rightButton.y = -150;
// Swipe detection variables
var swipeStartY = 0;
var swipeStartTime = 0;
var isSwipeActive = false;
var swipeThreshold = 100; // Minimum distance for swipe
var swipeTimeLimit = 500; // Maximum time for swipe in milliseconds
function updateScoreDisplay() {
scoreText.setText('Score: ' + LK.getScore());
}
function updateLivesDisplay() {
livesText.setText('Lives: ' + hero.lives);
}
function updateCoinDisplay() {
coinText.setText('Coins: ' + coinsCollected + '/' + totalCoins);
}
function createLevel() {
// Create hero
hero = game.addChild(new Hero());
hero.x = 200;
hero.y = 600;
// Create platforms
var platformData = [{
x: 0,
y: 650,
width: 400,
height: 40
}, {
x: 600,
y: 550,
width: 300,
height: 40
}, {
x: 1100,
y: 450,
width: 250,
height: 40
}, {
x: 1500,
y: 350,
width: 200,
height: 40
}, {
x: 1900,
y: 450,
width: 300,
height: 40
}, {
x: 2400,
y: 550,
width: 250,
height: 40
}, {
x: 2900,
y: 350,
width: 200,
height: 40
}, {
x: 3300,
y: 250,
width: 300,
height: 40
}, {
x: 3800,
y: 350,
width: 200,
height: 40
}, {
x: 0,
y: 700,
width: levelWidth,
height: 100
} // Ground
];
for (var i = 0; i < platformData.length; i++) {
var data = platformData[i];
var platform = game.addChild(new Platform(data.width, data.height));
platform.x = data.x;
platform.y = data.y;
platforms.push(platform);
}
// Create enemies
var enemyPositions = [{
x: 700,
y: 550
}, {
x: 1200,
y: 450
}, {
x: 2000,
y: 450
}, {
x: 2500,
y: 550
}, {
x: 3400,
y: 250
}];
for (var j = 0; j < enemyPositions.length; j++) {
var enemyPos = enemyPositions[j];
var enemy = game.addChild(new Enemy());
enemy.x = enemyPos.x;
enemy.y = enemyPos.y;
enemies.push(enemy);
}
// Create coins
var coinPositions = [{
x: 750,
y: 500
}, {
x: 1200,
y: 400
}, {
x: 1600,
y: 300
}, {
x: 2050,
y: 400
}, {
x: 2550,
y: 500
}, {
x: 3050,
y: 300
}, {
x: 3450,
y: 200
}, {
x: 3900,
y: 300
}];
totalCoins = coinPositions.length;
updateCoinDisplay();
for (var k = 0; k < coinPositions.length; k++) {
var coinPos = coinPositions[k];
var coin = game.addChild(new Coin());
coin.x = coinPos.x;
coin.y = coinPos.y;
coins.push(coin);
}
// Create goal
goal = game.addChild(new Goal());
goal.x = 3900;
goal.y = 350;
}
function checkPlatformCollisions() {
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
// Check if hero is colliding with platform
if (hero.x > platform.x - 40 && hero.x < platform.x + platform.platformWidth + 40) {
if (hero.y > platform.y - 5 && hero.y < platform.y + platform.platformHeight + 80) {
// Landing on top of platform
if (hero.velocityY > 0 && hero.y - 80 < platform.y) {
hero.y = platform.y;
hero.velocityY = 0;
hero.onGround = true;
}
// Hitting platform from below
else if (hero.velocityY < 0 && hero.y > platform.y + platform.platformHeight) {
hero.y = platform.y + platform.platformHeight + 80;
hero.velocityY = 0;
}
}
}
}
}
function checkEnemyCollisions() {
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
if (!enemy.alive) {
continue;
}
if (hero.intersects(enemy)) {
// Check if hero is jumping on enemy
if (hero.velocityY > 0 && hero.y < enemy.y - 30) {
enemy.defeat();
enemies.splice(i, 1);
hero.velocityY = -15; // Bounce
} else {
hero.takeDamage();
}
}
}
}
function checkCoinCollisions() {
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (!coin.collected && hero.intersects(coin)) {
coin.collect();
coins.splice(i, 1);
}
}
}
function checkGoalCollision() {
if (!goal.reached && hero.intersects(goal)) {
goal.reachGoal();
}
}
function updateCamera() {
camera.x = hero.x - 1024;
camera.y = hero.y - 2200; // Zoom in so ground appears at bottom
if (camera.x < 0) {
camera.x = 0;
}
if (camera.x > levelWidth - 2048) {
camera.x = levelWidth - 2048;
}
if (camera.y < -500) {
camera.y = -500;
}
if (camera.y > 0) {
camera.y = 0;
}
game.x = -camera.x;
game.y = -camera.y;
}
function checkBounds() {
// Check if hero fell off the world
if (hero.y > 1000) {
hero.takeDamage();
hero.x = 200;
hero.y = 600;
hero.velocityX = 0;
hero.velocityY = 0;
}
}
// Button event handlers
leftButton.down = function (x, y, obj) {
leftPressed = true;
};
leftButton.up = function (x, y, obj) {
leftPressed = false;
};
rightButton.down = function (x, y, obj) {
rightPressed = true;
};
rightButton.up = function (x, y, obj) {
rightPressed = false;
};
// Touch controls with swipe detection
game.down = function (x, y, obj) {
// Start swipe detection
swipeStartY = y;
swipeStartTime = Date.now();
isSwipeActive = true;
};
game.move = function (x, y, obj) {
// Track swipe movement but don't perform action yet
};
game.up = function (x, y, obj) {
if (isSwipeActive) {
var swipeDistance = swipeStartY - y; // Positive if swiping up
var swipeTime = Date.now() - swipeStartTime;
// Check if this is an upward swipe
if (swipeDistance > swipeThreshold && swipeTime < swipeTimeLimit) {
// Trigger jump if hero is on ground
if (hero && hero.onGround) {
hero.jump();
}
}
}
isSwipeActive = false;
};
game.update = function () {
// Handle continuous button presses
if (leftPressed) {
hero.moveLeft();
}
if (rightPressed) {
hero.moveRight();
}
// Jump is handled directly in jumpButton.down event
checkPlatformCollisions();
checkEnemyCollisions();
checkCoinCollisions();
checkGoalCollision();
checkBounds();
updateCamera();
};
// Initialize level
createLevel(); ===================================================================
--- original.js
+++ change.js
@@ -51,9 +51,11 @@
self.speed = 2;
self.alive = true;
self.direction = 1;
self.update = function () {
- if (!self.alive) return;
+ if (!self.alive) {
+ return;
+ }
self.x += self.velocityX * self.direction;
// Reverse direction at platform edges
var onPlatform = false;
for (var i = 0; i < platforms.length; i++) {
@@ -114,9 +116,9 @@
self.velocityX = 0;
self.velocityY = 0;
self.onGround = false;
self.speed = 8;
- self.jumpPower = -30;
+ self.jumpPower = -100;
self.gravity = 0.8;
self.maxFallSpeed = 20;
self.lives = 3;
self.invulnerable = false;
@@ -416,9 +418,11 @@
}
function checkEnemyCollisions() {
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
- if (!enemy.alive) continue;
+ if (!enemy.alive) {
+ continue;
+ }
if (hero.intersects(enemy)) {
// Check if hero is jumping on enemy
if (hero.velocityY > 0 && hero.y < enemy.y - 30) {
enemy.defeat();
@@ -446,12 +450,20 @@
}
function updateCamera() {
camera.x = hero.x - 1024;
camera.y = hero.y - 2200; // Zoom in so ground appears at bottom
- if (camera.x < 0) camera.x = 0;
- if (camera.x > levelWidth - 2048) camera.x = levelWidth - 2048;
- if (camera.y < -500) camera.y = -500;
- if (camera.y > 0) camera.y = 0;
+ if (camera.x < 0) {
+ camera.x = 0;
+ }
+ if (camera.x > levelWidth - 2048) {
+ camera.x = levelWidth - 2048;
+ }
+ if (camera.y < -500) {
+ camera.y = -500;
+ }
+ if (camera.y > 0) {
+ camera.y = 0;
+ }
game.x = -camera.x;
game.y = -camera.y;
}
function checkBounds() {
colocale la boca sonriendo, mostrando los dientes blancos
SUELO 2D DE METAL ESTILO CARTOON. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
HAZLO COMPLETAMENTE CUADRADO, ESQUINAZ RECTAS
dale un toque moderno, con sombras y reflejos, y reduce un poco el tamaño
COFRE DEL TESORO ESTILO CARTOON. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Quita la figura del centro y remplazala por un circulo con un borde no muy grueso
Dale un estilo cartoon y quítale el símbolo del centro
dibuja bien la cola, colocale los bigotes en zigzag
RATA MUTANTE MUSCULOZA, ESTILO CARTOON, JEFE FINAL. In-Game asset. 2d. High contrast. No shadows