2014-08-25 20:50:24 +00:00
|
|
|
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.terra=t()}}(function(){var t;return function e(t,n,r){function o(u,a){if(!n[u]){if(!t[u]){var c="function"==typeof require&&require;if(!a&&c)return c(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var s=n[u]={exports:{}};t[u][0].call(s.exports,function(e){var n=t[u][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(t,e){var n=t("./terrarium.js"),r=t("./creature.js");e.exports={Terrarium:n,creatureFactory:r}},{"./creature.js":2,"./terrarium.js":5}],2:[function(t,e){var n=t("./util.js"),r=function(){function t(){this.age=0}t.prototype.initialEnergy=50,t.prototype.maxEnergy=100,t.prototype.efficiency=.7,t.prototype.size=50,t.prototype.actionRadius=1,t.prototype.sustainability=2,t.prototype.reproduceLv=.7,t.prototype.moveLv=0,t.prototype.boundEnergy=function(){this.energy>this.maxEnergy&&(this.energy=this.maxEnergy)},t.prototype.isDead=function(){return this.energy<=0},t.prototype.reproduce=function(t){var e=n.filter(t,function(t){return!t.creature});if(e.length){var o=e[n.random(e.length-1)],i=o.coords,u=r.make(this.type),a=function(){return this.energy-=this.initialEnergy,!0}.bind(this),c=this.wait;return{x:i.x,y:i.y,creature:u,successFn:a,failureFn:c}}return!1},t.prototype.move=function(t){var e=this,r=n.filter(t,function(t){return t.creature.size<this.size}.bind(this));if(r.length<this.sustainability&&(r=n.filter(t,function(t){return!t.creature})),r.length){var o=r[n.random(r.length-1)],i=o.coords,u=function(){var t=o.creature.energy*this.efficiency;return this.energy=this.energy+(t||-10),!1}.bind(this);return{x:i.x,y:i.y,creature:e,successFn:u}}return!1},t.prototype.wait=function(){return this.energy-=5,!0},t.prototype.queue=function(t){var e={},n=this.maxEnergy;this.energy>n*this.reproduceLv&&this.reproduce?e=this.reproduce(t):this.energy>n*this.moveLv&&this.move&&(e=this.move(t));var r=e.creature;return r?(r.successFn=e.successFn||r.wait,r.failureFn=e.failureFn||r.wait,{x:e.x,y:e.y,creature:r}):!1};var e={};return{make:function(t,n){var r=e[t];return r?new r(n):!1},register:function(r,o){var i=r.type;if("string"==typeof i&&"undefined"==typeof e[i]){e[i]="function"==typeof o?function(){this.energy=this.initialEnergy,o.call(this)}:function(){this.energy=this.initialEnergy};var u=r.color;return("object"!=typeof u||3!==u.length)&&(r.color=[n.random(255),n.random(255),n.random(255)]),e[i].prototype=new t,e[i].prototype.constructor=e[i],n.each(r,function(t,n){e[i].prototype[n]=t}),e[i].prototype.successFn=e[i].wait,e[i].prototype.failureFn=e[i].wait,e[i].prototype.energy=r.initialEnergy,!0}return!1}}}();e.exports=r},{"./util.js":6}],3:[function(t,e){var n=t("./util.js");e.exports=function(t,e,r){var o=t.getContext("2d");o.clearRect(0,0,t.width,t.height),n.each(e,function(t,e){n.each(t,function(t,n){if(t){var i=t.colorFn?t.colorFn():t.color+","+t.energy/t.maxEnergy;o.fillStyle="rgba("+i+")",t.character?o.fillText(t.character,e*r,n*r+r):o.fillRect(e*r,n*r,r,r)}})})}},{"./util.js":6}],4:[function(t,e){var n=function(t,e,n,r,o){function i(o){var i=document.createElement("canvas"),u=i.getContext("2d");return o=function(){var t=document.createElement("canvas").getContext("2d"),e=window.devicePixelRatio||1,n=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return e/n}(),i.width=t*o,i.height=e*o,i.style.width=t+"px",i.style.height=e+"px",u.setTransform(o,0,0,o,0,0),u.font="bold "+n+"px Arial",r&&(i.id=r),i}t*=n,e*=n;var u=i();return o?o.parentNode.insertBefore(u,o.nextSibling):document.body.appendChild(u),u};e.exports={createCanvasElement:n}},{}],5:[function(t,e){function n(t,e,n,r,o){r=r||10,this.cellSize=r,t
|