update bird position when too far away
This commit is contained in:
@@ -208,6 +208,7 @@ void SwapAndPopObjectsArrayOnPointCollision(ObjectArray *objects, const Vector2
|
|||||||
void RenderObjectArray(const ObjectArray *objects);
|
void RenderObjectArray(const ObjectArray *objects);
|
||||||
|
|
||||||
Vector2 GetDirectionBetweenTwoVectors(Vector2 vec1, Vector2 vec2);
|
Vector2 GetDirectionBetweenTwoVectors(Vector2 vec1, Vector2 vec2);
|
||||||
|
float GetDistanceBetweenTwoVectors(Vector2 vec1, Vector2 vec2);
|
||||||
void UpdatePhysicsDirection(Vector2 *direction, Vector2 vector);
|
void UpdatePhysicsDirection(Vector2 *direction, Vector2 vector);
|
||||||
void UpdatePhysicsVelocity(Vector2 *velocity, Vector2 *direction, float *speed);
|
void UpdatePhysicsVelocity(Vector2 *velocity, Vector2 *direction, float *speed);
|
||||||
void UpdatePhysicsPosition(Vector2 *position, Vector2 *velocity);
|
void UpdatePhysicsPosition(Vector2 *position, Vector2 *velocity);
|
||||||
|
|||||||
+5
-2
@@ -37,7 +37,7 @@ Birds CreateBirds(void){
|
|||||||
Rectangle cameraRec = GetCameraRectangle();
|
Rectangle cameraRec = GetCameraRectangle();
|
||||||
|
|
||||||
birds.physics[i] = (Physics){
|
birds.physics[i] = (Physics){
|
||||||
.position = GetPositionOutsideRectangle(cameraRec, 1, 100),
|
.position = GetPositionOutsideRectangle(cameraRec, 100, 1000),
|
||||||
.direction = (Vector2){0.0f, 0.0f},
|
.direction = (Vector2){0.0f, 0.0f},
|
||||||
.speed = 5.0f
|
.speed = 5.0f
|
||||||
};
|
};
|
||||||
@@ -58,13 +58,16 @@ void UpdateBirds(Birds *birds){
|
|||||||
{
|
{
|
||||||
if(birds->arrived[i])
|
if(birds->arrived[i])
|
||||||
{
|
{
|
||||||
birds->destPos[i] = GetPositionOutsideRectangle(cameraRec, 1, 100);
|
birds->destPos[i] = GetPositionOutsideRectangle(cameraRec, 100, 1000);
|
||||||
birds->arrived[i] = false;
|
birds->arrived[i] = false;
|
||||||
}
|
}
|
||||||
if(CheckCollisionPointCircle(birds->physics[i].position, birds->destPos[i], 10.0F))
|
if(CheckCollisionPointCircle(birds->physics[i].position, birds->destPos[i], 10.0F))
|
||||||
{
|
{
|
||||||
birds->arrived[i] = true;
|
birds->arrived[i] = true;
|
||||||
}
|
}
|
||||||
|
if(GetDistanceBetweenTwoVectors(birds->physics[i].position, camera->target) > 1000){
|
||||||
|
birds->physics[i].position = GetPositionOutsideRectangle(cameraRec, 100, 1000);
|
||||||
|
}
|
||||||
Vector2 dir = GetDirectionBetweenTwoVectors(birds->physics[i].position, birds->destPos[i]);
|
Vector2 dir = GetDirectionBetweenTwoVectors(birds->physics[i].position, birds->destPos[i]);
|
||||||
UpdatePhysics(&birds->physics[i], dir);
|
UpdatePhysics(&birds->physics[i], dir);
|
||||||
printf("birdsPos: %f, %f", birds->physics[i].position.x, birds->physics[i].position.y);
|
printf("birdsPos: %f, %f", birds->physics[i].position.x, birds->physics[i].position.y);
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ Vector2 GetDirectionBetweenTwoVectors(Vector2 vec1, Vector2 vec2)
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float GetDistanceBetweenTwoVectors(Vector2 vec1, Vector2 vec2)
|
||||||
|
{
|
||||||
|
float dx = vec1.x - vec2.x;
|
||||||
|
float dy = vec1.y - vec2.y;
|
||||||
|
return sqrtf(dx * dx + dy * dy);
|
||||||
|
}
|
||||||
|
|
||||||
void UpdatePhysicsDirection(Vector2 *direction, Vector2 vector)
|
void UpdatePhysicsDirection(Vector2 *direction, Vector2 vector)
|
||||||
{
|
{
|
||||||
*direction = Vector2Normalize(vector);
|
*direction = Vector2Normalize(vector);
|
||||||
|
|||||||
Reference in New Issue
Block a user