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.
1776 lines
56 KiB
JavaScript
1776 lines
56 KiB
JavaScript
// Generated by CoffeeScript 1.7.1
|
|
(function() {
|
|
var Ease, Engine, Object, ResourceManager, Scene, Sound, Sprite, Tileset, TilesetTile, Timer, util,
|
|
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__slice = [].slice;
|
|
|
|
window.pass = void 0;
|
|
|
|
Engine = (function() {
|
|
function Engine(resource_manager) {
|
|
this.resource_manager = resource_manager;
|
|
this.getTileset = __bind(this.getTileset, this);
|
|
this.getSprite = __bind(this.getSprite, this);
|
|
this.getSound = __bind(this.getSound, this);
|
|
this.getObject = __bind(this.getObject, this);
|
|
this.getScene = __bind(this.getScene, this);
|
|
this.createTileset = __bind(this.createTileset, this);
|
|
this.createSprite = __bind(this.createSprite, this);
|
|
this.createSound = __bind(this.createSound, this);
|
|
this.createObject = __bind(this.createObject, this);
|
|
this.createScene = __bind(this.createScene, this);
|
|
this.setPreloadScene = __bind(this.setPreloadScene, this);
|
|
this.setInitialScene = __bind(this.setInitialScene, this);
|
|
this.skipTimers = __bind(this.skipTimers, this);
|
|
this.updateTimers = __bind(this.updateTimers, this);
|
|
this.iteration = __bind(this.iteration, this);
|
|
this.loop = __bind(this.loop, this);
|
|
this.start = __bind(this.start, this);
|
|
this.updateCanvasSize = __bind(this.updateCanvasSize, this);
|
|
this.getSurface = __bind(this.getSurface, this);
|
|
this.createSurface = __bind(this.createSurface, this);
|
|
this.addCanvas = __bind(this.addCanvas, this);
|
|
this.canvases = {};
|
|
this.fps = 45;
|
|
this.last_frameskip_collection = Math.floor(Date.now());
|
|
this.frameskip = 0;
|
|
this.current_frameskip = 0;
|
|
this.current_frame = 0;
|
|
this.scenes = {};
|
|
this.objects = {};
|
|
this.sounds = {};
|
|
this.sprites = {};
|
|
this.tilesets = {};
|
|
this.named_timers = {};
|
|
this.unnamed_timers = [];
|
|
this.ease.engine = this;
|
|
}
|
|
|
|
Engine.prototype.addCanvas = function(canvas, label) {
|
|
if (label == null) {
|
|
label = "";
|
|
}
|
|
return this.canvases[label] = util.unpackElement(canvas);
|
|
};
|
|
|
|
Engine.prototype.createSurface = function(label) {
|
|
return this.canvases[label] = document.createElement("canvas");
|
|
};
|
|
|
|
Engine.prototype.getSurface = function(label) {
|
|
var _ref;
|
|
if (typeof label === "string") {
|
|
return (_ref = this.canvases[label]) != null ? _ref.getContext("2d") : void 0;
|
|
} else if (label.tagName === "CANVAS") {
|
|
return label.getContext("2d");
|
|
} else {
|
|
return label;
|
|
}
|
|
};
|
|
|
|
Engine.prototype.updateCanvasSize = function(canvas, w, h) {
|
|
canvas.width = w;
|
|
canvas.height = h;
|
|
canvas.style.width = "" + w + "px";
|
|
return canvas.style.height = "" + h + "px";
|
|
};
|
|
|
|
Engine.prototype.start = function() {
|
|
this.initial_scene.addTargetSurface(this.canvases[""]);
|
|
return this.loop();
|
|
};
|
|
|
|
Engine.prototype.loop = function() {
|
|
return this.iteration();
|
|
};
|
|
|
|
Engine.prototype.iteration = function() {
|
|
var belated_timeout, current_frame, frame_interval, name, next_frame, overtime, scene, skipped_frames, _ref;
|
|
frame_interval = 1000 / this.fps;
|
|
current_frame = Date.now();
|
|
next_frame = current_frame + frame_interval;
|
|
this.current_frame += 1;
|
|
if (Math.floor(current_frame) > this.last_frameskip_collection) {
|
|
this.frameskip = this.current_frameskip;
|
|
this.current_frameskip = 0;
|
|
this.last_frameskip_collection = Math.floor(current_frame);
|
|
}
|
|
this.updateTimers();
|
|
_ref = this.scenes;
|
|
for (name in _ref) {
|
|
scene = _ref[name];
|
|
if (scene.active) {
|
|
scene.iteration();
|
|
}
|
|
}
|
|
if (Date.now() < next_frame) {
|
|
return setTimeout(this.iteration, next_frame - Date.now());
|
|
} else {
|
|
overtime = Date.now() - next_frame;
|
|
skipped_frames = Math.floor(overtime / frame_interval);
|
|
this.current_frameskip += skipped_frames;
|
|
this.current_frame += skipped_frames;
|
|
this.skipTimers(skipped_frames);
|
|
belated_timeout = overtime % frame_interval;
|
|
return setTimeout(this.iteration, belated_timeout);
|
|
}
|
|
};
|
|
|
|
Engine.prototype.updateTimers = function() {
|
|
var key, timer, timer_name, val, _i, _len, _ref, _ref1, _results;
|
|
_ref = this.unnamed_timers.concat((function() {
|
|
var _ref, _results;
|
|
_ref = this.named_timers;
|
|
_results = [];
|
|
for (key in _ref) {
|
|
val = _ref[key];
|
|
_results.push(val);
|
|
}
|
|
return _results;
|
|
}).call(this));
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
timer = _ref[_i];
|
|
timer.step();
|
|
}
|
|
this.unnamed_timers = this.unnamed_timers.filter(function(obj) {
|
|
return !obj.finished;
|
|
});
|
|
_ref1 = this.named_timers;
|
|
_results = [];
|
|
for (timer_name in _ref1) {
|
|
timer = _ref1[timer_name];
|
|
if (timer.finished) {
|
|
_results.push(delete this.named_timers[timer_name]);
|
|
} else {
|
|
_results.push(void 0);
|
|
}
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
Engine.prototype.skipTimers = function(frames) {
|
|
var key, timer, val, _i, _len, _ref, _results;
|
|
_ref = this.unnamed_timers.concat((function() {
|
|
var _ref, _results1;
|
|
_ref = this.named_timers;
|
|
_results1 = [];
|
|
for (key in _ref) {
|
|
val = _ref[key];
|
|
_results1.push(val);
|
|
}
|
|
return _results1;
|
|
}).call(this));
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
timer = _ref[_i];
|
|
_results.push(timer.skip(frames));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
Engine.prototype.setInitialScene = function(scene) {
|
|
return this.initial_scene = scene;
|
|
};
|
|
|
|
Engine.prototype.setPreloadScene = function(scene) {
|
|
return this.preload_scene = scene;
|
|
};
|
|
|
|
Engine.prototype.createScene = function(name) {
|
|
var scene;
|
|
scene = new Scene(this, name);
|
|
if (this.initial_scene == null) {
|
|
this.initial_scene = scene;
|
|
}
|
|
return this.scenes[name] = scene;
|
|
};
|
|
|
|
Engine.prototype.createObject = function(name) {
|
|
return this.objects[name] = new Object(this, name);
|
|
};
|
|
|
|
Engine.prototype.createSound = function(name, sound) {
|
|
return this.sounds[name] = new Sound(this, name, this.resource_manager.getSound(sound));
|
|
};
|
|
|
|
Engine.prototype.createSprite = function(name, image) {
|
|
console.log("gget", this.resource_manager.getImage(image));
|
|
return this.sprites[name] = new Sprite(this, name, this.resource_manager.getImage(image));
|
|
};
|
|
|
|
Engine.prototype.createTileset = function(name, image, tile_width, tile_height) {
|
|
return this.tilesets[name] = new Tileset(this, name, this.resource_manager.getImage(image), tile_width, tile_height);
|
|
};
|
|
|
|
Engine.prototype.getScene = function(name) {
|
|
if (typeof name === "string") {
|
|
return this.scenes[name];
|
|
} else {
|
|
return name;
|
|
}
|
|
};
|
|
|
|
Engine.prototype.getObject = function(name) {
|
|
if (typeof name === "string") {
|
|
return this.objects[name];
|
|
} else {
|
|
return name;
|
|
}
|
|
};
|
|
|
|
Engine.prototype.getSound = function(name) {
|
|
if (typeof name === "string") {
|
|
return this.sounds[name];
|
|
} else {
|
|
return name;
|
|
}
|
|
};
|
|
|
|
Engine.prototype.getSprite = function(name) {
|
|
if (typeof name === "string") {
|
|
return this.sprites[name];
|
|
} else {
|
|
return name;
|
|
}
|
|
};
|
|
|
|
Engine.prototype.getTileset = function(name) {
|
|
if (typeof name === "string") {
|
|
return this.tilesets[name];
|
|
} else {
|
|
return name;
|
|
}
|
|
};
|
|
|
|
return Engine;
|
|
|
|
})();
|
|
|
|
Engine.prototype.draw = {
|
|
_startPath: (function(_this) {
|
|
return function(surface, options) {
|
|
var _ref;
|
|
surface = _this.getSurface(surface);
|
|
if ((_ref = !options._is_text) != null ? _ref : false) {
|
|
surface.beginPath();
|
|
}
|
|
return surface;
|
|
};
|
|
})(this),
|
|
_finishPath: (function(_this) {
|
|
return function(surface, options) {
|
|
var _ref, _ref1, _ref10, _ref11, _ref12, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
|
|
if ((_ref = options.stroke) != null ? _ref : true) {
|
|
surface.lineWidth = (_ref1 = (_ref2 = options.lineWidth) != null ? _ref2 : (_ref3 = options.pen) != null ? _ref3.lineWidth : void 0) != null ? _ref1 : 1;
|
|
surface.strokeStyle = (_ref4 = (_ref5 = options.lineColor) != null ? _ref5 : (_ref6 = options.pen) != null ? _ref6.lineColor : void 0) != null ? _ref4 : "black";
|
|
if ((_ref7 = options._is_text) != null ? _ref7 : false) {
|
|
surface.strokeText(options.text, options.x, options.y);
|
|
} else {
|
|
surface.stroke();
|
|
}
|
|
}
|
|
if ((_ref8 = options.fill) != null ? _ref8 : false) {
|
|
surface.fillStyle = (_ref9 = (_ref10 = options.fillColor) != null ? _ref10 : (_ref11 = options.pen) != null ? _ref11.fillColor : void 0) != null ? _ref9 : "white";
|
|
if ((_ref12 = options._is_text) != null ? _ref12 : false) {
|
|
return surface.fillText(options.text, options.x, options.y);
|
|
} else {
|
|
return surface.fill();
|
|
}
|
|
}
|
|
};
|
|
})(this),
|
|
_getTextWidth: (function(_this) {
|
|
return function(surface, text, options) {
|
|
var width;
|
|
_this._applyTextContext(surface, options);
|
|
width = surface.measureText(text).width;
|
|
surface.restore();
|
|
return width;
|
|
};
|
|
})(this),
|
|
_applyTextContext: (function(_this) {
|
|
return function(surface, options) {
|
|
var font_family, font_size, font_style, font_weight, scale, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
|
font_family = (_ref = options.font) != null ? _ref : "sans-serif";
|
|
font_size = (_ref1 = options.size) != null ? _ref1 : 16;
|
|
font_weight = (_ref2 = options.weight) != null ? _ref2 : "normal";
|
|
font_style = (_ref3 = options.style) != null ? _ref3 : "normal";
|
|
scale = (_ref4 = options.scale) != null ? _ref4 : 1;
|
|
surface.save();
|
|
surface.font = "" + font_weight + " " + font_style + " " + font_size + "px '" + font_family + "'";
|
|
surface.globalAlpha = (_ref5 = options.alpha) != null ? _ref5 : 1;
|
|
return surface.scale(scale, scale);
|
|
};
|
|
})(this),
|
|
line: (function(_this) {
|
|
return function(x1, y1, x2, y2, options, surface) {
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (surface == null) {
|
|
surface = "";
|
|
}
|
|
surface = _this._startPath(surface, options);
|
|
surface.moveTo(x1, y1);
|
|
surface.lineTo(x2, y2);
|
|
return _this._finishPath(surface, options);
|
|
};
|
|
})(this),
|
|
rectangle: (function(_this) {
|
|
return function(x1, y1, x2, y2, options, surface) {
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (surface == null) {
|
|
surface = "";
|
|
}
|
|
surface = _this._startPath(surface, options);
|
|
surface.rect(x1, y1, x2 - x1, y2 - y1);
|
|
return _this._finishPath(surface, options);
|
|
};
|
|
})(this),
|
|
boxEllipse: (function(_this) {
|
|
return function(x1, y1, x2, y2, options, surface) {
|
|
var rx, ry, x, y;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (surface == null) {
|
|
surface = "";
|
|
}
|
|
x = (x1 + x2) / 2;
|
|
y = (y1 + y2) / 2;
|
|
rx = (x2 - x1) / 2;
|
|
ry = (y2 - y1) / 2;
|
|
return _this.radiusEllipse(x, y, rx, ry, options, surface);
|
|
};
|
|
})(this),
|
|
radiusEllipse: (function(_this) {
|
|
return function(x, y, rx, ry, options, surface) {
|
|
var i, step, _i, _ref, _ref1;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (surface == null) {
|
|
surface = "";
|
|
}
|
|
surface = _this._startPath(surface, options);
|
|
step = (_ref = options.step) != null ? _ref : 0.1;
|
|
if (rx === ry) {
|
|
surface.arc(x, y, rx, 0, 2 * Math.PI, false);
|
|
} else {
|
|
surface.moveTo(x + rx, y);
|
|
for (i = _i = 0, _ref1 = Math.PI * 2 + step; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
|
|
surface.lineTo(x + (Math.cos(i) * rx), y + (Math.sin(i) * ry));
|
|
}
|
|
}
|
|
return _this._finishPath(surface, options);
|
|
};
|
|
})(this),
|
|
boxPolygon: (function(_this) {
|
|
return function(x1, y1, x2, y2, sides, options, surface) {
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (surface == null) {
|
|
surface = "";
|
|
}
|
|
return pass;
|
|
};
|
|
})(this),
|
|
radiusPolygon: (function(_this) {
|
|
return function(x, y, r, sides, options, surface) {
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (surface == null) {
|
|
surface = "";
|
|
}
|
|
return pass;
|
|
};
|
|
})(this),
|
|
text: (function(_this) {
|
|
return function(x, y, text, options, surface) {
|
|
var text_width;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (surface == null) {
|
|
surface = "";
|
|
}
|
|
if (options.alignment == null) {
|
|
options.alignment = "left";
|
|
}
|
|
if (options.scale == null) {
|
|
options.scale = 1;
|
|
}
|
|
options._is_text = true;
|
|
options.text = text;
|
|
options.y = y;
|
|
if (options.fill == null) {
|
|
options.fill = true;
|
|
}
|
|
if (options.fillColor == null) {
|
|
options.fillColor = "black";
|
|
}
|
|
if (options.stroke == null) {
|
|
options.stroke = false;
|
|
}
|
|
if (alignment === "left") {
|
|
options.x = x;
|
|
} else {
|
|
text_width = _this._getTextWidth(text, options);
|
|
if (alignment === "center") {
|
|
options.x = x - ((text_width / 2) * scale * scale);
|
|
} else if (alignment === "right") {
|
|
options.x = x - text_width;
|
|
}
|
|
}
|
|
_this._startPath(surface, options);
|
|
_this._finishPath(surface, options);
|
|
return surface.restore();
|
|
};
|
|
})(this)
|
|
};
|
|
|
|
Engine.prototype.ease = {
|
|
_calculateElasticValues: function(duration, amplitude, period, change, inout) {
|
|
var overshoot;
|
|
if (inout == null) {
|
|
inout = false;
|
|
}
|
|
if (period == null) {
|
|
if (inout) {
|
|
period = duration * (0.3 * 1.5);
|
|
} else {
|
|
period = duration * 0.3;
|
|
}
|
|
}
|
|
if ((amplitude == null) || amplitude < Math.abs(change)) {
|
|
amplitude = change;
|
|
overshoot = period / 4;
|
|
} else {
|
|
overshoot = period / (2 * Math.PI) * Math.asin(change / amplitude);
|
|
}
|
|
return [amplitude, period, change, overshoot];
|
|
},
|
|
backIn: function(start, end, duration, next, infinite, invert_repeat, overshoot) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
if (overshoot == null) {
|
|
overshoot = 1.70158;
|
|
}
|
|
return new Ease(this.engine, "backIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, overshoot);
|
|
},
|
|
backOut: function(start, end, duration, next, infinite, invert_repeat, overshoot) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
if (overshoot == null) {
|
|
overshoot = 1.70158;
|
|
}
|
|
return new Ease(this.engine, "backOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, overshoot);
|
|
},
|
|
backInOut: function(start, end, duration, next, infinite, invert_repeat, overshoot) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
if (overshoot == null) {
|
|
overshoot = 1.70158;
|
|
}
|
|
return new Ease(this.engine, "backInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, overshoot);
|
|
},
|
|
bounceOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "bounceOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
bounceIn: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "bounceIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
bounceInOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "bounceInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
circOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "circOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
circIn: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "circIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
circInOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "circInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
cubicOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "cubicOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
cubicIn: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "cubicIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
cubicInOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "cubicInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
elasticOut: function(start, end, duration, next, infinite, invert_repeat, amplitude, period) {
|
|
var change, overshoot, _ref;
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
if (amplitude == null) {
|
|
amplitude = null;
|
|
}
|
|
if (period == null) {
|
|
period = null;
|
|
}
|
|
_ref = this._calculateElasticValues(duration, amplitude, period, end - start), amplitude = _ref[0], period = _ref[1], change = _ref[2], overshoot = _ref[3];
|
|
end = start + change;
|
|
return new Ease(this.engine, "elasticOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot);
|
|
},
|
|
elasticIn: function(start, end, duration, next, infinite, invert_repeat, amplitude, period) {
|
|
var change, overshoot, _ref;
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
if (amplitude == null) {
|
|
amplitude = null;
|
|
}
|
|
if (period == null) {
|
|
period = null;
|
|
}
|
|
_ref = this._calculateElasticValues(duration, amplitude, period, end - start), amplitude = _ref[0], period = _ref[1], change = _ref[2], overshoot = _ref[3];
|
|
end = start + change;
|
|
return new Ease(this.engine, "elasticIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot);
|
|
},
|
|
elasticInOut: function(start, end, duration, next, infinite, invert_repeat, amplitude, period) {
|
|
var change, overshoot, _ref;
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
if (amplitude == null) {
|
|
amplitude = null;
|
|
}
|
|
if (period == null) {
|
|
period = null;
|
|
}
|
|
_ref = this._calculateElasticValues(duration, amplitude, period, end - start, true), amplitude = _ref[0], period = _ref[1], change = _ref[2], overshoot = _ref[3];
|
|
end = start + change;
|
|
return new Ease(this.engine, "elasticInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot);
|
|
},
|
|
expoOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "expoOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
expoIn: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "expoIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
expoInOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "expoInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
linearNone: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "linearNone", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
linearOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "linearNone", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
linearIn: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "linearNone", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
linearInOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "linearNone", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
quadOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "quadOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
quadIn: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "quadIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
quadInOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "quadInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
quartOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "quartOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
quartIn: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "quartIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
quartInOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "quartInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
sineOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "sineOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
sineIn: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "sineIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
},
|
|
sineInOut: function(start, end, duration, next, infinite, invert_repeat) {
|
|
if (next == null) {
|
|
next = null;
|
|
}
|
|
if (infinite == null) {
|
|
infinite = false;
|
|
}
|
|
if (invert_repeat == null) {
|
|
invert_repeat = false;
|
|
}
|
|
return new Ease(this.engine, "sineInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
|
|
}
|
|
};
|
|
|
|
Ease = (function() {
|
|
function Ease() {
|
|
var duration, end, engine, infinite, invert_repeat, next, params, start, start_frame, type;
|
|
engine = arguments[0], type = arguments[1], infinite = arguments[2], start = arguments[3], end = arguments[4], start_frame = arguments[5], duration = arguments[6], invert_repeat = arguments[7], next = arguments[8], params = 10 <= arguments.length ? __slice.call(arguments, 9) : [];
|
|
this.engine = engine;
|
|
this.type = type;
|
|
this.infinite = infinite;
|
|
this.start = start;
|
|
this.start_frame = start_frame;
|
|
this.duration = duration;
|
|
this.invert_repeat = invert_repeat;
|
|
this.next = next;
|
|
this.params = params;
|
|
this.quadInOut = __bind(this.quadInOut, this);
|
|
this.quadOut = __bind(this.quadOut, this);
|
|
this.quadIn = __bind(this.quadIn, this);
|
|
this.linearNone = __bind(this.linearNone, this);
|
|
this.expoInOut = __bind(this.expoInOut, this);
|
|
this.expoOut = __bind(this.expoOut, this);
|
|
this.expoIn = __bind(this.expoIn, this);
|
|
this.elasticInOut = __bind(this.elasticInOut, this);
|
|
this.elasticIn = __bind(this.elasticIn, this);
|
|
this.elasticOut = __bind(this.elasticOut, this);
|
|
this.cubicInOut = __bind(this.cubicInOut, this);
|
|
this.cubicOut = __bind(this.cubicOut, this);
|
|
this.cubicIn = __bind(this.cubicIn, this);
|
|
this.circInOut = __bind(this.circInOut, this);
|
|
this.circOut = __bind(this.circOut, this);
|
|
this.circIn = __bind(this.circIn, this);
|
|
this.bounceInOut = __bind(this.bounceInOut, this);
|
|
this.bounceIn = __bind(this.bounceIn, this);
|
|
this.bounceOut = __bind(this.bounceOut, this);
|
|
this.backInOut = __bind(this.backInOut, this);
|
|
this.backOut = __bind(this.backOut, this);
|
|
this.backIn = __bind(this.backIn, this);
|
|
this.valueOf = __bind(this.valueOf, this);
|
|
this.updateValue = __bind(this.updateValue, this);
|
|
this.goToNext = __bind(this.goToNext, this);
|
|
this.func = this[this.type];
|
|
this.change = end - this.start;
|
|
this.value = this.start;
|
|
this.last_updated = this.start_frame;
|
|
this.finished = false;
|
|
}
|
|
|
|
Ease.prototype.goToNext = function() {
|
|
this.func = this[this.next.type];
|
|
this.change = this.next.change;
|
|
this.value = this.next.value;
|
|
this.start_frame = this.last_updated = this.engine.current_frame;
|
|
this.infinite = this.next.infinite;
|
|
this.start = this.next.start;
|
|
this.change = this.next.change;
|
|
this.invert_repeat = this.next.invert_repeat;
|
|
this.params = this.next.params;
|
|
this.duration = this.next.duration;
|
|
this.finished = false;
|
|
return this.next = this.next.next;
|
|
};
|
|
|
|
Ease.prototype.updateValue = function(current_frame) {
|
|
if (current_frame >= this.start_frame + this.duration) {
|
|
if (this.infinite) {
|
|
this.start_frame = current_frame;
|
|
if (this.invert_repeat) {
|
|
this.start = this.start + this.change;
|
|
this.change = -this.change;
|
|
}
|
|
return this.value = this.start;
|
|
} else if (this.next != null) {
|
|
return this.goToNext();
|
|
} else {
|
|
this.finished = true;
|
|
return this.value = this.start + this.change;
|
|
}
|
|
} else {
|
|
return this.value = this.func(current_frame - this.start_frame);
|
|
}
|
|
};
|
|
|
|
Ease.prototype.valueOf = function() {
|
|
if (!this.finished && this.engine.current_frame > this.last_updated) {
|
|
this.updateValue(this.engine.current_frame);
|
|
this.last_updated = this.engine.current_frame;
|
|
}
|
|
return this.value;
|
|
};
|
|
|
|
Ease.prototype.backIn = function(time) {
|
|
var overshoot;
|
|
time = time / this.duration;
|
|
overshoot = this.params[0];
|
|
return this.change * time * time * ((overshoot + 1) * time - overshoot) + this.start;
|
|
};
|
|
|
|
Ease.prototype.backOut = function(time) {
|
|
var overshoot;
|
|
time = time / this.duration - 1;
|
|
overshoot = this.params[0];
|
|
return this.change * (time * time * ((overshoot + 1) * time + overshoot) + 1) + this.start;
|
|
};
|
|
|
|
Ease.prototype.backInOut = function(time) {
|
|
var overshoot;
|
|
time = time / (this.duration / 2);
|
|
overshoot = this.params[0] * 1.525;
|
|
if (time < 1) {
|
|
return this.change / 2 * (time * time * ((overshoot + 1) * time - overshoot)) + this.start;
|
|
} else {
|
|
time -= 2;
|
|
return this.change / 2 * (time * time * ((overshoot + 1) * time + overshoot) + 2) + this.start;
|
|
}
|
|
};
|
|
|
|
Ease.prototype.bounceOut = function(time, start) {
|
|
if (start == null) {
|
|
start = null;
|
|
}
|
|
time = time / this.duration;
|
|
start = start != null ? start : this.start;
|
|
if (time < 1 / 2.75) {
|
|
return this.change * (7.5625 * time * time) + start;
|
|
} else if (time < 2 / 2.75) {
|
|
time = time - (1.5 / 2.75);
|
|
return this.change * (7.5625 * time * time + 0.75) + start;
|
|
} else if (time < 2.5 / 2.75) {
|
|
time = time - (2.25 / 2.75);
|
|
return this.change * (7.5625 * time * time + 0.9375) + start;
|
|
} else {
|
|
time = time - (2.625 / 2.75);
|
|
return this.change * (7.5625 * time * time + 0.984375) + start;
|
|
}
|
|
};
|
|
|
|
Ease.prototype.bounceIn = function(time, start) {
|
|
if (start == null) {
|
|
start = null;
|
|
}
|
|
start = start != null ? start : this.start;
|
|
return this.change - this.bounceOut(this.duration - time, 0) + start;
|
|
};
|
|
|
|
Ease.prototype.bounceInOut = function(time) {
|
|
if (time < this.duration / 2) {
|
|
return this.bounceIn(time * 2, 0) + this.start;
|
|
} else {
|
|
return this.bounceOut(time * 2 - this.duration, 0) + this.start;
|
|
}
|
|
};
|
|
|
|
Ease.prototype.circIn = function(time) {
|
|
time = time / this.duration;
|
|
return -this.change * (Math.sqrt(1 - time * time) - 1) + this.start;
|
|
};
|
|
|
|
Ease.prototype.circOut = function(time) {
|
|
time = time / this.duration - 1;
|
|
return this.change * Math.sqrt(1 - time * time) + this.start;
|
|
};
|
|
|
|
Ease.prototype.circInOut = function(time) {
|
|
time = time / (this.duration / 2);
|
|
if (time < 1) {
|
|
return -this.change / 2 * (Math.sqrt(1 - time * time) - 1) + this.start;
|
|
} else {
|
|
time = time - 2;
|
|
return this.change / 2 * (Math.sqrt(1 - time * time) + 1) + this.start;
|
|
}
|
|
};
|
|
|
|
Ease.prototype.cubicIn = function(time) {
|
|
time = time / this.duration;
|
|
return this.change * time * time * time + this.start;
|
|
};
|
|
|
|
Ease.prototype.cubicOut = function(time) {
|
|
time = time / this.duration - 1;
|
|
return this.change * (time * time * time + 1) + this.start;
|
|
};
|
|
|
|
Ease.prototype.cubicInOut = function(time) {
|
|
time = time / (this.duration / 2);
|
|
if (time < 1) {
|
|
return change / 2 * time * time * time + this.start;
|
|
} else {
|
|
time = time - 2;
|
|
return change / 2 * (time * time * time + 2) + begin;
|
|
}
|
|
};
|
|
|
|
Ease.prototype.elasticOut = function(time) {
|
|
var amplitude, overshoot, period;
|
|
time = time / this.duration;
|
|
amplitude = this.params[0];
|
|
period = this.params[1];
|
|
overshoot = this.params[2];
|
|
return (amplitude * Math.pow(2, -10 * time)) * Math.sin((time * this.duration - overshoot) * (2 * Math.PI) / period) + this.change + this.start;
|
|
};
|
|
|
|
Ease.prototype.elasticIn = function(time) {
|
|
var amplitude, overshoot, period;
|
|
time = time / this.duration;
|
|
amplitude = this.params[0];
|
|
period = this.params[1];
|
|
overshoot = this.params[2];
|
|
return -(amplitude * Math.pow(2, -10 * time)) * Math.sin((time * this.duration - overshoot) * (2 * Math.PI) / period) + this.start;
|
|
};
|
|
|
|
Ease.prototype.elasticInOut = function(time) {
|
|
var amplitude, overshoot, period;
|
|
time = time / (this.duration / 2) - 1;
|
|
amplitude = this.params[0];
|
|
period = this.params[1];
|
|
overshoot = this.params[2];
|
|
if (time < 1) {
|
|
return -0.5 * (amplitude * Math.pow(2, -10 * time)) * Math.sin((time * this.duration - overshoot) * ((2 * Math.PI) / period)) + this.start;
|
|
} else {
|
|
return amplitude * Math.pow(2, -10 * time) * Math.sin((time * this.duration - overshoot) * (2 * Math.PI) / period) + this.change + this.start;
|
|
}
|
|
};
|
|
|
|
Ease.prototype.expoIn = function(time) {
|
|
return this.change * Math.pow(2, 10 * (time / this.duration - 1)) + this.start;
|
|
};
|
|
|
|
Ease.prototype.expoOut = function(time) {
|
|
return this.change * (-Math.pow(2, -10 * time / this.duration) + 1) + this.start;
|
|
};
|
|
|
|
Ease.prototype.expoInOut = function(time) {
|
|
time = time / (this.duration / 2);
|
|
if (time < 1) {
|
|
return this.change / 2 * Math.pow(2, 10 * (time - 1)) + this.start;
|
|
} else {
|
|
return this.change / 2 * (-Math.pow(2, -10 * (time - 1)) + 2) + this.start;
|
|
}
|
|
};
|
|
|
|
Ease.prototype.linearNone = function(time) {
|
|
return this.change * time / this.duration + this.start;
|
|
};
|
|
|
|
Ease.prototype.quadIn = function(time) {
|
|
time = time / this.duration;
|
|
return this.change * time * time + this.start;
|
|
};
|
|
|
|
Ease.prototype.quadOut = function(time) {
|
|
time = time / this.duration;
|
|
return -this.change * time * (time - 2) + this.start;
|
|
};
|
|
|
|
Ease.prototype.quadInOut = function(time) {
|
|
time = time / (this.duration / 2);
|
|
if (time < 1) {
|
|
return this.change / 2 * time * time + this.start;
|
|
} else {
|
|
time = time - 1;
|
|
return -this.change / 2 * (time * (time - 2) - 1) + this.start;
|
|
}
|
|
};
|
|
|
|
return Ease;
|
|
|
|
})();
|
|
|
|
Engine.prototype.random = {
|
|
number: (function(_this) {
|
|
return function(min, max, precision) {
|
|
var base_number, rounding_factor, space;
|
|
base_number = Math.random();
|
|
space = Math.abs(max - min);
|
|
rounding_factor = 1 / (precision != null ? precision : 0.00000001);
|
|
return Math.floor((min + (base_number * space)) * rounding_factor) / rounding_factor;
|
|
};
|
|
})(this),
|
|
pick: (function(_this) {
|
|
return function() {
|
|
var options;
|
|
options = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
return options[Math.floor(Math.random() * options.length)];
|
|
};
|
|
})(this),
|
|
string: (function(_this) {
|
|
return function(length, alphabet) {
|
|
var i;
|
|
if (alphabet == null) {
|
|
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
}
|
|
return ((function() {
|
|
var _i, _ref, _results;
|
|
_results = [];
|
|
for (i = _i = 0, _ref = length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
|
|
_results.push(alphabet[Math.floor(Math.random() * alphabet.length)]);
|
|
}
|
|
return _results;
|
|
})()).join("");
|
|
};
|
|
})(this)
|
|
};
|
|
|
|
Engine.prototype.timing = {
|
|
startTimer: (function(_this) {
|
|
return function(frames, callback, name, repeat) {
|
|
var timer;
|
|
if (name == null) {
|
|
name = null;
|
|
}
|
|
if (repeat == null) {
|
|
repeat = false;
|
|
}
|
|
timer = new Timer(frames, callback, repeat);
|
|
if (name != null) {
|
|
return _this.named_timers[name] = timer;
|
|
} else {
|
|
return _this.unnamed_timers.push(timer);
|
|
}
|
|
};
|
|
})(this),
|
|
stopTimer: (function(_this) {
|
|
return function(name) {
|
|
return _this.timers[name].stop();
|
|
};
|
|
})(this)
|
|
};
|
|
|
|
Timer = (function() {
|
|
function Timer(frames, callback, repeat) {
|
|
this.frames = frames;
|
|
this.callback = callback;
|
|
this.repeat = repeat;
|
|
this.stop = __bind(this.stop, this);
|
|
this.skip = __bind(this.skip, this);
|
|
this.step = __bind(this.step, this);
|
|
this.current_frame = 0;
|
|
this.finished = false;
|
|
}
|
|
|
|
Timer.prototype.step = function() {
|
|
if (this.current_frame >= this.frames) {
|
|
this.callback();
|
|
if (repeat) {
|
|
return this.current_frame = 0;
|
|
} else {
|
|
return this.finished = true;
|
|
}
|
|
}
|
|
};
|
|
|
|
Timer.prototype.skip = function(frames) {
|
|
return this.current_frame += frames;
|
|
};
|
|
|
|
Timer.prototype.stop = function() {
|
|
return this.finished = true;
|
|
};
|
|
|
|
return Timer;
|
|
|
|
})();
|
|
|
|
Object = (function() {
|
|
function Object(engine, name) {
|
|
this.engine = engine;
|
|
this.name = name;
|
|
this.sprite = null;
|
|
this.instances = [];
|
|
this.x = 0;
|
|
this.y = 0;
|
|
}
|
|
|
|
Object.prototype.callEvent = function(name, data) {
|
|
var event_map, _ref, _ref1;
|
|
if (data == null) {
|
|
data = {};
|
|
}
|
|
event_map = {
|
|
mouseover: this.onMouseOver,
|
|
mouseout: this.onMouseOut,
|
|
create: this.onCreate,
|
|
step: this.onStep,
|
|
click: this.onClick,
|
|
click_global: this.onClickGlobal
|
|
};
|
|
switch (name) {
|
|
case "draw":
|
|
this.drawSelf((_ref = data.surface) != null ? _ref : "");
|
|
return typeof this.onDraw === "function" ? this.onDraw(data) : void 0;
|
|
default:
|
|
return (_ref1 = event_map[name]) != null ? _ref1.bind(this)(data) : void 0;
|
|
}
|
|
};
|
|
|
|
Object.prototype.drawSelf = function(surface) {
|
|
return this.drawSprite(surface);
|
|
};
|
|
|
|
Object.prototype.drawSprite = function(surface) {
|
|
var _ref;
|
|
if (surface == null) {
|
|
surface = "";
|
|
}
|
|
if ((this.sprite != null) && ((_ref = this.draw_sprite) != null ? _ref : "true")) {
|
|
return this.sprite.draw(this.x, this.y, {}, surface);
|
|
}
|
|
};
|
|
|
|
Object.prototype.getBoundingBox = function() {
|
|
var image_size, _ref;
|
|
image_size = (_ref = this.sprite) != null ? _ref.getSize() : void 0;
|
|
return {
|
|
x1: this.x,
|
|
x2: this.x + (image_size != null ? image_size.width : void 0),
|
|
y1: this.y,
|
|
y2: this.y + (image_size != null ? image_size.height : void 0)
|
|
};
|
|
};
|
|
|
|
Object.prototype.getInstances = function() {
|
|
return this.instances;
|
|
};
|
|
|
|
Object.prototype.checkPointCollision = function(x, y) {
|
|
var bounding_box;
|
|
bounding_box = this.getBoundingBox();
|
|
return x >= (bounding_box != null ? bounding_box.x1 : void 0) && x <= (bounding_box != null ? bounding_box.x2 : void 0) && y >= (bounding_box != null ? bounding_box.y1 : void 0) && y <= (bounding_box != null ? bounding_box.y2 : void 0);
|
|
};
|
|
|
|
return Object;
|
|
|
|
})();
|
|
|
|
ResourceManager = (function() {
|
|
function ResourceManager(base_path) {
|
|
this.base_path = base_path != null ? base_path : "";
|
|
this.preload = __bind(this.preload, this);
|
|
this.prepare = __bind(this.prepare, this);
|
|
this.getImage = __bind(this.getImage, this);
|
|
this.addSounds = __bind(this.addSounds, this);
|
|
this.addScripts = __bind(this.addScripts, this);
|
|
this.addImages = __bind(this.addImages, this);
|
|
this.addScript = __bind(this.addScript, this);
|
|
this.addSound = __bind(this.addSound, this);
|
|
this.addImage = __bind(this.addImage, this);
|
|
this.joinPath = __bind(this.joinPath, this);
|
|
this.resources = {
|
|
stage1_images: [],
|
|
stage1_audio: [],
|
|
stage1_scripts: [],
|
|
images: [],
|
|
audio: [],
|
|
scripts: []
|
|
};
|
|
this.resource_objects = {
|
|
images: {},
|
|
audio: {},
|
|
scripts: {}
|
|
};
|
|
}
|
|
|
|
ResourceManager.prototype.joinPath = function(path) {
|
|
if (this.base_path === "") {
|
|
return path;
|
|
} else {
|
|
return util.stripRight(this.base_path, "/") + "/" + path;
|
|
}
|
|
};
|
|
|
|
ResourceManager.prototype.addImage = function(path, first_stage) {
|
|
if (first_stage == null) {
|
|
first_stage = false;
|
|
}
|
|
if (first_stage) {
|
|
return this.resources.stage1_images.push(this.joinPath(path));
|
|
} else {
|
|
return this.resources.images.push(this.joinPath(path));
|
|
}
|
|
};
|
|
|
|
ResourceManager.prototype.addSound = function(path, first_stage) {
|
|
if (first_stage == null) {
|
|
first_stage = false;
|
|
}
|
|
if (first_stage) {
|
|
return this.resources.stage1_audio.push(this.joinPath(path));
|
|
} else {
|
|
return this.resources.audio.push(this.joinPath(path));
|
|
}
|
|
};
|
|
|
|
ResourceManager.prototype.addScript = function(path, first_stage) {
|
|
if (first_stage == null) {
|
|
first_stage = false;
|
|
}
|
|
if (first_stage) {
|
|
return this.resources.stage1_scripts.push(this.joinPath(path));
|
|
} else {
|
|
return this.resources.scripts.push(this.joinPath(path));
|
|
}
|
|
};
|
|
|
|
ResourceManager.prototype.addImages = function(paths, first_stage) {
|
|
var path, _i, _len, _results;
|
|
if (first_stage == null) {
|
|
first_stage = false;
|
|
}
|
|
_results = [];
|
|
for (_i = 0, _len = paths.length; _i < _len; _i++) {
|
|
path = paths[_i];
|
|
_results.push(this.addImage(path, first_stage));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
ResourceManager.prototype.addScripts = function(paths, first_stage) {
|
|
var path, _i, _len, _results;
|
|
if (first_stage == null) {
|
|
first_stage = false;
|
|
}
|
|
_results = [];
|
|
for (_i = 0, _len = paths.length; _i < _len; _i++) {
|
|
path = paths[_i];
|
|
_results.push(this.addScript(path, first_stage));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
ResourceManager.prototype.addSounds = function(paths, first_stage) {
|
|
var path, _i, _len, _results;
|
|
if (first_stage == null) {
|
|
first_stage = false;
|
|
}
|
|
_results = [];
|
|
for (_i = 0, _len = paths.length; _i < _len; _i++) {
|
|
path = paths[_i];
|
|
_results.push(this.addSound(path, first_stage));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
ResourceManager.prototype.getImage = function(path) {
|
|
console.log("objs", this.resource_objects);
|
|
console.log("path", path);
|
|
return this.resource_objects.images[this.joinPath(path)];
|
|
};
|
|
|
|
ResourceManager.prototype.prepare = function(finished_callback) {
|
|
if (finished_callback == null) {
|
|
finished_callback = (function() {});
|
|
}
|
|
return pass;
|
|
};
|
|
|
|
ResourceManager.prototype.preload = function(progress_callback, finished_callback) {
|
|
var image, obj, _i, _len, _ref;
|
|
if (progress_callback == null) {
|
|
progress_callback = (function() {});
|
|
}
|
|
if (finished_callback == null) {
|
|
finished_callback = (function() {});
|
|
}
|
|
_ref = this.resources.images;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
image = _ref[_i];
|
|
obj = document.createElement("img");
|
|
obj.src = image;
|
|
this.resource_objects.images[image] = obj;
|
|
}
|
|
return finished_callback();
|
|
};
|
|
|
|
return ResourceManager;
|
|
|
|
})();
|
|
|
|
Scene = (function() {
|
|
function Scene(engine, name) {
|
|
this.engine = engine;
|
|
this.name = name;
|
|
this.changeScene = __bind(this.changeScene, this);
|
|
this.createInstance = __bind(this.createInstance, this);
|
|
this.checkMouseCollisions = __bind(this.checkMouseCollisions, this);
|
|
this.redraw = __bind(this.redraw, this);
|
|
this.iteration = __bind(this.iteration, this);
|
|
this.checkActive = __bind(this.checkActive, this);
|
|
this.removeTargetSurface = __bind(this.removeTargetSurface, this);
|
|
this.handleMouseDown = __bind(this.handleMouseDown, this);
|
|
this.handleMouseUp = __bind(this.handleMouseUp, this);
|
|
this.handleClick = __bind(this.handleClick, this);
|
|
this.addTargetSurface = __bind(this.addTargetSurface, this);
|
|
this.instances = {};
|
|
this.surfaces = [];
|
|
this.dirty = true;
|
|
this.last_instance_id = 100;
|
|
this.active = false;
|
|
this.width = 800;
|
|
this.height = 600;
|
|
this.last_width = 800;
|
|
this.last_height = 600;
|
|
}
|
|
|
|
Scene.prototype.addTargetSurface = function(surface) {
|
|
this.surfaces.push(surface);
|
|
this.engine.updateCanvasSize(surface, this.width, this.height);
|
|
$(surface).on("mousemove.radium", (function(_this) {
|
|
return function(event) {
|
|
var canvas_pos;
|
|
canvas_pos = surface.getBoundingClientRect();
|
|
_this.mouse_x = (event.clientX - canvas_pos.left) | 0;
|
|
_this.mouse_y = (event.clientY - canvas_pos.top) | 0;
|
|
return _this.checkMouseCollisions();
|
|
};
|
|
})(this));
|
|
$(surface).on("click.radium", (function(_this) {
|
|
return function(event) {
|
|
return _this.handleClick(event);
|
|
};
|
|
})(this));
|
|
$(surface).on("mouseup.radium", (function(_this) {
|
|
return function(event) {
|
|
return _this.handleMouseUp(event);
|
|
};
|
|
})(this));
|
|
$(surface).on("mousedown.radium", (function(_this) {
|
|
return function(event) {
|
|
return _this.handleMouseDown(event);
|
|
};
|
|
})(this));
|
|
return this.checkActive();
|
|
};
|
|
|
|
Scene.prototype.handleClick = function(event) {
|
|
var id, instance, _ref;
|
|
_ref = this.instances;
|
|
for (id in _ref) {
|
|
instance = _ref[id];
|
|
instance.callEvent("click_global", {
|
|
x: this.mouse_x,
|
|
y: this.mouse_y,
|
|
button: event.which
|
|
});
|
|
if (instance.checkPointCollision(this.mouse_x, this.mouse_y)) {
|
|
instance.callEvent("click", {
|
|
x: this.mouse_x,
|
|
y: this.mouse_y,
|
|
button: event.which
|
|
});
|
|
}
|
|
}
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
return false;
|
|
};
|
|
|
|
Scene.prototype.handleMouseUp = function(event) {
|
|
return pass;
|
|
};
|
|
|
|
Scene.prototype.handleMouseDown = function(event) {
|
|
return pass;
|
|
};
|
|
|
|
Scene.prototype.removeTargetSurface = function(surface) {
|
|
this.surfaces = this.surfaces.filter(function(obj) {
|
|
return obj !== surface;
|
|
});
|
|
$(surface).off("mousemove.radium");
|
|
return this.checkActive();
|
|
};
|
|
|
|
Scene.prototype.checkActive = function() {
|
|
return this.active = this.surfaces.length > 0;
|
|
};
|
|
|
|
Scene.prototype.iteration = function() {
|
|
var id, instance, surface, _i, _len, _ref, _ref1, _ref2;
|
|
if (this.width !== this.last_width || this.height !== this.last_height) {
|
|
_ref = this.surfaces;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
surface = _ref[_i];
|
|
this.engine.updateCanvasSize(surface, this.width, this.height);
|
|
}
|
|
_ref1 = [this.width, this.height], this.last_width = _ref1[0], this.last_height = _ref1[1];
|
|
}
|
|
_ref2 = this.instances;
|
|
for (id in _ref2) {
|
|
instance = _ref2[id];
|
|
if (instance.callEvent("step")) {
|
|
this.dirty = true;
|
|
}
|
|
}
|
|
if (this.dirty) {
|
|
this.redraw();
|
|
return this.dirty = false;
|
|
}
|
|
};
|
|
|
|
Scene.prototype.redraw = function() {
|
|
var ctx, id, instance, surface, _i, _len, _ref, _results;
|
|
_ref = this.surfaces;
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
surface = _ref[_i];
|
|
ctx = this.engine.getSurface(surface);
|
|
ctx.clearRect(0, 0, surface.width, surface.height);
|
|
_results.push((function() {
|
|
var _ref1, _results1;
|
|
_ref1 = this.instances;
|
|
_results1 = [];
|
|
for (id in _ref1) {
|
|
instance = _ref1[id];
|
|
_results1.push(instance.callEvent("draw", {
|
|
surface: surface
|
|
}));
|
|
}
|
|
return _results1;
|
|
}).call(this));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
Scene.prototype.checkMouseCollisions = function() {
|
|
var collision, id, instance, _ref, _results;
|
|
_ref = this.instances;
|
|
_results = [];
|
|
for (id in _ref) {
|
|
instance = _ref[id];
|
|
collision = instance.checkPointCollision(this.mouse_x, this.mouse_y);
|
|
if (collision && !instance._moused_over) {
|
|
instance.callEvent("mouseover");
|
|
_results.push(instance._moused_over = true);
|
|
} else if (!collision && instance._moused_over) {
|
|
instance.callEvent("mouseout");
|
|
_results.push(instance._moused_over = false);
|
|
} else {
|
|
_results.push(void 0);
|
|
}
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
Scene.prototype.createInstance = function(object, x, y) {
|
|
var id, instance, real_object;
|
|
if (x == null) {
|
|
x = 0;
|
|
}
|
|
if (y == null) {
|
|
y = 0;
|
|
}
|
|
id = this.last_instance_id += 1;
|
|
real_object = this.engine.getObject(object);
|
|
instance = window.Object.create(real_object);
|
|
instance.x = x;
|
|
instance.y = y;
|
|
instance.id = id;
|
|
instance.scene = this;
|
|
this.instances[id] = instance;
|
|
real_object.instances.push(instance);
|
|
instance.callEvent("create");
|
|
return instance;
|
|
};
|
|
|
|
Scene.prototype.changeScene = function(scene) {
|
|
return pass;
|
|
};
|
|
|
|
return Scene;
|
|
|
|
})();
|
|
|
|
Sound = (function() {
|
|
function Sound() {}
|
|
|
|
return Sound;
|
|
|
|
})();
|
|
|
|
Sprite = (function() {
|
|
function Sprite(engine, name, image) {
|
|
this.engine = engine;
|
|
this.name = name;
|
|
this.image = image;
|
|
this.getSize = __bind(this.getSize, this);
|
|
this.draw = __bind(this.draw, this);
|
|
pass;
|
|
}
|
|
|
|
Sprite.prototype.draw = function(x, y, options, surface) {
|
|
var _ref;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (surface == null) {
|
|
surface = "";
|
|
}
|
|
surface = this.engine.getSurface(surface);
|
|
surface.globalAlpha = (_ref = options.alpha) != null ? _ref : 1;
|
|
return surface.drawImage(this.image, x, y);
|
|
};
|
|
|
|
Sprite.prototype.getSize = function() {
|
|
return {
|
|
width: this.image.width,
|
|
height: this.image.height
|
|
};
|
|
};
|
|
|
|
return Sprite;
|
|
|
|
})();
|
|
|
|
Tileset = (function() {
|
|
function Tileset(engine, name, image, tile_width, tile_height) {
|
|
this.engine = engine;
|
|
this.name = name;
|
|
this.image = image;
|
|
this.tile_width = tile_width;
|
|
this.tile_height = tile_height;
|
|
this.tile = __bind(this.tile, this);
|
|
this.tiles = {};
|
|
}
|
|
|
|
Tileset.prototype.tile = function(x, y, precise, w, h) {
|
|
var key, _ref;
|
|
if (precise == null) {
|
|
precise = false;
|
|
}
|
|
if (w == null) {
|
|
w = 0;
|
|
}
|
|
if (h == null) {
|
|
h = 0;
|
|
}
|
|
key = ("" + x + "/" + y + "/" + w + "/" + h + "/") + (precise ? 1 : 0);
|
|
return (_ref = this.tiles[key]) != null ? _ref : tiles[key] = new TilesetTile(this.engine, this, x, y, precise, w, h);
|
|
};
|
|
|
|
return Tileset;
|
|
|
|
})();
|
|
|
|
TilesetTile = (function() {
|
|
function TilesetTile(engine, tileset, x, y, precise, w, h) {
|
|
this.engine = engine;
|
|
this.tileset = tileset;
|
|
this.x = x;
|
|
this.y = y;
|
|
this.precise = precise != null ? precise : false;
|
|
this.w = w != null ? w : 0;
|
|
this.h = h != null ? h : 0;
|
|
this.getSize = __bind(this.getSize, this);
|
|
this.draw = __bind(this.draw, this);
|
|
pass;
|
|
}
|
|
|
|
TilesetTile.prototype.draw = function(x, y) {
|
|
var source_h, source_w, source_x, source_y, surface;
|
|
if (this.precise) {
|
|
source_x = this.x;
|
|
source_y = this.y;
|
|
source_w = this.w;
|
|
source_h = this.h;
|
|
} else {
|
|
source_x = this.x * this.tileset.tile_width;
|
|
source_y = this.y * this.tileset.tile_height;
|
|
source_w = this.tileset.tile_width;
|
|
source_h = this.tileset.tile_height;
|
|
}
|
|
surface = this.engine.getSurface();
|
|
return surface.drawImage(source_x, source_y, source_width, source_height, x, y);
|
|
};
|
|
|
|
TilesetTile.prototype.getSize = function() {
|
|
if (this.precise) {
|
|
return {
|
|
width: this.w,
|
|
height: this.h
|
|
};
|
|
} else {
|
|
return {
|
|
width: this.tileset.tile_width,
|
|
height: this.tileset.tile_height
|
|
};
|
|
}
|
|
};
|
|
|
|
return TilesetTile;
|
|
|
|
})();
|
|
|
|
util = {
|
|
stripRight: function(string, character) {
|
|
return string.replace(new RegExp(character + "*$", "g"), "");
|
|
},
|
|
unpackElement: function(element) {
|
|
console.log(element);
|
|
if (element instanceof jQuery) {
|
|
return element[0];
|
|
} else {
|
|
return element;
|
|
}
|
|
}
|
|
};
|
|
|
|
window.ResourceManager = ResourceManager;
|
|
|
|
window.Engine = Engine;
|
|
|
|
}).call(this);
|