User prompt
make sure when hero is running, it is cycling between run1 and run2
User prompt
display hero run1 and run2 images when hero is running
User prompt
I don't see run1 and run2 animations
User prompt
fix bugs
User prompt
make sure run1 and run2 animation are used
User prompt
make hero to have animation
User prompt
make background parallax scroll slower than the foreground
User prompt
make the foreground parallex scroll slower
User prompt
make the double jump higher
User prompt
Create a Foreground Parallax.
User prompt
Every 10 hurdle, replace the hurdle with a boss.
User prompt
Delete the boss.
User prompt
fix bugs
User prompt
have hero move a little slower
User prompt
have hurdles on the ground
User prompt
after ten obstacles, have a big boss show up
User prompt
have hero jump higher
User prompt
after hero jump, have the hero fall back to the ground, and not in the sky
User prompt
fix bugs
User prompt
make hero jump when mouse is clicked
User prompt
lower the hero to the ground
User prompt
Make hero jump when spacebar is pressed
User prompt
Make SpacebarJump or LeftMouseButtonJump
User prompt
fix bugs
User prompt
Make hero jump when left mouse button is pressed
/**** * 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 = -1; self.update = function () { self.x += self.speed; if (self.x <= -2048) { self.x = 2048; } }; return self; }); // Boss class var Boss = Container.expand(function () { var self = Container.call(this); var bossGraphics = self.attachAsset('boss', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.x += self.speed; if (self.x < -50) { self.destroy(); } }; return self; }); // Foreground class var Foreground = Container.expand(function () { var self = Container.call(this); var foregroundGraphics = self.attachAsset('foreground', { 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); self.heroIdle = self.attachAsset('hero_idle', { anchorX: 0.5, anchorY: 0.5 }); self.heroRun1 = self.attachAsset('hero_run1', { anchorX: 0.5, anchorY: 0.5 }); self.heroRun2 = self.attachAsset('hero_run2', { anchorX: 0.5, anchorY: 0.5 }); self.heroJump = self.attachAsset('hero_jump', { anchorX: 0.5, anchorY: 0.5 }); self.heroIdle.visible = true; self.heroRun1.visible = false; self.heroRun2.visible = false; self.heroJump.visible = false; self.speed = 3; self.jumpSpeed = -30; 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; } self.heroIdle.visible = false; self.heroRun1.visible = false; self.heroRun2.visible = false; self.heroJump.visible = true; } else if (self.isFalling) { self.y += self.jumpSpeed; self.jumpSpeed += self.gravity; if (self.y >= 2732 - self.height / 2) { self.y = 2732 - self.height / 2; self.isFalling = false; self.jumpSpeed = -30; self.doubleJump = false; } self.heroIdle.visible = false; self.heroRun1.visible = false; self.heroRun2.visible = false; self.heroJump.visible = true; } else { self.heroJump.visible = false; self.heroIdle.visible = false; if (self.isMovingRight) { if (LK.ticks % 30 == 0) { if (self.heroRun1.visible) { self.heroRun1.visible = false; self.heroRun2.visible = true; } else { self.heroRun1.visible = true; self.heroRun2.visible = false; } } } else { self.heroRun1.visible = false; self.heroRun2.visible = false; self.heroIdle.visible = true; } } // 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 ****/ function spawnHurdle() { if (hurdles.length % 10 == 0 && !bossSpawned) { var boss = new Boss(); boss.x = 2048; boss.y = 2732 - boss.height / 2; // Ground level game.addChild(boss); bossSpawned = true; } else { var hurdle = new Hurdle(); hurdle.x = 2048; hurdle.y = 2732 - hurdle.height / 2; // Ground level hurdles.push(hurdle); game.addChild(hurdle); } } 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 foreground1 = game.addChild(new Foreground()); foreground1.x = 0; foreground1.y = 0; var foreground2 = game.addChild(new Foreground()); foreground2.x = 2048; foreground2.y = 0; var hero = game.addChild(new Hero()); hero.x = 200; hero.y = 2732 - hero.height / 2; // Ground level var hurdles = []; var bossSpawned = false; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); game.down = function (x, y, obj) { if (obj) { hero.jump(); } }; game.up = function (x, y, obj) { if (obj) { 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) { spawnHurdle(); } score += 1; scoreTxt.setText(score); }; background1.update(); background2.update(); foreground1.update(); foreground2.update(); game.move = function (x, y, obj) { var game_position = game.toLocal(obj.global); hero.x = game_position.x; };
===================================================================
--- original.js
+++ change.js
@@ -108,16 +108,22 @@
self.heroJump.visible = true;
} else {
self.heroJump.visible = false;
self.heroIdle.visible = false;
- if (LK.ticks % 30 == 0) {
- if (self.heroRun1.visible) {
- self.heroRun1.visible = false;
- self.heroRun2.visible = true;
- } else {
- self.heroRun1.visible = true;
- self.heroRun2.visible = false;
+ if (self.isMovingRight) {
+ if (LK.ticks % 30 == 0) {
+ if (self.heroRun1.visible) {
+ self.heroRun1.visible = false;
+ self.heroRun2.visible = true;
+ } else {
+ self.heroRun1.visible = true;
+ self.heroRun2.visible = false;
+ }
}
+ } else {
+ self.heroRun1.visible = false;
+ self.heroRun2.visible = false;
+ self.heroIdle.visible = true;
}
}
// Add left and right movement
if (self.isMovingLeft) {