Code edit (1 edits merged)
Please save this source code
User prompt
move enemy and player 150 pixels higher
User prompt
player starting position in the y axis should be the same as the one its going to keep on moving in the game after jumping. same for enemy
User prompt
when we update starting position of player we should also update the position where they normally move
User prompt
move player and enemy 200 pixels higher
User prompt
player and enemy should be 100 pixiels higher, where the floor is
Code edit (10 edits merged)
Please save this source code
User prompt
nice, can you now triple the size of the player and the enemy
User prompt
now only 40 pixels higher
User prompt
actually move them both 100 pixels higher
User prompt
player and enemy starting position and movement should be 200 pixels from the bottom of the screen
User prompt
Please fix the bug: 'enemy is not defined' in or related to this line: 'enemy.y = 2732 / 2;' Line Number: 169
User prompt
player and enemy should be 500 pixels down
User prompt
add 3 different backgrounds to use in paraxl scrolling and they should be changed randomly
Code edit (1 edits merged)
Please save this source code
User prompt
transitioning from one frame to the other should be smooth and have not white or transparent space between them
Code edit (3 edits merged)
Please save this source code
User prompt
enemy shoudl also have several images like player to replicate movement. enemy will have 2
Code edit (4 edits merged)
Please save this source code
User prompt
player image shoudl last a little longe before the next one appears so that there are no gaps between them
User prompt
how can we make mario not have glitches? maybe wait a little longer before swaping images in run animation?
User prompt
now make sure background is continuous
User prompt
add lateral paralx scrolling to seem like player is moving
User prompt
reduce jump height
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ // Define a class for enemies var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.passed = false; // Flag to track if player passed this enemy self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Define a class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player_run1', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; // Not used currently, but kept for potential horizontal movement self.jumpHeight = 50; // Higher jump for better feel self.isJumping = false; self.velocityY = 0; self.runFrames = ['player_run1', 'player_run2', 'player_run3']; self.runFrameIndex = 0; self.runFrameCounter = 0; // Counter to control animation speed self.runFrameDelay = 8; // Update run frame every 8 updates (~7.5 FPS at 60 FPS) self.update = function () { if (self.isJumping) { // Handle jumping physics self.y += self.velocityY; self.velocityY += 0.8; // Slightly stronger gravity if (self.y >= 2732 / 2) { // Landed on ground self.y = 2732 / 2; self.isJumping = false; self.velocityY = 0; // Switch back to running animation playerGraphics.destroy(); playerGraphics = self.attachAsset(self.runFrames[self.runFrameIndex], { anchorX: 0.5, anchorY: 0.5 }); } } else { // Handle running animation self.runFrameCounter++; if (self.runFrameCounter >= self.runFrameDelay) { self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length; playerGraphics.destroy(); playerGraphics = self.attachAsset(self.runFrames[self.runFrameIndex], { anchorX: 0.5, anchorY: 0.5 }); self.runFrameCounter = 0; } } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; playerGraphics.destroy(); playerGraphics = self.attachAsset('player_jump', { anchorX: 0.5, anchorY: 0.5 }); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); background.x = 0; background.y = 0; // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; // Center horizontally player.y = 2732 / 2; // Ground level // Initialize enemies var enemies = []; var enemySpawnInterval = 100; // Initial spawn interval var enemySpawnCounter = 0; // Create a new Text2 object to display the score var scoreText = new Text2('0', { size: 100, fill: 0xFFFFFF }); // Add the score text to the game GUI at the top center of the screen LK.gui.top.addChild(scoreText); scoreText.x = 2048 / 2; scoreText.y = 0; // Handle game updates game.update = function () { player.update(); // Spawn enemies enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var enemy = new Enemy(); enemy.x = 2048; // Start at right edge enemy.y = 2732 / 2; // Ground level enemies.push(enemy); game.addChild(enemy); // Randomize next spawn interval enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; } // Update enemies and check collisions for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 1000); // Red flash on collision LK.showGameOver(); } else if (player.x > enemies[j].x && !enemies[j].passed) { enemies[j].passed = true; LK.setScore(LK.getScore() + 1); scoreText.setText(LK.getScore()); } // Clean up destroyed enemies if (enemies[j].x < -50) { enemies.splice(j, 1); } } }; // Handle player jump on input game.down = function (x, y, obj) { player.jump(); };
/****
* Classes
****/
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.passed = false; // Flag to track if player passed this enemy
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
// Define a class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player_run1', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Not used currently, but kept for potential horizontal movement
self.jumpHeight = 50; // Higher jump for better feel
self.isJumping = false;
self.velocityY = 0;
self.runFrames = ['player_run1', 'player_run2', 'player_run3'];
self.runFrameIndex = 0;
self.runFrameCounter = 0; // Counter to control animation speed
self.runFrameDelay = 8; // Update run frame every 8 updates (~7.5 FPS at 60 FPS)
self.update = function () {
if (self.isJumping) {
// Handle jumping physics
self.y += self.velocityY;
self.velocityY += 0.8; // Slightly stronger gravity
if (self.y >= 2732 / 2) {
// Landed on ground
self.y = 2732 / 2;
self.isJumping = false;
self.velocityY = 0;
// Switch back to running animation
playerGraphics.destroy();
playerGraphics = self.attachAsset(self.runFrames[self.runFrameIndex], {
anchorX: 0.5,
anchorY: 0.5
});
}
} else {
// Handle running animation
self.runFrameCounter++;
if (self.runFrameCounter >= self.runFrameDelay) {
self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length;
playerGraphics.destroy();
playerGraphics = self.attachAsset(self.runFrames[self.runFrameIndex], {
anchorX: 0.5,
anchorY: 0.5
});
self.runFrameCounter = 0;
}
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
playerGraphics.destroy();
playerGraphics = self.attachAsset('player_jump', {
anchorX: 0.5,
anchorY: 0.5
});
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
background.x = 0;
background.y = 0;
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2; // Center horizontally
player.y = 2732 / 2; // Ground level
// Initialize enemies
var enemies = [];
var enemySpawnInterval = 100; // Initial spawn interval
var enemySpawnCounter = 0;
// Create a new Text2 object to display the score
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
// Add the score text to the game GUI at the top center of the screen
LK.gui.top.addChild(scoreText);
scoreText.x = 2048 / 2;
scoreText.y = 0;
// Handle game updates
game.update = function () {
player.update();
// Spawn enemies
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = 2048; // Start at right edge
enemy.y = 2732 / 2; // Ground level
enemies.push(enemy);
game.addChild(enemy);
// Randomize next spawn interval
enemySpawnInterval = Math.floor(Math.random() * 150) + 50;
enemySpawnCounter = 0;
}
// Update enemies and check collisions
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
LK.effects.flashScreen(0xff0000, 1000); // Red flash on collision
LK.showGameOver();
} else if (player.x > enemies[j].x && !enemies[j].passed) {
enemies[j].passed = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
}
// Clean up destroyed enemies
if (enemies[j].x < -50) {
enemies.splice(j, 1);
}
}
};
// Handle player jump on input
game.down = function (x, y, obj) {
player.jump();
};