aboutsummaryrefslogtreecommitdiff
path: root/examples/physics_rigidbody_force.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/physics_rigidbody_force.c')
-rw-r--r--examples/physics_rigidbody_force.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/examples/physics_rigidbody_force.c b/examples/physics_rigidbody_force.c
index 3ac560c5..74a88a97 100644
--- a/examples/physics_rigidbody_force.c
+++ b/examples/physics_rigidbody_force.c
@@ -2,10 +2,10 @@
*
* raylib [physac] physics example - Rigidbody forces
*
-* This example has been created using raylib 1.3 (www.raylib.com)
+* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@@ -26,15 +26,9 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [physics] example - rigidbodies forces");
- InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024)
+ InitPhysics(MAX_OBJECTS + 1); // Initialize physics system with maximum physic objects
- // Physics initialization
- Physics worldPhysics = {true, false, (Vector2){0, -9.81f}};
-
- // Set internal physics settings
- SetPhysics(worldPhysics);
-
- // Objects initialization
+ // Physic Objects initialization
Transform objects[MAX_OBJECTS];
for (int i = 0; i < MAX_OBJECTS; i++)
@@ -49,6 +43,8 @@ int main()
Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}};
AddCollider(MAX_OBJECTS, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0});
+ bool physicsDebug = false;
+
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -72,14 +68,7 @@ int main()
}
// Check debug mode toggle button input
- if (IsKeyPressed(KEY_P))
- {
- // Update program physics value
- worldPhysics.debug = !worldPhysics.debug;
-
- // Update internal physics value
- SetPhysics(worldPhysics);
- }
+ if (IsKeyPressed(KEY_P)) physicsDebug = !physicsDebug;
//----------------------------------------------------------------------------------
// Draw
@@ -89,10 +78,10 @@ int main()
ClearBackground(RAYWHITE);
// Check if debug mode is enabled
- if (worldPhysics.debug)
+ if (physicsDebug)
{
// Draw every internal physics stored collider if it is active (floor included)
- for (int i = 0; i < MAX_OBJECTS + 1; i++)
+ for (int i = 0; i < MAX_OBJECTS; i++)
{
if (GetCollider(i).enabled)
{
@@ -136,7 +125,9 @@ int main()
}
// De-Initialization
- //--------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
+ UnloadPhysics(); // Unload physic objects
+
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------