Skip to content

Commit

Permalink
fixed landing animation
Browse files Browse the repository at this point in the history
  • Loading branch information
benchmark committed Jun 26, 2011
1 parent a69aca0 commit 16fd1a8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions shared/ship.js
Expand Up @@ -23,13 +23,17 @@
if (initial_state) this.update(initial_state);

this.heldKeys = {};
this._.animation = {
this.animation = {
trails: {
big: 0
},
landing: 0,
crashing: []
}

this._.animation = {
crashing: []
}

this.render = function(ctx, timeDiff) {
ctx.save()
Expand All @@ -41,18 +45,18 @@
ctx.translate(-(this._.x + 25), -(this._.y + 25));

if (this._.landed) {
this._.animation.landing += timeDiff;
ctx.save()
var imageIndex = Math.floor(this._.animation.landing / 500);
this.animation.landing += timeDiff;
ctx.save();
var imageIndex = Math.floor(this.animation.landing / 500);
if (imageIndex >= 4) imageIndex = 4;
ctx.drawImage(imageCache.ship.default.landing[imageIndex % 5], this._.x, this._.y);
ctx.restore()
} else if (this._.crashed) {
this._.animation.landing += timeDiff;
this.animation.landing += timeDiff;
ctx.save()
var imageIndex = Math.floor(this._.animation.landing / 1000);
var imageIndex = Math.floor(this.animation.landing / 1000);
if (imageIndex >= 2) imageIndex = 2;
ctx.drawImage(imageCache.ship.default.crunching[imageIndex % 2], this._.x, this._.y);
ctx.drawImage(imageCache.ship.default.crunching[imageIndex % 1], this._.x, this._.y);
ctx.restore()

for (var i = 0; i < 13; i ++) {
Expand All @@ -64,24 +68,24 @@
}

if (this.heldKeys['38']) {
this._.animation.trails.big += timeDiff;
this.animation.trails.big += timeDiff;

ctx.save();
ctx.translate(this._.x + 22, this._.y + 50);
var imageIndex = (this._.animation.trails.big % 50) % 4;
var imageIndex = (this.animation.trails.big % 50) % 4;
if (this.trails.large[imageIndex]) {
ctx.scale(2.0);
ctx.drawImage(this.trails.large[imageIndex], -7, 2);
}
ctx.restore();
} else {
this._.animation.trails.big = 0;
this.animation.trails.big = 0;
}

if (this.heldKeys['37']) {
ctx.save();
ctx.translate(this._.x + 34, this._.y + 35);
var imageIndex = (this._.animation.trails.big % 50) % 4;
var imageIndex = (this.animation.trails.big % 50) % 4;
if (this.trails.small[imageIndex]) {
ctx.scale(2.0);
ctx.drawImage(this.trails.small[imageIndex], -6, 2);
Expand All @@ -92,7 +96,7 @@
if (this.heldKeys['39']) {
ctx.save();
ctx.translate(this._.x + 10, this._.y + 35);
var imageIndex = (this._.animation.trails.big % 50) % 4;
var imageIndex = (this.animation.trails.big % 50) % 4;
if (this.trails.small[imageIndex]) {
ctx.scale(2.0);
ctx.drawImage(this.trails.small[imageIndex], -5, 2);
Expand Down

0 comments on commit 16fd1a8

Please sign in to comment.