GameLib_EntityCustomCheckCollision: Función para hacer pruebas de colisiones de una entidad con vector velocidad diferente
This commit is contained in:
@@ -644,10 +644,6 @@ void Entity_CollisionResponseLine(
|
|||||||
vec2 pos2,vel2,velFric,intersection;
|
vec2 pos2,vel2,velFric,intersection;
|
||||||
float dist,fric_static,fric_dynamic,fricLen;
|
float dist,fric_static,fric_dynamic,fricLen;
|
||||||
|
|
||||||
// Calculate friction
|
|
||||||
fric_static=(ent->fric_static+ent2->fric_static)/2;
|
|
||||||
fric_dynamic=(ent->fric_dynamic+ent2->fric_dynamic)/2;
|
|
||||||
|
|
||||||
// Calculate end position
|
// Calculate end position
|
||||||
vec2_scale(vel2,ent->vel,1.0f-t);
|
vec2_scale(vel2,ent->vel,1.0f-t);
|
||||||
dist=-vec2_dot(norm,vel2);
|
dist=-vec2_dot(norm,vel2);
|
||||||
@@ -658,6 +654,10 @@ void Entity_CollisionResponseLine(
|
|||||||
vec2_scaleadd(intersection,ent->pos,ent->vel,t);
|
vec2_scaleadd(intersection,ent->pos,ent->vel,t);
|
||||||
|
|
||||||
if(applyFriction){
|
if(applyFriction){
|
||||||
|
// Calculate friction
|
||||||
|
fric_static=(ent->fric_static+ent2->fric_static)/2;
|
||||||
|
fric_dynamic=(ent->fric_dynamic+ent2->fric_dynamic)/2;
|
||||||
|
|
||||||
// Apply friction
|
// Apply friction
|
||||||
vec2_minus(velFric,pos2,intersection);
|
vec2_minus(velFric,pos2,intersection);
|
||||||
fricLen=sqrtf(vec2_dot(velFric,velFric));
|
fricLen=sqrtf(vec2_dot(velFric,velFric));
|
||||||
|
|||||||
@@ -529,6 +529,41 @@ Entity GameLib_SearchEnt(int (*func)(Entity ent,void *d),void *d){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// GameLib_EntityCustomCheckCollision
|
||||||
|
//
|
||||||
|
//
|
||||||
|
int GameLib_EntityCustomCheckCollision(Entity ent,vec2 vel){
|
||||||
|
int collision=0;
|
||||||
|
CollisionInfo collInfo=NULL;
|
||||||
|
vec2 originalVel;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
vec2_copy(originalVel,ent->vel);
|
||||||
|
vec2_copy(ent->vel,vel);
|
||||||
|
Entity_CalcBBox(ent);
|
||||||
|
|
||||||
|
for(j=0;j<_n_entities;j++){
|
||||||
|
if(!(_entity[j]->flags&EntityFlag_Collision) ||
|
||||||
|
!Entity_BBoxIntersect(ent,_entity[j]))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Entity_CheckCollision(ent,_entity[j],&collInfo);
|
||||||
|
if(collInfo!=NULL){
|
||||||
|
collision=1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2_copy(ent->vel,originalVel);
|
||||||
|
Entity_CalcBBox(ent);
|
||||||
|
|
||||||
|
CollisionInfo_Destroy(&collInfo);
|
||||||
|
return collision;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// GameLib_PlaySound
|
// GameLib_PlaySound
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -94,6 +94,13 @@ void GameLib_ForEachEnt(int (*func)(Entity ent));
|
|||||||
Entity GameLib_SearchEnt(int (*func)(Entity ent,void *d),void *d);
|
Entity GameLib_SearchEnt(int (*func)(Entity ent,void *d),void *d);
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// GameLib_EntityCustomCheckCollision
|
||||||
|
//
|
||||||
|
//
|
||||||
|
int GameLib_EntityCustomCheckCollision(Entity ent,vec2 vel);
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// GameLib_PlaySound
|
// GameLib_PlaySound
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user