User prompt
fix bugs
User prompt
اصنع مفتاح الجهاز اليساري مفتاح الهيوغو
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'button')' in or related to this line: 'if (obj.event.button === 0) {' Line Number: 137
User prompt
fix bugs
User prompt
Adjust Hero's Jump Height
User prompt
Make hero jump when the left mouse button is pressed
User prompt
have hero move towards the mouse cursor, but only limit to left and right movement, not up and down
User prompt
have hero follow the mouse cursor in a relative mode
User prompt
Move the hero and the obstacles to the bottom of the screen.
User prompt
Have the hero follow the mouse cursor.
User prompt
Use WASD and Spacebar for movement.
User prompt
use spacebar for jump and not the mouse click
User prompt
Allow the hero to jump as well.
User prompt
Allow Hero to run left and right.
User prompt
Allow the hero to have double jump.
User prompt
Create a parallaxing background.
User prompt
Make the hero jump higher
Initial prompt
Mark's Mayhem
/**** * Classes ****/ // Background class var Background = Container.expand(function () { var self = Container.call(this); var backgroundGraphics = self.attachAsset('background', { anchorX: 0.0, anchorY: 0.0 }); self.speed = -2; self.update = function () { self.x += self.speed; if (self.x <= -2048) { self.x = 2048; } }; return self; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.jumpSpeed = -20; self.gravity = 1; self.isJumping = false; self.isFalling = false; self.doubleJump = false; self.isMovingLeft = false; self.isMovingRight = false; self.update = function () { if (self.isJumping) { self.y += self.jumpSpeed; self.jumpSpeed += self.gravity; if (self.jumpSpeed >= 0) { self.isJumping = false; self.isFalling = true; } } else if (self.isFalling) { self.y += self.jumpSpeed; self.jumpSpeed += self.gravity; if (self.y >= 200) { // Ground level self.y = 200; self.isFalling = false; self.jumpSpeed = -20; self.doubleJump = false; } } // Add left and right movement if (self.isMovingLeft) { self.x -= self.speed; if (self.x <= 0) { self.x = 0; } } if (self.isMovingRight) { self.x += self.speed; if (self.x >= 2048) { self.x = 2048; } } }; self.jump = function () { if (!self.isJumping && !self.isFalling) { self.isJumping = true; } else if (!self.doubleJump) { self.isJumping = true; self.doubleJump = true; self.jumpSpeed = -20; } }; return self; }); // Hurdle class var Hurdle = Container.expand(function () { var self = Container.call(this); var hurdleGraphics = self.attachAsset('hurdle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.x += self.speed; if (self.x < -50) { self.destroy(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game(); /**** * Game Code ****/ var background1 = game.addChild(new Background()); background1.x = 0; background1.y = 0; var background2 = game.addChild(new Background()); background2.x = 2048; background2.y = 0; var hero = game.addChild(new Hero()); hero.x = 200; hero.y = 2732 - 200; // Ground level var hurdles = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function spawnHurdle() { var hurdle = new Hurdle(); hurdle.x = 2048; hurdle.y = 2732 - hurdle.height; hurdles.push(hurdle); game.addChild(hurdle); } game.down = function (x, y, obj) { if (obj && obj.event && obj.event.button === 0) { // Left mouse button hero.isMovingLeft = true; } }; game.up = function (x, y, obj) { if (obj && obj.event && obj.event.button === 0) { // Left mouse button hero.isMovingLeft = false; } hero.isMovingRight = false; }; game.update = function () { hero.update(); for (var i = hurdles.length - 1; i >= 0; i--) { hurdles[i].update(); if (hero.intersects(hurdles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } if (LK.ticks % 120 == 0) { game.move = function (x, y, obj) { var game_position = game.toLocal(obj.global); hero.x = game_position.x; }; spawnHurdle(); } score += 1; scoreTxt.setText(score); }; background1.update(); background2.update();
===================================================================
--- original.js
+++ change.js
@@ -126,15 +126,15 @@
hurdles.push(hurdle);
game.addChild(hurdle);
}
game.down = function (x, y, obj) {
- if (obj.event && obj.event.button === 0) {
+ if (obj && obj.event && obj.event.button === 0) {
// Left mouse button
hero.isMovingLeft = true;
}
};
game.up = function (x, y, obj) {
- if (obj.event && obj.event.button === 0) {
+ if (obj && obj.event && obj.event.button === 0) {
// Left mouse button
hero.isMovingLeft = false;
}
hero.isMovingRight = false;