UNPKG

@tdurtschi/bug

Version:

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

73 lines 2.9 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GroundWalk = void 0; var BugBehavior_1 = require("./BugBehavior"); var bug_1 = __importDefault(require("../bug")); var walk_1 = require("./walk"); var plant_1 = __importDefault(require("../../plant/plant")); var turnAround_1 = require("./turnAround"); var Victor = require("victor"); var climb_1 = require("./climb"); var wall_1 = __importDefault(require("../../wall/wall")); var GroundWalk = (function (_super) { __extends(GroundWalk, _super); function GroundWalk(bug, countdown) { if (countdown === void 0) { countdown = 1; } var _this = _super.call(this, bug) || this; _this.countdown = countdown; return _this; } GroundWalk.prototype.do = function (inputs) { if (inputs.find(function (input) { return input instanceof plant_1.default; }) && this.bug.bugInstinct.WillClimb) { var plant = inputs.find(function (input) { return input instanceof plant_1.default; }); beginClimbing(this.bug, plant); } else if (inputs && inputs.find(function (i) { return i instanceof wall_1.default; })) { new turnAround_1.TurnAround(this.bug).do(); } else if (inputs && inputs.find(function (i) { return i instanceof bug_1.default; })) { new turnAround_1.TurnAround(this.bug).do(); } else { walk_1.walk(this.bug); } this.countDown(); }; GroundWalk.prototype.countDown = function () { this.countdown--; if (this.countdown == 0) { this.bug.finishBehavior(); } }; return GroundWalk; }(BugBehavior_1.BugBehavior)); exports.GroundWalk = GroundWalk; var beginClimbing = function (bug, tree) { bug.direction = tree.graph.node.clone().norm(); bug.pos = new Victor(tree.pos.x, 0).add(bug.direction.clone().multiplyScalar(bug.size.x)); bug.climbingOn = { plant: tree, branch: tree.graph, }; bug.zIndexChanged.next(); bug.finishBehavior(); bug.queueBehavior(new climb_1.Climb(bug)); }; //# sourceMappingURL=GroundWalk.js.map