UNPKG

@tdurtschi/bug

Version:

Bug is a simulation that models a weevil walking around in an HTML canvas.

33 lines 1.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var victor_1 = __importDefault(require("victor")); var stats_1 = require("../../util/stats"); var jade_1 = require("./jade/jade"); var PlantFactory = (function () { function PlantFactory(generateId, width) { this.generateId = generateId; this.width = width; this.plantPosCursor = this.randomX(); } PlantFactory.prototype.build = function (initialState) { var newState = Object.assign({ pos: this.getNextPos(), }, initialState); return new jade_1.Jade(this.generateId(), newState); }; PlantFactory.prototype.getNextPos = function () { this.plantPosCursor.x = (this.plantPosCursor.x + stats_1.randInt(this.width / 2, this.width / 3)) % this.width; return this.plantPosCursor.clone(); }; PlantFactory.prototype.randomX = function () { return new victor_1.default(Math.floor(Math.random() * this.width - 40), 0); }; return PlantFactory; }()); exports.default = PlantFactory; //# sourceMappingURL=plantFactory.js.map