UNPKG

react-simple-game-engine

Version:

[WIP] not able to use in currently. <!-- Document cumming soon... -->

99 lines (98 loc) 4.05 kB
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import p5 from "p5"; import { copyProperties } from "../utils"; import { Particle } from "./particle"; import { EntitySuit } from "./entities/entity-suit"; var ParticleSystem = /** @class */ (function (_super) { __extends(ParticleSystem, _super); function ParticleSystem() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.particles = []; _this.forces = []; _this.particleOptions = { x: 0, y: 0, }; _this.particleClass = Particle; _this.quantityPerFrame = 50; _this.vecWeight = 5; return _this; } ParticleSystem.prototype.initial = function (_a) { var _b; var forces = _a.forces, _c = _a.particleOptions, particleOptions = _c === void 0 ? {} : _c, params = __rest(_a, ["forces", "particleOptions"]); copyProperties(this.particleOptions, particleOptions); copyProperties(this, params); if (forces) { (_b = this.forces).push.apply(_b, forces); } }; ParticleSystem.prototype.update = function () { var ParticleClass = this.particleClass; var _a = this.particleOptions, x = _a.x, y = _a.y, particleOptions = __rest(_a, ["x", "y"]); for (var _i = 0, _b = Array.from({ length: this.quantityPerFrame }); _i < _b.length; _i++) { var _ = _b[_i]; var p = new ParticleClass(x, y); var vec = p5.Vector.random2D(); vec.mult(Renderer.random(this.vecWeight)); var angle = Renderer.random(Renderer.TWO_PI); p.initial(__assign(__assign({}, particleOptions), { simpleCamera: this.simpleCamera, vec: vec, angle: angle })); this.particles.push(p); } for (var i = this.particles.length - 1; i > -1; i--) { var p = this.particles[i]; for (var _c = 0, _d = this.forces; _c < _d.length; _c++) { var force = _d[_c]; p.applyForce(force); } p.update(); if (p.isDead()) { this.particles.splice(i, 1); } } }; ParticleSystem.prototype.draw = function () { for (var _i = 0, _a = this.particles; _i < _a.length; _i++) { var particle = _a[_i]; particle.draw(); } }; return ParticleSystem; }(EntitySuit)); export { ParticleSystem };