GameScreen.GetEntitiesUnderPoint: Entity picking
This commit is contained in:
@@ -68,11 +68,10 @@ GameScreen.prototype = {
|
|||||||
Update: function(){
|
Update: function(){
|
||||||
for(var i=0,n=this.Entities.length;i<n;i++){
|
for(var i=0,n=this.Entities.length;i<n;i++){
|
||||||
var entity = this.Entities[i];
|
var entity = this.Entities[i];
|
||||||
if(!entity.GameEntity.Deleted){
|
if(entity.GameEntity.Deleted){ continue; }
|
||||||
entity.GameEntity.Update();
|
entity.GameEntity.Update();
|
||||||
if(entity.Update){
|
if(entity.Update){
|
||||||
entity.Update();
|
entity.Update();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -80,9 +79,8 @@ GameScreen.prototype = {
|
|||||||
this.Ctx.clearRect(0, 0, this.Size.X, this.Size.Y);
|
this.Ctx.clearRect(0, 0, this.Size.X, this.Size.Y);
|
||||||
for(var i=0,n=this.Entities.length;i<n;i++){
|
for(var i=0,n=this.Entities.length;i<n;i++){
|
||||||
var entity = this.Entities[i];
|
var entity = this.Entities[i];
|
||||||
if(!entity.GameEntity.Deleted){
|
if(entity.GameEntity.Deleted){ continue; }
|
||||||
entity.GameEntity.Draw(factor);
|
entity.GameEntity.Draw(factor);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -102,6 +100,20 @@ GameScreen.prototype = {
|
|||||||
AddEntity: function(newEntity){
|
AddEntity: function(newEntity){
|
||||||
this.NewEntities.push(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
|
Debug: false
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -155,6 +167,15 @@ GameEntity.prototype = {
|
|||||||
Delete: function(){
|
Delete: function(){
|
||||||
this.Deleted = true;
|
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
|
Debug: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user