aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.h51
-rw-r--r--src/graphics.h9
-rw-r--r--src/main.c46
-rw-r--r--src/physics.h10
4 files changed, 107 insertions, 9 deletions
diff --git a/src/common.h b/src/common.h
index 4b0cdc8..a9ad3d0 100644
--- a/src/common.h
+++ b/src/common.h
@@ -1,10 +1,47 @@
// common.h
-#pragma once
+#ifndef COMMON_H
+#define COMMON_H
+
#include <stdint.h>
-typedef u8 uint8_t_least_t
-typedef i8 int8_t_least_t
-typedef u16 uint16_least_t
-typedef i16 int16_least_t
-typedef u32 uint32_least_t
-typedef i32 int32_least_t
+typedef uint_least8_t u8;
+typedef int_least8_t i8;
+typedef uint_least16_t u16;
+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"
+
+// physics
+#define MAX_OBJECTS 100
+#define FORCE_RESITUTION_DEFAULT 0.8f
+#define FORCE_GRAVITY_DEFAULT 1000.0f
+#define FORCE_LINEAR_DAMPING_DEFAULT 0.995f;
+
+typedef enum {
+ SHAPE_CIRCLE,
+ 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.h b/src/graphics.h
index 297fbbd..e9ea1fd 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -1,2 +1,9 @@
// graphics.h
-#pragma once
+#ifndef GRAPHICS_H
+#define GRAPHICS_H
+
+#include <raylib.h>
+#include "common.h"
+void create_new_object(object_t object);
+
+#endif // GRAPHICS_H
diff --git a/src/main.c b/src/main.c
index cdd077c..1f943c8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,13 +1,59 @@
// main.c
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <raylib.h>
+#include <math.h>
#include "common.h"
#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()
+{
+ char buffer[128];
+ snprintf(buffer, sizeof(buffer), "FPS: %d", GetFPS());
+ DrawText(buffer, 10, 10, 20, BLACK);
+ /* snprintf(buffer, sizeof(buffer), "OBJ: %d/%d", objects, MAX_OBJECTS); */
+ /* DrawText(buffer, 10, 35, 20, BLACK); */
+ DrawText("ESC: Exit", 10, 60, 20, BLACK);
+ DrawText("R: Random velocity", 10, 85, 20, BLACK);
+ DrawText("G: Random gravity", 10, 110, 20, BLACK);
+ DrawText("C: Clear screen", 10, 135, 20, BLACK);
+ DrawText("RCLICK: Push object", 10, 160, 20, BLACK);
+ DrawText("LCLICK: Add object", 10, 185, 20, BLACK);
+}
int main(void)
{
+ bool should_run = true;
+
+ // physics related
+ object_t objects[MAX_OBJECTS];
+ float force_resitution = FORCE_RESITUTION_DEFAULT;
+ float force_gravity = FORCE_GRAVITY_DEFAULT;
+ float force_linear_damping = FORCE_LINEAR_DAMPING_DEFAULT;
+
+ physics_init();
+
+ while(!WindowShouldClose() && should_run)
+ {
+ BeginDrawing();
+ ClearBackground(WHITE);
+ physics_draw_info();
+ EndDrawing();
+ }
+
+ physics_close();
return EXIT_SUCCESS;
}
diff --git a/src/physics.h b/src/physics.h
index 7c92e1a..b9a397b 100644
--- a/src/physics.h
+++ b/src/physics.h
@@ -1,2 +1,10 @@
// physics.h
-#pragma once
+#ifndef PHYSICS_H
+#define PHYSICS_H
+
+#include <raylib.h>
+#include "common.h"
+
+void register_new_object(object_t object, u32 object_x, u32 object_y);
+
+#endif // PHYSICS_H