UNPKG

@fuwu-yuan/bgew

Version:

Baguette Game Engine Web is a french 2D Web game engine

81 lines (80 loc) 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Line = void 0; const entity_1 = require("../entity"); const collisionSystem_1 = require("../../collisionSystem"); class Line extends entity_1.Entity { constructor(x1, y1, x2, y2, color = null) { super(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2 - x1), Math.abs(y2 - y1)); this._color = "rgba(0,0,0, 1.0)"; this._x1 = x1; this._x2 = x2; this._y1 = y1; this._y2 = y2; if (color) { this._color = color; } this._length = Math.sqrt(Math.pow(Math.abs(x2 - x1), 2) + Math.pow(Math.abs(y2 - y1), 2)); } init(board) { this.board = board; this._body = new collisionSystem_1.Polygon(this, this.parent ? this.parent.absX : 0, this.parent ? this.parent.absY : 0, [[this.x1, this.y1], [this.x2, this.y2]]); if (this.board.collisionSystem) { this.board.collisionSystem.insert(this.body); } } draw(ctx) { super.draw(ctx); ctx.strokeStyle = this.color; //draw line let path = this.getPath2D(); ctx.stroke(path); } getPath2D() { let path = new Path2D(); path.moveTo(this.x1, this.y1); path.lineTo(this.x2, this.y2); path.closePath(); return path; } update(delta) { super.update(delta); } /********************* * Getters & Setters * *********************/ get color() { return this._color; } set color(value) { this._color = value; } get x1() { return this._x1; } set x1(value) { this._x1 = value; } get x2() { return this._x2; } set x2(value) { this._x2 = value; } get y1() { return this._y1; } set y1(value) { this._y1 = value; } get y2() { return this._y2; } set y2(value) { this._y2 = value; } get length() { return this._length; } } exports.Line = Line;