GameScreen.GetEntitiesUnderPoint: Entity picking
This commit is contained in:
@@ -68,22 +68,20 @@ GameScreen.prototype = {
|
||||
Update: function(){
|
||||
for(var i=0,n=this.Entities.length;i<n;i++){
|
||||
var entity = this.Entities[i];
|
||||
if(!entity.GameEntity.Deleted){
|
||||
if(entity.GameEntity.Deleted){ continue; }
|
||||
entity.GameEntity.Update();
|
||||
if(entity.Update){
|
||||
entity.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Draw: function(factor){
|
||||
this.Ctx.clearRect(0, 0, this.Size.X, this.Size.Y);
|
||||
for(var i=0,n=this.Entities.length;i<n;i++){
|
||||
var entity = this.Entities[i];
|
||||
if(!entity.GameEntity.Deleted){
|
||||
if(entity.GameEntity.Deleted){ continue; }
|
||||
entity.GameEntity.Draw(factor);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// For public use
|
||||
@@ -102,6 +100,20 @@ GameScreen.prototype = {
|
||||
AddEntity: function(newEntity){
|
||||
this.NewEntities.push(newEntity);
|
||||
},
|
||||
GetEntitiesUnderPoint: function(point, type){
|
||||
var entities = [];
|
||||
for(var i=0,n=this.Entities.length;i<n;i++){
|
||||
var entity = this.Entities[i];
|
||||
if(entity.GameEntity.Deleted){ continue; }
|
||||
if(type){
|
||||
if(entity.GameEntity.Type!==type){ continue; }
|
||||
}
|
||||
if(entity.GameEntity.IntersectPoint(point)){
|
||||
entities.push(entity);
|
||||
}
|
||||
}
|
||||
return entities;
|
||||
},
|
||||
Debug: false
|
||||
};
|
||||
|
||||
@@ -155,6 +167,15 @@ GameEntity.prototype = {
|
||||
Delete: function(){
|
||||
this.Deleted = true;
|
||||
},
|
||||
IntersectPoint: function(point){
|
||||
return (
|
||||
point.X < (this.PositionDest.X + (this.Size.X/2)) &&
|
||||
point.X > (this.PositionDest.X - (this.Size.X/2)) &&
|
||||
point.Y < (this.PositionDest.Y + (this.Size.Y/2)) &&
|
||||
point.Y > (this.PositionDest.Y - (this.Size.Y/2)) &&
|
||||
true
|
||||
);
|
||||
},
|
||||
Debug: false
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user