You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
radium/gemswap/gemswap.js

86 lines
2.8 KiB
JavaScript

// Generated by CoffeeScript 1.7.1
(function() {
$(function() {
var engine, manager;
manager = new ResourceManager("gemswap/assets");
engine = new Engine(manager);
/*
* Configure pre-loading assets
manager.addImages([
"images/loading_screen.png"
], true)
*/
manager.addImages(["images/diamond.png", "images/diamond_inverted.png", "images/diamond_shimmer.png"]);
/*
manager.addSounds([
"sfx/match.wav"
"sfx/swap.wav"
])
*/
manager.prepare();
return manager.preload(null, function() {
var diamond, scene;
engine.addCanvas($("#gamecanvas"));
scene = engine.createScene("main");
engine.createSprite("diamond", "images/diamond.png");
engine.createSprite("diamond_inverted", "images/diamond_inverted.png");
engine.createSprite("diamond_shimmer", "images/diamond_shimmer.png");
diamond = engine.createObject("diamond");
diamond.sprite = engine.getSprite("diamond");
diamond.onCreate = function() {
this.fade_step = 0.045;
this.fade_current_step = this.fade_step;
this.fade_value = 0;
this.fade_decay_current = 9999;
this.fade_decay_max = 8;
this.shimmer_step = 0.006;
this.shimmer_current_step = this.shimmer_step;
return this.shimmer_value = 0;
};
diamond.onStep = function() {
var max;
if (this.fade_decay_current < Math.pow(2, this.fade_decay_max)) {
this.fade_value += this.fade_current_step;
max = 1.5 / this.fade_decay_current;
if (this.fade_value > Math.min(max, 1)) {
this.fade_value = Math.min(max, 1);
this.fade_current_step = -this.fade_step;
}
if (this.fade_value <= 0) {
this.fade_value = 0;
this.fade_decay_current *= 1.5;
this.fade_current_step = this.fade_step;
}
}
this.shimmer_value += this.shimmer_current_step;
if (this.shimmer_value > 0.7) {
this.shimmer_value = 0.7;
this.shimmer_current_step = -this.shimmer_step;
}
if (this.shimmer_value < 0) {
this.shimmer_value = 0;
this.shimmer_current_step = this.shimmer_step;
}
return true;
};
diamond.onDraw = function() {
this.engine.getSprite("diamond_inverted").draw(this.x, this.y, {
alpha: this.fade_value
});
return this.engine.getSprite("diamond_shimmer").draw(this.x - 14, this.y - 14, {
alpha: this.shimmer_value
});
};
diamond.onMouseOver = function() {
console.log("mouseover");
return this.fade_decay_current = 1;
};
scene.createInstance(diamond, 20, 20);
return engine.start();
});
});
}).call(this);