UNPKG

2.71 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return function (d, b) {
7 extendStatics(d, b);
8 function __() { this.constructor = d; }
9 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10 };
11})();
12Object.defineProperty(exports, "__esModule", { value: true });
13var p2_1 = require("p2");
14var Entity_1 = require("./../Entity");
15var _1 = require("./../Tool/");
16/**
17 * Module for wall tilemap
18 */
19var Wall = (function (_super) {
20 __extends(Wall, _super);
21 function Wall() {
22 return _super !== null && _super.apply(this, arguments) || this;
23 }
24 /* LIFECYCLE */
25 /**
26 * @initialize
27 * @override
28 */
29 Wall.prototype.initialize = function (props) {
30 this.setProps({
31 gravityFactor: 0,
32 box: _1.Enum.BOX.RECTANGLE,
33 type: _1.Enum.TYPE.STATIC,
34 group: _1.Enum.GROUP.GROUND
35 });
36 _super.prototype.initialize.call(this, props);
37 };
38 /* METHODS */
39 /**
40 * Know if the entity is constrained by the DirectionConstraint
41 * @param entity - The entity to check
42 * @returns If the entity is constrained by the DirectionConstraint
43 */
44 Wall.prototype.isConstrainedByDirection = function (entity) {
45 return !this.resolveDirectionConstraint(this.props.directionConstraint, this.props.x, this.props.y, this.props.width, this.props.height, entity);
46 };
47 /**
48 * resolve the direction by constraint
49 * @param directionConstraint - constraint of direction
50 * @param x - position x of the first shape
51 * @param y - position y of the first shape
52 * @param width - width of the first shape
53 * @param height - height of the first shape
54 * @param entity - entity to check
55 * @returns If true, the target is constrained by constraint direction of the wall
56 */
57 Wall.prototype.resolveDirectionConstraint = function (directionConstraint, x, y, width, height, entity) {
58 switch (directionConstraint) {
59 case "upper": return entity.props.y < y;
60 case "lower": return entity.last.y > entity.props.y && entity.props.y + entity.props.height > y && (entity.props.y + (entity.props.height / 2)) >= (y + height);
61 default: return true;
62 }
63 };
64 return Wall;
65}(Entity_1.Entity));
66/* STATICS */
67/**
68 * Default material for Wall
69 */
70Wall.wallMaterial = new p2_1.Material(Wall.generateId());
71exports.Wall = Wall;