Skip to content

Commit

Permalink
Merge branch 'master' of github.com:robashton/MolyHole
Browse files Browse the repository at this point in the history
  • Loading branch information
U-JoTory-net\Jo Tory authored and U-JoTory-net\Jo Tory committed Apr 1, 2012
2 parents c627e36 + e9b70e7 commit 3f22254
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion site/assets.json

Large diffs are not rendered by default.

83 changes: 80 additions & 3 deletions site/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,53 @@
};
_.extend(SaddenedSpiderAnimation.prototype, Effect.prototype);

var AngrySpiderAnimation = function(spider) {
Effect.call(this);
this.spider = spider;
this.tick = 0;
this.frame = 1;
};
AngrySpiderAnimation.prototype = {
update: function() {
this.selectFrame();
if(this.frame <= 3) {
this.showFrame(this.frame);
} else if(this.frame <= 13) {
this.beAngry(this.frame);
} else if(this.frame < 16) {
this.cheerUp(this.frame);
} else {
this.end();
}
},
selectFrame: function() {
if(this.tick++ % 5 === 0) {
this.frame++;
}
},
showFrame: function(frame) {
this.spider.colour = GlobalResources.getTexture('assets/spiderangry/angry-' + frame + '.png');
},
beAngry: function(frame) {
var odd = frame % 2;
if(odd === 0) {
this.showFrame(2);
}
else {
this.showFrame(3);
}
},
cheerUp: function(frame) {
var cheeringTime = (16 - frame);
this.showFrame(cheeringTime);
},
end: function() {
this.spider.resetAnimations()
this.raise('Finished');
}
};
_.extend(AngrySpiderAnimation.prototype, Effect.prototype);

var CelebratingSpiderAnimation = function(spider) {
Effect.call(this);
this.spider = spider;
Expand All @@ -343,7 +390,7 @@
this.end();
},
selectFrame: function() {
if(this.tick++ % 5 == 0)
if(this.tick++ % 5 === 0)
this.frame++;
},
showFrame: function(frame) {
Expand Down Expand Up @@ -940,9 +987,11 @@
Quad.call(this, 80, 80);
this.x = 700;
this.y = 625;
this.destx = 0;
this.destx = 40;
this.speedx = 1.0;
this.id = "spider";
this.panicking = false;
this.animating = false;
this.panickedAnimation = new PanickedSpiderAnimation(this);
this.walkingAnimation = new WalkingSpiderAnimation(this);
this.addEffect(this.walkingAnimation);
Expand Down Expand Up @@ -977,16 +1026,34 @@
this.currentStrategy();
},
happyStrategy: function() {

this.walkTowardsTarget();
this.determineIfWaterIsHigh();
this.determineIfIntersectsWithWaterfall();
},
walkTowardsTarget: function() {
if(this.animating) return;

var difference = this.destx - (this.x + this.width / 2.0);
if(Math.abs(difference) < 10)
return this.chooseNewDirection();
if(difference < 0)
this.x -= this.speedx;
else
this.x += this.speedx;
},
chooseNewDirection: function() {
this.destx = (Math.random() * 700) + 50;
},
panickedStrategy: function() {
// Do bugger all
},
playNonDefaultAnimation: function(animation) {
if(this.animating) return;
this.stopDefaultAnimation();
this.animating = true;
animation.on('Finished', function() {
this.startDefaultAnimation();
this.animating = false;
}, this);
this.addEffect(animation);
},
Expand All @@ -996,6 +1063,16 @@
stopDefaultAnimation: function() {
this.walkingAnimation.disable();
},
determineIfIntersectsWithWaterfall: function() {
var self = this;
this.scene.withEntity("waterfall", function(waterfall) {
if(waterfall.intersects(self))
self.jumpAwayFromWaterfall();
});
},
jumpAwayFromWaterfall: function() {
this.playNonDefaultAnimation(new AngrySpiderAnimation(this));
},
determineIfWaterIsHigh: function() {
var self = this;
this.scene.withEntity("floorwater", function(water) {
Expand Down

0 comments on commit 3f22254

Please sign in to comment.