UNPKG

@tdurtschi/bug

Version:

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

39 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var stats_1 = require("../../../util/stats"); var pause_1 = require("../../../entities/bug/behaviors/pause"); var FRAMES_BETWEEN_STEPS = 25; var BugUI = (function () { function BugUI(id, bug) { this.id = id; this.bug = bug; this.frame = 0; this.imageIdx = 0; this.randomOffset = stats_1.randInt(0, 15); } BugUI.prototype.getImage = function () { return BugUI.images[this.imageIdx]; }; BugUI.prototype.update = function () { if (this.bug.behaviorQueue[0] && !(this.bug.behaviorQueue[0] instanceof pause_1.Pause)) { if ((this.frame++ + this.randomOffset) % FRAMES_BETWEEN_STEPS == 0) { this.imageIdx = (this.imageIdx + 1) % 2; } } }; BugUI.getBugImages = function () { var weevil1 = require("./weevil1.png").default; var weevil2 = require("./weevil2.png").default; var images = [ new Image(), new Image(), ]; images[0].src = weevil1; images[1].src = weevil2; return images; }; BugUI.images = BugUI.getBugImages(); return BugUI; }()); exports.default = BugUI; //# sourceMappingURL=bug-ui.js.map