-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.js
More file actions
29 lines (29 loc) · 812 Bytes
/
entity.js
File metadata and controls
29 lines (29 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
window.Entity = {
clone: function(entity) {
var newEntity;
newEntity = {};
// doesn't do deep clone.
Object.keys(entity).forEach(function(key) {
newEntity[key] = entity[key];
});
return newEntity;
},
getTop: function(entity) {
return entity.y + entity.height / 2;
},
getBottom: function(entity) {
return entity.y - entity.height / 2;
},
getRight: function(entity) {
return entity.x + entity.width / 2;
},
getLeft: function(entity) {
return entity.x - entity.width / 2;
},
overlapsEntity: function(entity, otherEntity) {
return Entity.getRight(entity) > Entity.getLeft(otherEntity) &&
Entity.getLeft(entity) < Entity.getRight(otherEntity) &&
Entity.getTop(entity) > Entity.getBottom(otherEntity) &&
Entity.getBottom(entity) < Entity.getTop(otherEntity);
}
};