Code edit (5 edits merged)
Please save this source code
User prompt
quita la funcion de deshabilitar el boton de saltar
User prompt
ahora quiero que cuando el jugador este en el suelo se habilite el boton de saltar para poder pulsarlo
User prompt
no quiero que pueda atravesar las plataformas
User prompt
quiero que pueda subir a las plataformas
User prompt
haz que se detecte cuando el jugador coliciona con las plataforma
Code edit (1 edits merged)
Please save this source code
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
/****
* 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 = -30;
self.gravity = 0.8;
self.maxFallSpeed = 50;
self.lives = 3;
self.invulnerable = false;
self.invulnerableTime = 0;
self.update = function () {
// Apply gravity
if (self.onGround === false) {
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 === true) {
self.velocityY = self.jumpPower;
self.onGround = false;
}
};
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;
var jumpButton = new Text2('⬆', {
size: 200,
fill: 0xFFFFFF
});
jumpButton.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(jumpButton);
jumpButton.x = -100;
jumpButton.y = -300;
// 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];
// Define hero boundaries
var heroLeft = hero.x - 40;
var heroRight = hero.x + 40;
var heroTop = hero.y - 80;
var heroBottom = hero.y;
var heroCenterX = hero.x;
var heroCenterY = hero.y - 40;
// Define platform boundaries
var platformLeft = platform.x;
var platformRight = platform.x + platform.platformWidth;
var platformTop = platform.y;
var platformBottom = platform.y + platform.platformHeight;
// Check if hero is overlapping with platform
var horizontalOverlap = heroRight > platformLeft && heroLeft < platformRight;
var verticalOverlap = heroBottom > platformTop && heroTop < platformBottom;
if (horizontalOverlap && verticalOverlap) {
// Calculate overlap distances
var overlapLeft = heroRight - platformLeft;
var overlapRight = platformRight - heroLeft;
var overlapTop = heroBottom - platformTop;
var overlapBottom = platformBottom - heroTop;
// Find minimum overlap to determine collision direction
var minOverlap = Math.min(overlapLeft, overlapRight, overlapTop, overlapBottom);
// Resolve collision based on minimum overlap
if (minOverlap === overlapTop && hero.velocityY >= 0) {
// Landing on top of platform
hero.y = platformTop;
hero.velocityY = 0;
hero.onGround = true;
} else if (minOverlap === overlapBottom && hero.velocityY < 0) {
// Hitting platform from below
hero.y = platformBottom + 80;
hero.velocityY = 0;
} else if (minOverlap === overlapLeft && hero.velocityX > 0) {
// Hitting platform from left side
hero.x = platformLeft - 40;
hero.velocityX = 0;
} else if (minOverlap === overlapRight && hero.velocityX < 0) {
// Hitting platform from right side
hero.x = platformRight + 40;
hero.velocityX = 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 - 1048) {
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;
};
// Jump button event handlers
jumpButton.down = function (x, y, obj) {
if (hero && hero.onGround && jumpButton.interactive) {
hero.jump();
}
};
jumpButton.up = function (x, y, obj) {
// No action needed on release
};
// 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();
}
// Update jump button visual state and interactivity
if (hero.onGround) {
jumpButton.alpha = 1.0; // Fully visible when can jump
jumpButton.tint = 0xFFFFFF; // White tint when available
jumpButton.interactive = true; // Enable button interaction
} else {
jumpButton.alpha = 0.5; // Semi-transparent when cannot jump
jumpButton.tint = 0x888888; // Gray tint when unavailable
jumpButton.interactive = false; // Disable button interaction
}
// Jump is handled directly in jumpButton.down event
checkPlatformCollisions();
checkEnemyCollisions();
checkCoinCollisions();
checkGoalCollision();
checkBounds();
updateCamera();
};
// Initialize level
createLevel(); ===================================================================
--- original.js
+++ change.js
@@ -404,33 +404,48 @@
}
function checkPlatformCollisions() {
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
- // Check horizontal overlap first
- if (hero.x + 40 > platform.x && hero.x - 40 < platform.x + platform.platformWidth) {
- // Landing on top of platform - hero's bottom touching platform's top
- if (hero.velocityY >= 0 && hero.y >= platform.y - 5 && hero.y <= platform.y + 20) {
- hero.y = platform.y;
+ // Define hero boundaries
+ var heroLeft = hero.x - 40;
+ var heroRight = hero.x + 40;
+ var heroTop = hero.y - 80;
+ var heroBottom = hero.y;
+ var heroCenterX = hero.x;
+ var heroCenterY = hero.y - 40;
+ // Define platform boundaries
+ var platformLeft = platform.x;
+ var platformRight = platform.x + platform.platformWidth;
+ var platformTop = platform.y;
+ var platformBottom = platform.y + platform.platformHeight;
+ // Check if hero is overlapping with platform
+ var horizontalOverlap = heroRight > platformLeft && heroLeft < platformRight;
+ var verticalOverlap = heroBottom > platformTop && heroTop < platformBottom;
+ if (horizontalOverlap && verticalOverlap) {
+ // Calculate overlap distances
+ var overlapLeft = heroRight - platformLeft;
+ var overlapRight = platformRight - heroLeft;
+ var overlapTop = heroBottom - platformTop;
+ var overlapBottom = platformBottom - heroTop;
+ // Find minimum overlap to determine collision direction
+ var minOverlap = Math.min(overlapLeft, overlapRight, overlapTop, overlapBottom);
+ // Resolve collision based on minimum overlap
+ if (minOverlap === overlapTop && hero.velocityY >= 0) {
+ // Landing on top of platform
+ hero.y = platformTop;
hero.velocityY = 0;
hero.onGround = true;
- return; // Exit early to prevent multiple collision checks
- }
- // Hitting platform from below - hero's top hitting platform's bottom
- else if (hero.velocityY < 0 && hero.y - 80 <= platform.y + platform.platformHeight && hero.y - 80 >= platform.y + platform.platformHeight - 20) {
- hero.y = platform.y + platform.platformHeight + 80;
+ } else if (minOverlap === overlapBottom && hero.velocityY < 0) {
+ // Hitting platform from below
+ hero.y = platformBottom + 80;
hero.velocityY = 0;
- }
- }
- // Check vertical overlap for side collisions
- if (hero.y > platform.y - 80 && hero.y < platform.y + platform.platformHeight) {
- // Left side collision - hero moving right into platform's left side
- if (hero.velocityX > 0 && hero.x + 40 >= platform.x && hero.x + 40 <= platform.x + 20) {
- hero.x = platform.x - 40;
+ } else if (minOverlap === overlapLeft && hero.velocityX > 0) {
+ // Hitting platform from left side
+ hero.x = platformLeft - 40;
hero.velocityX = 0;
- }
- // Right side collision - hero moving left into platform's right side
- else if (hero.velocityX < 0 && hero.x - 40 <= platform.x + platform.platformWidth && hero.x - 40 >= platform.x + platform.platformWidth - 20) {
- hero.x = platform.x + platform.platformWidth + 40;
+ } else if (minOverlap === overlapRight && hero.velocityX < 0) {
+ // Hitting platform from right side
+ hero.x = platformRight + 40;
hero.velocityX = 0;
}
}
}
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