User prompt
add a little more gravity to make players jump and descend a little slower
Code edit (1 edits merged)
Please save this source code
User prompt
make gague bar more proportionat to the players jump heigh
User prompt
enemies should not jump
Code edit (1 edits merged)
Please save this source code
User prompt
gauge fill should be aligne with the left side of the gaugebar
User prompt
bar fill is starting i n the middle of the empty one, please move fill to the left ot match the bar
User prompt
gauge should start empty
User prompt
Gauge bar should be fill from left to right not from the center to the sides
User prompt
fill gauge from left to right
User prompt
Please fix the bug: 'Uncaught TypeError: clearInterval is not a function' in or related to this line: 'clearInterval(interval);' Line Number: 267
User prompt
Please fix the bug: 'Uncaught TypeError: setInterval is not a function' in or related to this line: 'var interval = setInterval(function () {' Line Number: 261
User prompt
create gauge bar that will define how high the player will jump
User prompt
Please fix the bug: 'Background is not defined' in or related to this line: 'var background = game.addChild(new Background());' Line Number: 171
User prompt
Please fix the bug: 'ReferenceError: Enemy is not defined' in or related to this line: 'var enemy = new Enemy();' Line Number: 224
User prompt
Please fix the bug: 'TypeError: gaugeFill.beginFill is not a function' in or related to this line: 'return "rgb(".concat(Math.floor(255 * (ratio * 2)), ", 255, 0)");' Line Number: 71
User prompt
Please fix the bug: 'Graphics is not a constructor' in or related to this line: 'var gaugeBackground = new Graphics();' Line Number: 40
User prompt
Please fix the bug: 'Background2 is not defined' in or related to this line: 'var background2 = game.addChild(new Background2());' Line Number: 183
User prompt
Please fix the bug: 'Background is not defined' in or related to this line: 'var background = game.addChild(new Background());' Line Number: 167
Code edit (1 edits merged)
Please save this source code
User prompt
after jumpin player shoudl land 30 pixels higher
User prompt
move player 10 pixels higher
User prompt
good move player 20 pixels higher
Code edit (1 edits merged)
Please save this source code
User prompt
move enemy and player 150 pixels higher
/**** * 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 GaugeBar = Container.expand(function () { var self = Container.call(this); var gaugeBackground = self.attachAsset('gauge_background', { anchorX: 0.5, anchorY: 0.5 }); var gaugeFill = self.attachAsset('gauge_fill', { anchorX: 0.5, anchorY: 0.5 }); self.maxWidth = gaugeFill.width; self.currentValue = 0; self.updateGauge = function (value) { self.currentValue = value; gaugeFill.width = self.maxWidth * (self.currentValue / 100); }; }); 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 - 30) { self.y = self.groundY - 30; 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 - 30; // Use groundY for initial position and move 30 pixels higher var enemies = []; var enemySpawnInterval = 80; var enemySpawnCounter = 0; var gaugeBar = game.addChild(new GaugeBar()); gaugeBar.x = 2048 / 2; gaugeBar.y = 100; 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) { var startTime = Date.now(); var interval = setInterval(function () { var elapsed = Date.now() - startTime; var newValue = Math.min(100, elapsed / 10); // Increase gauge value over time gaugeBar.updateGauge(newValue); }, 100); game.up = function () { clearInterval(interval); var jumpHeight = gaugeBar.currentValue / 2; // Scale the gauge value to jump height player.jumpHeight = jumpHeight; player.jump(); gaugeBar.updateGauge(0); // Reset gauge after jump }; var jumpHeight = gaugeBar.currentValue / 2; // Scale the gauge value to jump height player.jumpHeight = jumpHeight; gaugeBar.updateGauge(0); // Reset gauge after jump };
===================================================================
--- original.js
+++ change.js
@@ -2,94 +2,110 @@
* Classes
****/
var Background = Container.expand(function () {
var self = Container.call(this);
- var bgAsset = self.attachAsset('background', {
+ 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 -= 2; // Move background to the left
+ self.x -= self.speed;
if (self.x <= -2048) {
- self.x = 2048; // Reset position to create a looping effect
+ self.x = 2048;
}
};
- return self;
});
-/****
-* Add Jump Gauge
-****/
-var JumpGauge = Container.expand(function () {
+var Background2 = Container.expand(function () {
var self = Container.call(this);
- // Create gauge background
- var gaugeBackground = new Graphics();
- gaugeBackground.beginFill(0x333333, 0.7);
- gaugeBackground.drawRect(0, 0, 300, 30);
- gaugeBackground.endFill();
- self.addChild(gaugeBackground);
- // Create gauge fill
- var gaugeFill = new Graphics();
- gaugeFill.beginFill(0x00FF00);
- gaugeFill.drawRect(0, 0, 0, 30);
- gaugeFill.endFill();
- self.addChild(gaugeFill);
- // Gauge properties
- self.maxWidth = 300;
- self.isCharging = false;
- self.chargeAmount = 0;
- self.chargeSpeed = 5;
- self.chargeDirection = 1; // 1 for increasing, -1 for decreasing
- // Update gauge display
- self.updateGauge = function () {
- gaugeFill.clear();
- gaugeFill.beginFill(self.getColorForCharge());
- gaugeFill.drawRect(0, 0, self.chargeAmount, 30);
- gaugeFill.endFill();
+ 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;
+ }
};
- // Get color based on charge amount (green to yellow to red)
- self.getColorForCharge = function () {
- var ratio = self.chargeAmount / self.maxWidth;
- if (ratio < 0.5) {
- // Green to yellow
- return Graphics.rgb(Math.floor(255 * (ratio * 2)), 255, 0);
- } else {
- // Yellow to red
- return Graphics.rgb(255, Math.floor(255 * (2 - ratio * 2)), 0);
+});
+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;
};
- // Start charging
- self.startCharging = function () {
- self.isCharging = true;
- self.chargeAmount = 0;
- self.chargeDirection = 1;
- };
- // Stop charging and get jump power
- self.stopCharging = function () {
- self.isCharging = false;
- // Convert charge amount to jump height (10 to 40)
- var jumpPower = 10 + self.chargeAmount / self.maxWidth * 30;
- return jumpPower;
- };
- // Update function
self.update = function () {
- if (self.isCharging) {
- // Update charge amount
- self.chargeAmount += self.chargeSpeed * self.chargeDirection;
- // Reverse direction if we hit the limits
- if (self.chargeAmount >= self.maxWidth) {
- self.chargeAmount = self.maxWidth;
- self.chargeDirection = -1;
- } else if (self.chargeAmount <= 0) {
- self.chargeAmount = 0;
- self.chargeDirection = 1;
+ 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;
}
- // Update gauge display
- self.updateGauge();
+ } 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();
+ }
};
- return self;
});
-// Modify Player class to use variable jump height
+var GaugeBar = Container.expand(function () {
+ var self = Container.call(this);
+ var gaugeBackground = self.attachAsset('gauge_background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var gaugeFill = self.attachAsset('gauge_fill', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.maxWidth = gaugeFill.width;
+ self.currentValue = 0;
+ self.updateGauge = function (value) {
+ self.currentValue = value;
+ gaugeFill.width = self.maxWidth * (self.currentValue / 100);
+ };
+});
var Player = Container.expand(function () {
var self = Container.call(this);
var currentSprite = self.attachAsset('player_run1', {
anchorX: 0.5,
@@ -106,9 +122,9 @@
scaleY: 1.5
});
self.currentAsset = 'player_run1';
self.speed = 5;
- self.jumpHeight = 25; // Default jump height
+ 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
@@ -149,24 +165,24 @@
self.runFrameCounter = 0;
}
}
};
- self.jump = function (power) {
+ self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
- // Use the provided power or default jump height
- var jumpPower = power || self.jumpHeight;
- self.velocityY = -jumpPower;
+ self.velocityY = -self.jumpHeight;
self.swapSprite('player_jump');
self.runFrameCounter = 0;
}
};
- return self;
});
/****
* Initialize Game
****/
+/****
+*-Seperator-
+****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
@@ -181,29 +197,25 @@
background2.y = 0;
var player = game.addChild(new Player());
player.x = 2048 / 4;
player.y = player.groundY - 30; // Use groundY for initial position and move 30 pixels higher
-// Add jump gauge
-var jumpGauge = game.addChild(new JumpGauge());
-jumpGauge.x = 50;
-jumpGauge.y = 50;
-jumpGauge.visible = false;
var enemies = [];
var enemySpawnInterval = 80;
var enemySpawnCounter = 0;
+var gaugeBar = game.addChild(new GaugeBar());
+gaugeBar.x = 2048 / 2;
+gaugeBar.y = 100;
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
LK.gui.top.addChild(scoreText);
scoreText.x = 2048 / 2;
scoreText.y = 50;
-var isPressingDown = false;
game.update = function () {
background.update();
background2.update();
player.update();
- jumpGauge.update();
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = 2048 + Math.random() * 200;
@@ -228,16 +240,21 @@
}
}
};
game.down = function (x, y, obj) {
- isPressingDown = true;
- jumpGauge.visible = true;
- jumpGauge.startCharging();
-};
-game.up = function (x, y, obj) {
- if (isPressingDown) {
- isPressingDown = false;
- var jumpPower = jumpGauge.stopCharging();
- player.jump(jumpPower);
- jumpGauge.visible = false;
- }
+ var startTime = Date.now();
+ var interval = setInterval(function () {
+ var elapsed = Date.now() - startTime;
+ var newValue = Math.min(100, elapsed / 10); // Increase gauge value over time
+ gaugeBar.updateGauge(newValue);
+ }, 100);
+ game.up = function () {
+ clearInterval(interval);
+ var jumpHeight = gaugeBar.currentValue / 2; // Scale the gauge value to jump height
+ player.jumpHeight = jumpHeight;
+ player.jump();
+ gaugeBar.updateGauge(0); // Reset gauge after jump
+ };
+ var jumpHeight = gaugeBar.currentValue / 2; // Scale the gauge value to jump height
+ player.jumpHeight = jumpHeight;
+ gaugeBar.updateGauge(0); // Reset gauge after jump
};
\ No newline at end of file