diff options
| author | Ray <[email protected]> | 2018-03-11 10:51:15 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-03-11 10:51:15 +0100 |
| commit | 8bc2813b0cbb016206708c41762a2fe3f01d5a13 (patch) | |
| tree | 15988f25f4f8da3ce7540be8e2ef1d27ce48ac7a /examples/physac/physics_shatter.c | |
| parent | a0127d83002c2462bc4e83715c1dcb0bf99796ca (diff) | |
| parent | 5b4197afebe29bdd9795507d440d048bb8cb7c0b (diff) | |
| download | raylib-8bc2813b0cbb016206708c41762a2fe3f01d5a13.tar.gz raylib-8bc2813b0cbb016206708c41762a2fe3f01d5a13.zip | |
Merge pull request #500 from victorfisac/fork/master
[fork/master] Fixed some memory leaks and add null checks for consistency
Diffstat (limited to 'examples/physac/physics_shatter.c')
| -rw-r--r-- | examples/physac/physics_shatter.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/examples/physac/physics_shatter.c b/examples/physac/physics_shatter.c index 6b474cd3..19c3cb6d 100644 --- a/examples/physac/physics_shatter.c +++ b/examples/physac/physics_shatter.c @@ -10,7 +10,7 @@ * 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 * -* Copyright (c) 2017 Victor Fisac +* Copyright (c) 2016-2018 Victor Fisac * ********************************************************************************************/ @@ -32,6 +32,7 @@ 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(); @@ -48,14 +49,19 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsKeyPressed('R')) // Reset physics input + // Delay initialization of variables due to physics reset asynchronous + if (needsReset) { - ResetPhysics(); - // Create random polygon physics body to shatter body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); } + if (IsKeyPressed('R')) // Reset physics input + { + ResetPhysics(); + needsReset = true; + } + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input { // Note: some values need to be stored in variables due to asynchronous changes during main thread |
