1 /** 2 * @class object2d 3 * @extends component 4 * @description 5 * A component that gives movement and collision-detection 6 * related attributes to an Entity in 2D space 7 * 8 * Known {@link component} events:</br> 9 * <pre> 10 * - on-move: Called 11 * - on-collide: 12 * </pre> 13 * 14 */ 15 function object2d() { 16 17 /** 18 * Compounds a velocity vector with the current velocity 19 * @param {Number} factor The velocity amount to add. Can be negative. 20 * @param {Number} direction The direction to apply the velocity in degrees. 21 */ 22 this.addVelocity = function(){}; 23 24 /** 25 * Compounds a velocity vector with the current velocity towards a point. 26 * @param {Number} factor The velocity amount to add. Can be negative. 27 * @param {vector} target The point to add velocity towards 28 */ 29 this.addVelocityTowards = function(){}; 30 31 32 /** 33 * Sets the velocity vector of an object. 34 * @param {Number} factor The velocity to set. 35 * @param {Number} direction The direction to set the velocity in degrees. 36 */ 37 this.setVelocity = function(){}; 38 39 /** 40 * Sets the velocity vector of an object. 41 * @param {Number} factor The velocity to set. 42 * @param {vector} target The point to set velocity towards 43 */ 44 this.setVelocityTowards = function(){}; 45 46 47 /** 48 * Reduces the speed of the Entity to 0. 49 */ 50 this.halt = function(){}; 51 52 /** 53 * Stops continuous motion consideration for the collider for the next frame. 54 */ 55 this.ResetMotion = function(){}; 56 57 /** 58 * Enables collisions between the given groups. By default, all groups can collide 59 * with all other groups, including itself. 60 * @param {Number} src Group in question 61 * @param {Number} dest Group to collide with in future collisions 62 */ 63 this.enableGroupInteraction = function(){}; 64 65 /** 66 * Disables collisions between the given groups. 67 * @param {Number} src Group in question 68 * @param {Number} dest Group to prevent collisions with in future collisions 69 */ 70 this.disableGroupInteraction = function(){}; 71 72 73 74 75 76 /** 77 * Sets the amount of resistance to speed measured as a percentile. 78 * 79 * Every frame, only the amount percent of the host Entity's velocity is retained. For example, 80 * if amt is specified to be .95, every frame 5% of the Entity's speed will be lost. 81 * This is applied in the horizontal direction. 82 * @type {Number} 83 */ 84 this.frictionX = 0.0; 85 86 /** 87 * Same as frinctionX, but is applied in the vertical direction. 88 * @type {Number} 89 */ 90 this.frictionY = 0.0; 91 92 /** 93 * Returns the speed of the object. 94 * @type {Number} 95 */ 96 this.speed = 0.0; 97 98 /** 99 * Returns the direction that the obejct is traveling in degress. 100 * @type {Number} 101 */ 102 this.direction = 0.0; 103 104 105 106 /** 107 * Horizontal velocity of the object. 108 * @type {Number} 109 */ 110 this.velocityX = 0.0; 111 112 /** 113 * Vertical velocity of the object. 114 * @type {Number} 115 */ 116 this.velocityY = 0.0; 117 118 119 /** 120 * When set, redefines the collider 121 * for the object. The array should be pairs of xy values 122 * to define the colled polygon object. 123 * @type {Array} 124 */ 125 this.collider = 0.0; 126 127 128 /** 129 * Returns the entity that this object last collided with. 130 * @type {entity} 131 */ 132 this.lastCollided = {}; 133 134 135 /** 136 * Based on the objects current velocity, returns the position that will be used 137 * as the new position next frame. Note that if the object moves by other means 138 * (i.e. the host's node is modified), the nextPosition will also change. 139 * @type {vector} 140 */ 141 this.nextPosition = {}; 142 143 /** 144 * Returns the previous position that was used before the current position 145 * when this object2d was attached. 146 * @type {vector} 147 */ 148 this.lastPosition = {}; 149 150 /** 151 * Sets/Gets the collision group. Groups can be used to ignore sets of object2D colliders 152 * efficently before collisions are processed. The default for all groups is sandboxe.object2d.group.a) 153 * @type {Number} 154 */ 155 this.group = 0; 156 157 158 159 160 161 162 return this; 163 } 164