diff --git a/js/main.js b/js/main.js index 4ac6dee..f48d5f5 100644 --- a/js/main.js +++ b/js/main.js @@ -142,9 +142,12 @@ function startGame (images) { mainCanvas.width = mainCanvas.width; + var mouseCanvasPosition = dContext.canvasPositionToMapPosition([mouseX, mouseY]); + if (!skier.isJumping) { - var mouseCanvasPosition = dContext.canvasPositionToMapPosition([mouseX, mouseY]); skier.setMapPositionTarget(mouseCanvasPosition[0], mouseCanvasPosition[1]); + } else { + skier.setMapPositionTarget(undefined, mouseCanvasPosition[1]); } skier.draw(dContext); @@ -203,7 +206,7 @@ function startGame (images) { 'High Score: ' + highScore, 'Created by Dan Hough (@basicallydan)', 'Current Speed: ' + skier.getSpeed(), - 'Skier Position: ' + skier.mapPosition[0] + ', ' + skier.mapPosition[1] + 'Skier Position: ' + skier.mapPosition[0].toFixed(1) + ', ' + skier.mapPosition[1].toFixed(1) ]); infoBox.draw(dContext); @@ -229,22 +232,22 @@ function startGame (images) { skier.speedBoost(); } //W Key - if (e.Keycode === 87 || e.keyCode === 119) { + if (e.Keycode === 87 || e.keyCode === 119 || e.keyCode === 38) { mouseX = 0; mouseY = 0; } // A Key - if (e.keyCode === 65 || e.keyCode === 97) { + if (e.keyCode === 65 || e.keyCode === 97 || e.keyCode === 37) { mouseX = 0; mouseY = mainCanvas.height; } // S Key - if (e.keyCode === 83 || e.keyCode === 115) { + if (e.keyCode === 83 || e.keyCode === 115 || e.keyCode === 40) { mouseX = mainCanvas.width / 2; mouseY = mainCanvas.height; } // D Key - if (e.keyCode === 68 || e.keyCode === 100) { + if (e.keyCode === 68 || e.keyCode === 100 || e.keyCode === 39) { mouseX = mainCanvas.width; mouseY = mainCanvas.height; } diff --git a/js/skier.js b/js/skier.js index e8043fb..6f3344f 100644 --- a/js/skier.js +++ b/js/skier.js @@ -6,6 +6,8 @@ var Sprite = require('./Sprite'); var sup = { draw: that.superior('draw'), cycle: that.superior('cycle'), + getSpeedX: that.superior('getSpeedX'), + getSpeedY: that.superior('getSpeedY'), hits: that.superior('hits') }; var directions = { @@ -152,6 +154,30 @@ var Sprite = require('./Sprite'); } }; + that.getSpeedX = function () { + if (getDirection() === 'esEast' || getDirection() === 'wsWest') { + return that.getSpeed() * 0.5; + } + + if (getDirection() === 'sEast' || getDirection() === 'sWest') { + return that.getSpeed() * 0.33; + } + + return 0; + }; + + that.getSpeedY = function () { + if (getDirection() === 'esEast' || getDirection() === 'wsWest') { + return that.getSpeed() * 0.6; + } + + if (getDirection() === 'sEast' || getDirection() === 'sWest') { + return that.getSpeed() * 0.85; + } + + return that.getSpeed(); + }; + that.hasHitObstacle = function (obs) { that.isMoving = false; that.hasBeenHit = true; diff --git a/js/sprite.js b/js/sprite.js index ed4fe02..3ab58df 100644 --- a/js/sprite.js +++ b/js/sprite.js @@ -13,8 +13,6 @@ that.canvasZ = 0; that.height = 0; that.speed = 0; - that.speedX = that.speed; - that.speedY = that.speed; that.data = data || { parts : {} }; that.movingToward = [ 0, 0 ]; that.metresDownTheMountain = 0; @@ -63,17 +61,17 @@ if (typeof that.movingToward[0] !== 'undefined') { if (currentX > that.movingToward[0]) { - currentX -= Math.min(that.speedX, Math.abs(currentX - that.movingToward[0])); + currentX -= Math.min(that.getSpeedX(), Math.abs(currentX - that.movingToward[0])); } else if (currentX < that.movingToward[0]) { - currentX += Math.min(that.speedX, Math.abs(currentX - that.movingToward[0])); + currentX += Math.min(that.getSpeedX(), Math.abs(currentX - that.movingToward[0])); } } if (typeof that.movingToward[1] !== 'undefined') { if (currentY > that.movingToward[1]) { - currentY -= Math.min(that.speedY, Math.abs(currentY - that.movingToward[1])); + currentY -= Math.min(that.getSpeedY(), Math.abs(currentY - that.movingToward[1])); } else if (currentY < that.movingToward[1]) { - currentY += Math.min(that.speedY, Math.abs(currentY - that.movingToward[1])); + currentY += Math.min(that.getSpeedY(), Math.abs(currentY - that.movingToward[1])); } } @@ -190,6 +188,14 @@ return that.speed; }; + that.getSpeedX = function () { + return that.speed; + }; + + that.getSpeedY = function () { + return that.speed; + }; + this.setHeight = function setHeight (h) { that.height = h; };