Some formatting tweaks

This commit is contained in:
raysan5 2016-01-20 19:09:48 +01:00
parent 51c0b61a43
commit c5663ca015
5 changed files with 42 additions and 36 deletions

View file

@ -32,7 +32,7 @@ int main()
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [physics] example - basic rigidbody"); InitWindow(screenWidth, screenHeight, "raylib [physics] example - basic rigidbody");
SetTargetFPS(60); // Enable v-sync
InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024) InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024)
// Physics initialization // Physics initialization
@ -43,17 +43,19 @@ int main()
// Object initialization // Object initialization
Transform player = (Transform){(Vector2){(screenWidth - OBJECT_SIZE) / 2, (screenHeight - OBJECT_SIZE) / 2}, 0.0f, (Vector2){OBJECT_SIZE, OBJECT_SIZE}}; Transform player = (Transform){(Vector2){(screenWidth - OBJECT_SIZE) / 2, (screenHeight - OBJECT_SIZE) / 2}, 0.0f, (Vector2){OBJECT_SIZE, OBJECT_SIZE}};
AddCollider(PLAYER_INDEX, (Collider){true, RectangleCollider, (Rectangle){player.position.x, player.position.y, player.scale.x, player.scale.y}, 0}); AddCollider(PLAYER_INDEX, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){player.position.x, player.position.y, player.scale.x, player.scale.y}, 0});
AddRigidbody(PLAYER_INDEX, (Rigidbody){true, 1.0f, (Vector2){0, 0}, (Vector2){0, 0}, false, false, true, 0.5f, 1.0f}); AddRigidbody(PLAYER_INDEX, (Rigidbody){true, 1.0f, (Vector2){0, 0}, (Vector2){0, 0}, false, false, true, 0.5f, 1.0f});
// Floor initialization // Floor initialization
// NOTE: floor doesn't need a rigidbody because it's a static physic object, just a collider to collide with other dynamic colliders (with rigidbody) // NOTE: floor doesn't need a rigidbody because it's a static physic object, just a collider to collide with other dynamic colliders (with rigidbody)
Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}}; Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}};
AddCollider(PLAYER_INDEX + 1, (Collider){true, RectangleCollider, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0}); AddCollider(PLAYER_INDEX + 1, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0});
// Object properties initialization // Object properties initialization
float moveSpeed = 6.0f; float moveSpeed = 6.0f;
float jumpForce = 4.5f; float jumpForce = 5.0f;
SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop

View file

@ -25,7 +25,7 @@ int main()
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [physics] example - rigidbodies forces"); InitWindow(screenWidth, screenHeight, "raylib [physics] example - rigidbodies forces");
SetTargetFPS(60); // Enable v-sync
InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024) InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024)
// Physics initialization // Physics initialization
@ -36,17 +36,20 @@ int main()
// Objects initialization // Objects initialization
Transform objects[MAX_OBJECTS]; Transform objects[MAX_OBJECTS];
for (int i = 0; i < MAX_OBJECTS; i++) for (int i = 0; i < MAX_OBJECTS; i++)
{ {
objects[i] = (Transform){(Vector2){75 + OBJECTS_OFFSET * i, (screenHeight - 50) / 2}, 0.0f, (Vector2){50, 50}}; objects[i] = (Transform){(Vector2){75 + OBJECTS_OFFSET * i, (screenHeight - 50) / 2}, 0.0f, (Vector2){50, 50}};
AddCollider(i, (Collider){true, RectangleCollider, (Rectangle){objects[i].position.x, objects[i].position.y, objects[i].scale.x, objects[i].scale.y}, 0}); AddCollider(i, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){objects[i].position.x, objects[i].position.y, objects[i].scale.x, objects[i].scale.y}, 0});
AddRigidbody(i, (Rigidbody){true, 1.0f, (Vector2){0, 0}, (Vector2){0, 0}, false, false, true, 0.5f, 0.5f}); AddRigidbody(i, (Rigidbody){true, 1.0f, (Vector2){0, 0}, (Vector2){0, 0}, false, false, true, 0.5f, 0.5f});
} }
// Floor initialization // Floor initialization
// NOTE: floor doesn't need a rigidbody because it's a static physic object, just a collider to collide with other dynamic colliders (with rigidbody) // NOTE: floor doesn't need a rigidbody because it's a static physic object, just a collider to collide with other dynamic colliders (with rigidbody)
Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}}; Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}};
AddCollider(MAX_OBJECTS, (Collider){true, RectangleCollider, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0}); AddCollider(MAX_OBJECTS, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0});
SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop

View file

@ -183,9 +183,9 @@ void ApplyPhysics(int index, Vector2 *position)
{ {
if (colliders[index].enabled && colliders[j].enabled) if (colliders[index].enabled && colliders[j].enabled)
{ {
if (colliders[index].type == RectangleCollider) if (colliders[index].type == COLLIDER_RECTANGLE)
{ {
if (colliders[j].type == RectangleCollider) if (colliders[j].type == COLLIDER_RECTANGLE)
{ {
if (CheckCollisionRecs(colliders[index].bounds, colliders[j].bounds)) if (CheckCollisionRecs(colliders[index].bounds, colliders[j].bounds))
{ {
@ -207,7 +207,7 @@ void ApplyPhysics(int index, Vector2 *position)
} }
else else
{ {
if (colliders[j].type == RectangleCollider) if (colliders[j].type == COLLIDER_RECTANGLE)
{ {
if (CheckCollisionCircleRec((Vector2){colliders[index].bounds.x, colliders[index].bounds.y}, colliders[index].radius, colliders[j].bounds)) if (CheckCollisionCircleRec((Vector2){colliders[index].bounds.x, colliders[index].bounds.y}, colliders[index].radius, colliders[j].bounds))
{ {

View file

@ -32,7 +32,8 @@
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
typedef enum { RectangleCollider, CircleCollider } ColliderType; // Collider types
typedef enum { COLLIDER_CIRCLE, COLLIDER_RECTANGLE, COLLIDER_CAPSULE } ColliderType;
// Physics struct // Physics struct
typedef struct Physics { typedef struct Physics {

View file

@ -463,7 +463,7 @@ typedef struct {
typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode; typedef enum { CAMERA_CUSTOM = 0, CAMERA_FREE, CAMERA_ORBITAL, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON } CameraMode;
// Collider types // Collider types
typedef enum { RectangleCollider, CircleCollider } ColliderType; typedef enum { COLLIDER_CIRCLE, COLLIDER_RECTANGLE, COLLIDER_CAPSULE } ColliderType;
// Physics struct // Physics struct
typedef struct Physics { typedef struct Physics {
@ -496,8 +496,8 @@ typedef struct Rigidbody {
typedef struct Collider { typedef struct Collider {
bool enabled; bool enabled;
ColliderType type; ColliderType type;
Rectangle bounds; // Just used for RectangleCollider type Rectangle bounds; // Used for COLLIDER_RECTANGLE and COLLIDER_CAPSULE
int radius; // Just used for CircleCollider type int radius; // Used for COLLIDER_CIRCLE and COLLIDER_CAPSULE
} Collider; } Collider;
#ifdef __cplusplus #ifdef __cplusplus