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 ****/ var Background = Container.expand(function () { var self = Container.call(this); var backgrounds = ['background1', 'background2', 'background3']; var randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)]; var backgroundGraphics = self.attachAsset(randomBackground, { anchorX: 0, anchorY: 0 }); self.speed = 3; self.update = function () { self.x -= self.speed; if (self.x <= -2048) { self.x = 2048; } }; }); var Background2 = Container.expand(function () { var self = Container.call(this); var backgrounds = ['background1', 'background2', 'background3']; var randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)]; var backgroundGraphics = self.attachAsset(randomBackground, { anchorX: 0, anchorY: 0 }); self.speed = 3; self.update = function () { self.x -= self.speed; if (self.x <= -2048) { self.x = 2048; } }; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy1', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); self.speed = 6 + Math.random() * 2; self.passed = false; self.isJumping = false; self.velocityY = 0; self.groundY = 2732 - 400; // 400 pixels from bottom self.y = self.groundY; // Set initial position to ground level self.runFrames = ['enemy1', 'enemy2']; self.runFrameIndex = 0; self.runFrameCounter = 0; self.runFrameDelay = 20; self.swapSprite = function (newAsset) { var newGraphics = self.attachAsset(newAsset, { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); if (enemyGraphics) { enemyGraphics.destroy(); } enemyGraphics = newGraphics; }; self.update = function () { self.x -= self.speed; if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.9; if (self.y >= self.groundY) { self.y = self.groundY; self.isJumping = false; self.velocityY = 0; } } else if (Math.random() < 0.01) { self.isJumping = true; self.velocityY = -20 - Math.random() * 10; } self.runFrameCounter++; if (self.runFrameCounter >= self.runFrameDelay) { self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length; self.swapSprite(self.runFrames[self.runFrameIndex]); self.runFrameCounter = 0; } if (self.x < -100) { self.destroy(); } }; }); var Player = Container.expand(function () { var self = Container.call(this); var currentSprite = self.attachAsset('player_run1', { anchorX: 0.5, anchorY: 0.5, visible: true, scaleX: 1.5, scaleY: 1.5 }); var nextSprite = self.attachAsset('player_run1', { anchorX: 0.5, anchorY: 0.5, visible: false, scaleX: 1.5, scaleY: 1.5 }); self.currentAsset = 'player_run1'; self.speed = 5; self.jumpHeight = 25; self.isJumping = false; self.velocityY = 0; self.groundY = 2732 - 400; // 400 pixels from bottom self.y = self.groundY; // Set initial position to ground level self.runFrames = ['player_run1', 'player_run2', 'player_run3']; self.runFrameIndex = 0; self.runFrameCounter = 0; self.runFrameDelay = 10; self.swapSprite = function (newAsset) { if (self.currentAsset !== newAsset) { nextSprite = self.attachAsset(newAsset, { anchorX: 0.5, anchorY: 0.5, visible: true, scaleX: 1.5, scaleY: 1.5 }); currentSprite.visible = false; currentSprite.destroy(); currentSprite = nextSprite; self.currentAsset = newAsset; } }; self.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.9; if (self.y >= self.groundY) { self.y = self.groundY; self.isJumping = false; self.velocityY = 0; self.swapSprite(self.runFrames[self.runFrameIndex]); } } else { self.runFrameCounter++; if (self.runFrameCounter >= self.runFrameDelay) { self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length; self.swapSprite(self.runFrames[self.runFrameIndex]); self.runFrameCounter = 0; } } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; self.swapSprite('player_jump'); self.runFrameCounter = 0; } }; }); /**** * Initialize Game ****/ /**** *-Seperator- ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var background = game.addChild(new Background()); background.x = 0; background.y = 0; var background2 = game.addChild(new Background2()); background2.x = 2048; background2.y = 0; var player = game.addChild(new Player()); player.x = 2048 / 4; player.y = player.groundY; // Use groundY for initial position var enemies = []; var enemySpawnInterval = 80; var enemySpawnCounter = 0; var scoreText = new Text2('0', { size: 100, fill: 0xFFFFFF }); LK.gui.top.addChild(scoreText); scoreText.x = 2048 / 2; scoreText.y = 50; game.update = function () { background.update(); background2.update(); player.update(); enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var enemy = new Enemy(); enemy.x = 2048 + Math.random() * 200; enemy.y = enemy.groundY; // Use groundY for initial position enemies.push(enemy); game.addChild(enemy); enemySpawnInterval = Math.floor(Math.random() * 100) + 60; enemySpawnCounter = 0; } for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 1000); 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()); } if (enemies[j].x < -100) { enemies.splice(j, 1); } } }; game.down = function (x, y, obj) { player.jump(); };
===================================================================
--- original.js
+++ change.js
@@ -44,8 +44,10 @@
self.speed = 6 + Math.random() * 2;
self.passed = false;
self.isJumping = false;
self.velocityY = 0;
+ self.groundY = 2732 - 400; // 400 pixels from bottom
+ self.y = self.groundY; // Set initial position to ground level
self.runFrames = ['enemy1', 'enemy2'];
self.runFrameIndex = 0;
self.runFrameCounter = 0;
self.runFrameDelay = 20;
@@ -65,10 +67,10 @@
self.x -= self.speed;
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.9;
- if (self.y >= 2732 - 200) {
- self.y = 2732 - 200;
+ if (self.y >= self.groundY) {
+ self.y = self.groundY;
self.isJumping = false;
self.velocityY = 0;
}
} else if (Math.random() < 0.01) {
@@ -106,9 +108,10 @@
self.speed = 5;
self.jumpHeight = 25;
self.isJumping = false;
self.velocityY = 0;
- self.groundY = 2732 - 200;
+ self.groundY = 2732 - 400; // 400 pixels from bottom
+ self.y = self.groundY; // Set initial position to ground level
self.runFrames = ['player_run1', 'player_run2', 'player_run3'];
self.runFrameIndex = 0;
self.runFrameCounter = 0;
self.runFrameDelay = 10;
@@ -176,9 +179,9 @@
background2.x = 2048;
background2.y = 0;
var player = game.addChild(new Player());
player.x = 2048 / 4;
-player.y = player.groundY - 150;
+player.y = player.groundY; // Use groundY for initial position
var enemies = [];
var enemySpawnInterval = 80;
var enemySpawnCounter = 0;
var scoreText = new Text2('0', {
@@ -195,9 +198,9 @@
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = 2048 + Math.random() * 200;
- enemy.y = 2732 - 350;
+ enemy.y = enemy.groundY; // Use groundY for initial position
enemies.push(enemy);
game.addChild(enemy);
enemySpawnInterval = Math.floor(Math.random() * 100) + 60;
enemySpawnCounter = 0;