Exemplo n.º 1
0
 function Elements() {
     Entity.call(this);
     
     this.maan  = new Sprite("images/element_maan.png");
     this.regen = new Sprite("images/element_regen.png");
     this.zon   = new Sprite("images/element_zon.png");
     this.lucht = new Sprite("images/element_lucht.png");
     
     this.maan.position.x = -150;
     this.maan.position.y = 100;
     
     this.regen.position.x = -102;
     this.regen.position.y = -152;
     
     this.zon.position.x = 150;
     this.zon.position.y = -100;
     
     this.lucht.position.x = 100;
     this.lucht.position.y = 150;
     
     this.elements = [
         this.maan,
         this.regen,
         this.zon,
         this.lucht
     ];
     
     this.elements.forEach(this.add.bind(this));
     
     this.rotationOffset = Math.PI / 3;
     
     this.rotation = 0;
 }
Exemplo n.º 2
0
    function World(w, h) {        
        Entity.call(this, 0, 0, w, h);
		
		this.bucketsize = new Vec2(0, 0);
		this.dimensions = new Vec2(0, 0);
		
		this.buckets = [];
		this.bycolor = {};
		
		this.pixelmap = new RawTexture("images/pixelmap.png", function(image) {
			var colors = image.asMatrix();
			
			var h = colors.r.numrows;
			var w = colors.r.numcolumns;
			
			this.bucketsize.x = this.width  / w;
			this.bucketsize.y = this.height / h * 0.5;
			
			console.log("Rows: " + colors.r.numrows);
			console.log("Columns: " + colors.r.numcolumns);
				
			var hsize = this.bucketsize.clone().scaleScalar(0.5);
			
			for(var row = 0; row < colors.r.numrows; ++row) {
				
				this.buckets.push([]);
				
				for(var col = 0; col < colors.r.numcolumns; ++col) {
					
					var r = colors.r.get(colors.r.numrows - row - 1, col);
					var g = colors.g.get(colors.r.numrows - row - 1, col);
					var b = colors.b.get(colors.r.numrows - row - 1, col);
					
					var color = "rgb(" + r + ", " + g + ", " + b + ")";
					
					this.buckets.last().push(new Bucket(
						col * this.bucketsize.x - this.hw + hsize.x,
						(row * this.bucketsize.y  + hsize.y),
						color
					));
					
					if( ! this.bycolor[color]) {
						this.bycolor[color] = [];
					}
					
					this.bycolor[color].push(this.buckets.last().last());
				}
			}
			
			console.log("Grid size: " + this.buckets.length + "x" + this.buckets[0].length);
			
			this.dimensions.x = this.buckets.length;
			this.dimensions.y = this.buckets[0].length;
		}.bind(this));
    }
Exemplo n.º 3
0
 function Boid(x, y) {
     Entity.call(this, x, y);
     
     
     this.outline = [
         new Vector(0, 20),
         new Vector(10, -20),
         new Vector(-10, -20)
     ];
     
     this.velocity = Random.Vector().scaleScalar(60); new Vector(0, 0);
 }
Exemplo n.º 4
0
	function Moveable(tile, world) {
        if(tile) {
    		Entity.call(this, tile.position.x, tile.position.y, 10, 10);

    		this.target = tile;
    		this.world  = world;

    		this.speed  = 80;

    		this.velocity = new V2(0, 0);
        }
	}
Exemplo n.º 5
0
 function Sprite(x, y, w, h, image) {
     
     if(typeof x == "string") {
         image = x;
         x = 0;
     } else if(typeof w == "string") {
         image = w;
         w = 0;
     } else if(typeof image == "string") {
         
     } else {
         throw new Error("Unknown arguments provided to constructor. " + 
                         "Try (x, y, w, h, image)");
     }
     
     Entity.call(this, x || 0, y || 0, w || 10, h || 10);
     
     this._texture = new Texture(image);
     
     // User provided texture size. No need to load.
     if(w && h) {
         this._isLoaded = true;
         
     // Retrieve width/height from texture:
     } else {
         this._isLoaded = false;
     }
             
     // Fading amount:
     this._opacityModifier = 0;
     
     this._slideModifier = 0;
     
     // Repeated fading?
     this._glow            = false;
     
     // Clipping values
     
     this._clipping = [0, 0, 0, 0];
     
     this._slide  = [0, 0, 0, 0];
     this._offset = [0, 0, 0, 0];
     
 }
Exemplo n.º 6
0
 function Sketch(x, y, w, h)  {
     Entity.call(this, x || 0, y || 0, w || 100, h || 100);
     
     this.enableEvent(Input.LEFT_DOWN, Input.RIGHT_DOWN, Input.LEFT_UP, Input.RIGHT_UP, Input.MOUSE_MOVE);
     
     this.isLeftDown  = false;        
     this.isRightDown = false;        
     this.cursor      = new Vector(0, 0);
     this.canvas      = null;
     this.radius      = 10;
     
     // Weird initial coordinates to force an update.
     this._canvasPosition = new Vector(Infinity, Infinity);
     
     this.lastDraw = new Vector(0, 0);
     
     
     this.min = new Vector(Infinity, Infinity);
     this.max = new Vector(-Infinity, -Infinity);
 }