aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.h21
-rw-r--r--src/graphics.c64
-rw-r--r--src/graphics.h11
-rw-r--r--src/main.c39
-rw-r--r--src/math.c4
-rw-r--r--src/math.h4
-rw-r--r--src/phy_math.c4
-rw-r--r--src/phy_math.h11
-rw-r--r--src/physics.c9
-rw-r--r--src/physics.h19
10 files changed, 147 insertions, 39 deletions
diff --git a/src/common.h b/src/common.h
index a9ad3d0..c757489 100644
--- a/src/common.h
+++ b/src/common.h
@@ -11,17 +11,13 @@ typedef int_least16_t i16;
typedef uint_least32_t u32;
typedef int_least32_t i32;
-typedef struct {
- float x;
- float y;
-} Vec2d;
+
// settings
// UI
-#define SCREEN_WIDTH 800
-#define SCREEN_HEIGHT 600
#define SCREEN_TITLE "physics"
-
+#define WINDOW_X 1250
+#define WINDOW_Y 1000
// physics
#define MAX_OBJECTS 100
#define FORCE_RESITUTION_DEFAULT 0.8f
@@ -33,15 +29,4 @@ typedef enum {
SHAPE_SQUARE,
SHAPE_RECTANGLE
} shape_t;
-
-typedef struct {
- shape_t type;
- Vec2d pos;
- Vec2d vel;
- Vec2d acc;
- float width;
- float height;
- Color color;
-} object_t;
-
#endif // COMMON_H
diff --git a/src/graphics.c b/src/graphics.c
new file mode 100644
index 0000000..ccc3fa7
--- /dev/null
+++ b/src/graphics.c
@@ -0,0 +1,64 @@
+// graphics.c
+#include <raylib.h>
+#include <stdint.h>
+#include "graphics.h"
+#include "math.h"
+
+void init_graphics(uint32_t x, uint32_t y, const char* title)
+{
+ InitWindow(x, y, title);
+ SetTargetFPS(60);
+}
+
+void close_graphics(void)
+{
+ CloseWindow();
+}
+
+void begin_graphics_drawing(void)
+{
+ BeginDrawing();
+}
+
+void end_graphics_drawing(void)
+{
+ EndDrawing();
+}
+
+void clear_graphics(const Color color)
+{
+ ClearBackground(color);
+}
+
+void draw_graphics_object(const object_t* obj, Color color)
+{
+ if(!obj->registered) return;
+
+ Vector2 pos = obj->pos;
+
+ switch(obj->type) {
+ case OBJECT_CIRCLE:
+ DrawCircleV(pos, obj->size_x, color);
+ break;
+ case OBJECT_SQUARE:
+ DrawRectangleV(
+ (Vector2){pos.x - obj->size_x/2, pos.y - obj->size_y/2},
+ (Vector2){obj->size_x, obj->size_y}, color);
+ break;
+ case OBJECT_RECTANGLE:
+ DrawRectangleV(
+ (Vector2){pos.x - obj->size_x/2, pos.y - obj->size_y/2},
+ (Vector2){obj->size_x, obj->size_y}, color);
+ break;
+ }
+
+}
+
+void draw_graphics_objects(const object_t* world, uint32_t count, Color color)
+{
+
+}
+
+
+void draw_graphics_info(uint32_t fps, uint32_t objs, uint32_t max_objs);
+bool should_close_graphics(void);
diff --git a/src/graphics.h b/src/graphics.h
index e9ea1fd..65c2ddc 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -3,7 +3,16 @@
#define GRAPHICS_H
#include <raylib.h>
+#include <stdint.h>
#include "common.h"
-void create_new_object(object_t object);
+void init_graphics(uint32_t x, uint32_t y, const char* title);
+void close_graphics(void)
+void begin_graphics_drawing(void);
+void end_graphics_drawing(void);
+void clear_graphics(const Color color);
+void draw_graphics_object(const object_t* obj, Color color);
+void draw_graphics_objects(const object_t* world, uint32_t count, Color color);
+void draw_graphics_info(uint32_t fps, uint32_t objs, uint32_t max_objs);
+bool should_close_graphics(void);
#endif // GRAPHICS_H
diff --git a/src/main.c b/src/main.c
index 1f943c8..12a3ac7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,18 +9,8 @@
#include "graphics.h"
#include "physics.h"
-void physics_init(void)
-{
- InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE);
- SetTargetFPS(60);
-}
-
-void physics_close(void)
-{
- CloseWindow();
-}
-void physics_draw_info()
+void draw_graphics_info()
{
char buffer[128];
snprintf(buffer, sizeof(buffer), "FPS: %d", GetFPS());
@@ -33,27 +23,38 @@ void physics_draw_info()
DrawText("C: Clear screen", 10, 135, 20, BLACK);
DrawText("RCLICK: Push object", 10, 160, 20, BLACK);
DrawText("LCLICK: Add object", 10, 185, 20, BLACK);
+ DrawText("1: Spawn Circle", 10, 210, 20, BLACK);
+ DrawText("2: Spawn Square", 10, 235, 20, BLACK);
+ DrawText("3: Spawn Rectangle", 10, 260, 20, BLACK);
}
+
int main(void)
{
bool should_run = true;
// physics related
- object_t objects[MAX_OBJECTS];
+ object_t world[MAX_OBJECTS];
float force_resitution = FORCE_RESITUTION_DEFAULT;
float force_gravity = FORCE_GRAVITY_DEFAULT;
float force_linear_damping = FORCE_LINEAR_DAMPING_DEFAULT;
- physics_init();
+ InitWindow(WINDOW_X, WINDOW_Y, SCREEN_TITLE);
+ SetTargetFPS(60);
while(!WindowShouldClose() && should_run)
- {
- BeginDrawing();
- ClearBackground(WHITE);
- physics_draw_info();
- EndDrawing();
+ {
+ /* handle_input(world) */
+ // physics_update
+
+ begin_graphics_drawing();
+
+ clear_graphics(RAYWHITE);
+ draw_graphics_objects(world, object_count, BLACK);
+ draw_graphics_info(GetFPS(), object_count, MAX_OBJECTS);
+
+ end_graphics_drawing();
}
- physics_close();
+ CloseWindow();
return EXIT_SUCCESS;
}
diff --git a/src/math.c b/src/math.c
new file mode 100644
index 0000000..0ee755b
--- /dev/null
+++ b/src/math.c
@@ -0,0 +1,4 @@
+// math.c
+#include "phy_math.h"
+
+
diff --git a/src/math.h b/src/math.h
new file mode 100644
index 0000000..0aa9c3d
--- /dev/null
+++ b/src/math.h
@@ -0,0 +1,4 @@
+#ifndef PHY_MATH
+#define PHY_MATH
+
+#endif
diff --git a/src/phy_math.c b/src/phy_math.c
new file mode 100644
index 0000000..0ee755b
--- /dev/null
+++ b/src/phy_math.c
@@ -0,0 +1,4 @@
+// math.c
+#include "phy_math.h"
+
+
diff --git a/src/phy_math.h b/src/phy_math.h
new file mode 100644
index 0000000..1110319
--- /dev/null
+++ b/src/phy_math.h
@@ -0,0 +1,11 @@
+#ifndef PHY_MATH
+#define PHY_MATH
+
+typedef struct {
+ float x;
+ float y;
+} Vec2d;
+
+Vec2d vec2d_add(Vec2d v1, Vec2d v2);
+Vec2d vec2d_sub(Vec2d v1, Vec2d )
+#endif
diff --git a/src/physics.c b/src/physics.c
new file mode 100644
index 0000000..4432dee
--- /dev/null
+++ b/src/physics.c
@@ -0,0 +1,9 @@
+// physics.c
+#include <raylib.h>
+#include "physics.h"
+#include "common.h"
+
+void register_new_object(object_t* world, u32 object_x, u32 object_y)
+{
+ world
+}
diff --git a/src/physics.h b/src/physics.h
index b9a397b..b1fef97 100644
--- a/src/physics.h
+++ b/src/physics.h
@@ -5,6 +5,23 @@
#include <raylib.h>
#include "common.h"
-void register_new_object(object_t object, u32 object_x, u32 object_y);
+typedef struct {
+ shape_t type;
+ Vec2d pos;
+ Vec2d vel;
+ Vec2d acc;
+ float width;
+ float height;
+ Color color;
+} object_t;
+typedef sturct {
+ object_t* object_arr;
+ u16 object_count;
+ size_t capacity;
+} world_t;
+
+void register_new_object(world_t* world, u32 object_x, u32 object_y);
+void delete_object(world_t* world);
+void clear_scene(world_t* world);
#endif // PHYSICS_H