Skip to content

Commit

Permalink
Fixed issue with player being able to shoot before moving mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
liamness committed Sep 10, 2015
1 parent c2124d0 commit 2006515
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"browser-sync": "^2.7.5",
"del": "^2.0.0",
"gulp": "^3.8.11",
"gulp-filter": "^3.0.1",
"gulp-jshint": "^1.11.2",
"gulp-sass": "^2.0.1",
"gulp-sourcemaps": "^1.5.2",
Expand Down
2 changes: 1 addition & 1 deletion public
Submodule public updated 1 files
+1 −1 app.js
10 changes: 6 additions & 4 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ export default (function() {
// code for firing
function playerShoot() {
/* jshint validthis:true */

var self = this;

var shot = new Shot('player');
var shot;

var mousemoveListener = function(e) {
if(!shot) { shot = new Shot('player'); }

if(!crosshair.visible) { crosshair.setVisible(true); }

var newX = checkInBounds(Math.floor(e.offsetX / constants.gridSpacing)),
Expand All @@ -148,7 +150,7 @@ export default (function() {

var clickListener = function() {
// check we haven't already taken this shot
if(shot.checkNotIntersecting(playerShots)) {
if(shot && shot.checkNotIntersecting(playerShots)) {
playerShots.push(shot);
shot.setVisible(true);
crosshair.setVisible(false);
Expand Down Expand Up @@ -232,7 +234,7 @@ export default (function() {
opponentShots.concat(playerShots).forEach(function(shot) {
shot.destroy();
});

/* falls through */
case 'start':
/* falls through */
Expand Down
2 changes: 1 addition & 1 deletion src/shot.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default (function() {

function checkNotIntersecting(otherShot) {
/* jshint validthis:true */

return (this.pos[0] !== otherShot.pos[0] || this.pos[1] !== otherShot.pos[1]);
}

Expand Down

0 comments on commit 2006515

Please sign in to comment.