Skip to content

Commit

Permalink
Add push animations to the box that is push
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkocev committed Jan 21, 2017
1 parent 6abfa51 commit 7b6dcc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
p1.moveLeft();
}
if(p1.canPushLeft(scene)){
p1.pushLeft();
p1.pushLeft(scene);
}
}
if(keyCode == RIGHT_KEY) {
if(p1.canMoveRight(scene)) {
p1.moveRight();
}
if(p1.canPushRight(scene)) {
p1.pushRight();
p1.pushRight(scene);
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions player.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,17 @@ function Player(x,y) {
return hasBoxRight && noBoxByTheBoxOnTheRight && noBoxOnTop && floor;
}

this.pushLeft = function() {
this.pushLeft = function(scene) {
if(!(!(self.interval))) return;

var speed = 1/8;

var box = scene.getItemAt(x-1, Math.round(y));

this.textures.setPushLeft();
self.interval = setInterval(function() {
x -= speed;
box.setX(box.getX() - speed);
if(Math.floor(x) == x) {
clearInterval(self.interval);
self.interval = null;
Expand All @@ -147,13 +151,15 @@ function Player(x,y) {
}, 100);
}

this.pushRight = function() {
this.pushRight = function(scene) {
if(!(!(self.interval))) return;

var speed = 1/8;
var box = scene.getItemAt(x+1, Math.round(y));
this.textures.setPushRight();
self.interval = setInterval(function() {
x += speed;
box.setX(box.getX() + speed);
if(Math.floor(x) == x) {
clearInterval(self.interval);
self.interval = null;
Expand Down

0 comments on commit 7b6dcc0

Please sign in to comment.