mirror of
https://github.com/rileyjshaw/terra.git
synced 2024-11-21 04:54:23 +00:00
1 line
24 KiB
JavaScript
1 line
24 KiB
JavaScript
|
!function t(e,n,r){function o(a,u){if(!n[a]){if(!e[a]){var c="function"==typeof require&&require;if(!u&&c)return c(a,!0);if(i)return i(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var l=n[a]={exports:{}};e[a][0].call(l.exports,function(t){var n=e[a][1][t];return o(n?n:t)},l,l.exports,t,e,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(t){function e(){document.body.className=document.body.scrollTop>=o?"sticky":""}function n(t,e){var n=function(){setTimeout(function(){t(),requestAnimationFrame(n)},1e3/e)};requestAnimationFrame(n)}var r=t("../../app/terrarium.js");t("./bugs.js"),t("../../bower_components/smooth-scroll.js/dist/js/bind-polyfill.min.js"),t("../../bower_components/smooth-scroll.js/dist/js/smooth-scroll.min.js").init({offset:60});var o=window.innerHeight,i=document.documentElement.clientWidth,a=Math.ceil(o/20),u=Math.ceil(i/20),c=new r(u,a,"topTerrarium",20,document.getElementById("header"));c.canvas.style.top=c.canvas.style.left="50%",c.canvas.style.marginTop=-10*a+"px",c.canvas.style.marginLeft=-10*u+"px",c.populate([["plant",50],["wimp",10],["bully",5]]);var s=new r(25,25,"golTerrarium",10,document.getElementById("gol"));s.populate([["GoL",100]]),c.draw(),s.draw(),n(function(){c.grid=c.step(),c.draw(),s.grid=s.step(),s.draw()},1e3),document.addEventListener("scroll",e)},{"../../app/terrarium.js":5,"../../bower_components/smooth-scroll.js/dist/js/bind-polyfill.min.js":8,"../../bower_components/smooth-scroll.js/dist/js/smooth-scroll.min.js":9,"./bugs.js":10}],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.metabolism=.7,t.prototype.size=50,t.prototype.speed=1,t.prototype.vision=1,t.prototype.sustainability=2,t.prototype.reproduceLv=.7,t.prototype.moveLv=.2,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,a=r.make(this.type),u=function(){return this.energy-=this.initialEnergy,!0}.bind(this),c=this.wait;return{x:i.x,y:i.y,creature:a,successFn:u,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,a=function(){var t=o.creature.energy*this.metabolism;return this.energy=this.energy+(t||-10),!1}.bind(this);return{x:i.x,y:i.y,creature:e,successFn:a}}return!1},t.prototype.wait=function(){return this.energy-=5,!0},t.prototype.queue=function(t){{var e={};this.maxEnergy}this.energy>this.maxEnergy*this.reproduceLv&&this.reproduce?e=this.reproduce(t):this.energy>this.moveLv&&this.move&&(e=this.move(t));var n=e.creature;return n?(n.successFn=e.successFn||n.wait,n.failureFn=e.failureFn||n.wait,{x:e.x,y:e.y,creature:n}):!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,a=r.color;return"string"==typeof i&&"undefined"==typeof e[i]&&"object"==typeof a&&3===a.length?(e[i]="function"==typeof o?function(){this.energy=this.initialEnergy,o.call(this)}:function(){this.energy=this.initialEnergy},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):!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.font="bold "+r+"px Arial",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
|