Code edit (3 edits merged)
Please save this source code
User prompt
ahora quiero que al caminar el jugador deje un rastro en el suelo que no se borre
User prompt
puedes hacer que al presionar los botones de direccion el jugador se incline hacia la direccion correspondiente ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (2 edits merged)
Please save this source code
User prompt
haz que al mantener presionado los botones de direccion se agranden un poco ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'directionAsset')' in or related to this line: 'var rightButton = self.directionAsset('DIRECCION', {' Line Number: 295
Code edit (5 edits merged)
Please save this source code
User prompt
cuando el jugador se mueva a la izquierda invertir la imagen
Code edit (3 edits merged)
Please save this source code
User prompt
lo que quiero es que el suelo tenga un asset diferente del de las plataformas flotantes
User prompt
quiero que la plataforma inferior sea un objeto separado de las plataformas flotantes
User prompt
separa la plataforma que representa el suelo del nivel de las plataformas flotantes
User prompt
elimina la primera plataforma
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
ahora elimina el boton de salto
User prompt
quiero que la funcion de saltar se pueda realizar al presionar la pantalla, deja el sistema de salto tal cual esta, solo haz que se active al presionar cualquier zona de la pantalla
Code edit (13 edits merged)
Please save this source code
User prompt
la plataforma inferior estirala mas hacia abajo
Code edit (1 edits merged)
Please save this source code
User prompt
la camara no llega hasta el final del nivel
Code edit (5 edits merged)
Please save this source code
User prompt
sube un poco la camara
/****
* 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.canJump = true;
self.speed = 8;
self.jumpPower = -25;
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 canJump when landing on ground
if (self.onGround === true) {
self.canJump = true;
}
// Friction
self.velocityX *= 0.85;
};
self.jump = function () {
if (self.onGround && self.canJump) {
self.velocityY = self.jumpPower;
self.canJump = 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
****/
// Set background using cielocaricatura image
game.setBackgroundColor(0x87ceeb);
var background = game.addChild(LK.getAsset('cielocaricatura', {
anchorX: 0,
anchorY: 0.2,
scaleX: 40.96,
// Scale to cover full level width (4000/100)
scaleY: 27.32 // Scale to fit screen height (2732/100)
}));
background.x = 0;
background.y = 0;
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/8', {
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: 500
} // 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() {
// Reset ground state - hero is only on ground if touching a platform
hero.onGround = false;
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;
hero.canJump = 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 follows hero smoothly - adjusted view area for larger screen
var targetX = hero.x - 450; // Center horizontally (2048/2 = 1024)
var targetY = hero.y - 1000; // Center vertically (2732/2 = 1366) - raised camera
// Smooth camera movement with good responsiveness
camera.x += (targetX - camera.x) * 0.1;
camera.y += (targetY - camera.y) * 0.1;
// Keep camera within level bounds - adjusted for larger view and scale factor
if (camera.x < 0) {
camera.x = 0;
}
if (camera.x > levelWidth - 1024) {
// Adjusted for 2.0 scale (2048/2 = 1024)
camera.x = levelWidth - 1024;
}
if (camera.y < -600) {
camera.y = -600;
}
if (camera.y > 350) {
camera.y = 350;
}
// Apply camera position to game world with scale factor
game.x = -camera.x * 2.0;
game.y = -camera.y * 1.0;
}
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 && hero.canJump) {
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.canJump) {
hero.jump();
}
}
}
isSwipeActive = false;
};
game.update = function () {
// Handle continuous button presses
if (leftPressed) {
hero.moveLeft();
}
if (rightPressed) {
hero.moveRight();
}
// Jump button remains always enabled
jumpButton.alpha = 1.0;
jumpButton.tint = 0xFFFFFF;
jumpButton.interactive = true;
// Jump is handled directly in jumpButton.down event
checkPlatformCollisions();
checkEnemyCollisions();
checkCoinCollisions();
checkGoalCollision();
checkBounds();
updateCamera();
};
// Initialize level
createLevel();
// Scale game up to increase screen size
tween(game, {
scaleX: 2.0,
scaleY: 2.0
}, {
duration: 1000,
easing: tween.easeInOut
}); ===================================================================
--- original.js
+++ change.js
@@ -340,9 +340,9 @@
}, {
x: 0,
y: 700,
width: levelWidth,
- height: 200
+ height: 500
} // Ground
];
for (var i = 0; i < platformData.length; i++) {
var data = platformData[i];
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