Beispiel #1
0
	Builder.prototype.displayingUpdate = function(elapsed) {
	    if(this.menu.width < menuWidth) {
	        this.menu.width = this.menu.grow(elapsed);
	    }

	    if(input.state.hasPointer) {
	        var origin = this.camera.project(this.cell);
	        if(geo.lengthSquared(input.state, origin) > (menuWidth * menuWidth)) {
	            this.state = 'dismissing';
	            this.menu.shrink = tween(this.menu.width, 0, 300, tween.smooth);
	        } else {
	            var v = vector(origin, input.state);
	            var third = Math.PI * 2 / 3;
	            var entityType;

	            var a = v.angle() - Math.PI; // off by 180 from the canvas arc()
	            if(a < 0) a = (2 * Math.PI) + a; // normalize negative angles
	            if(a < third) {
	                entityType = Generator;
	            } else if(a < 2 * third) {
	                entityType = Miner;
	            } else if(a < 3 * third) {
	                entityType = Turret;
	            } else {
	                throw new Error('?');
	            }

	            if(!entityType.cost) throw new Error('no cost for unit: ' + entityType);

	            if(this.level.money < entityType.cost) return;

	            this.level.money -= entityType.cost;

	            var entity = new entityType();
	            entity.hydrate({
	                x: this.cell.x,
	                y: this.cell.y,
	                context: this.level
	            });

	            this.gameObjects.friendlies.push(entity);

	            this.state = 'dismissing';
	            this.menu.shrink = tween(this.menu.width, 0, 300, tween.smooth);
	        }
	    }
	};
Beispiel #2
0
	Builder.prototype.idleUpdate = function(elapsed) {

	    if(!input.state.handled && input.state.hasPointer && input.state.pointers.length === 1) {

	        var worldCoords = this.camera.toWorldSpace(input.state);
	        worldCoords.x = Math.round(worldCoords.x);
	        worldCoords.y = Math.round(worldCoords.y);

	        if(isInGameBounds(worldCoords)) {
	            this.cell = worldCoords;
	            this.state = 'scanning';
	            this.menu.grow = tween(0, menuWidth, 300, tween.smooth);

	            input.state.handled = true;
	        }

	    }
	};