summaryrefslogtreecommitdiffhomepage
path: root/examples/src/physac/physics_shatter.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/src/physac/physics_shatter.c')
-rw-r--r--examples/src/physac/physics_shatter.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/examples/src/physac/physics_shatter.c b/examples/src/physac/physics_shatter.c
index 6b474cd..7478522 100644
--- a/examples/src/physac/physics_shatter.c
+++ b/examples/src/physac/physics_shatter.c
@@ -7,17 +7,19 @@
*
* Use the following line to compile:
*
-* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread
-* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
+* gcc -o $(NAME_PART).exe $(FILE_NAME) -s -static /
+* -lraylib -lpthread -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm /
+* -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
*
-* Copyright (c) 2017 Victor Fisac
+* Copyright (c) 2016-2018 Victor Fisac
*
********************************************************************************************/
#include "raylib.h"
#define PHYSAC_IMPLEMENTATION
-#include "physac.h"
+#define PHYSAC_NO_THREADS
+#include "physac.h"
int main()
{
@@ -32,14 +34,15 @@ int main()
// Physac logo drawing position
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
int logoY = 15;
+ bool needsReset = false;
// Initialize physics and default physics bodies
InitPhysics();
SetPhysicsGravity(0, 0);
// Create random polygon physics body to shatter
- PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
-
+ CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
+
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -47,13 +50,21 @@ int main()
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
+ RunPhysicsStep();
+
//----------------------------------------------------------------------------------
+ // Delay initialization of variables due to physics reset asynchronous
+ if (needsReset)
+ {
+ // Create random polygon physics body to shatter
+ CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
+ needsReset = false;
+ }
+
if (IsKeyPressed('R')) // Reset physics input
{
ResetPhysics();
-
- // Create random polygon physics body to shatter
- body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
+ needsReset = true;
}
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input
@@ -112,4 +123,3 @@ int main()
return 0;
}
-