summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-12-11 11:50:06 +0500
committerilotterytea <iltsu@alright.party>2024-12-11 11:50:06 +0500
commit80c74c80615693cf4b8a5090121dad8d14ccfb0f (patch)
tree35eded3126e68e182b51314ed80407da099352e5
parentcbeb0314a90edb5ce28df2a8892160c0023320cb (diff)
feat: mouse can control the world view
-rw-r--r--src/main.c17
-rw-r--r--src/star.c5
-rw-r--r--src/star.h2
3 files changed, 18 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 897c49b..be9a05e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,6 +5,7 @@
#include "time.h"
int main(int argc, char *argv[]) {
+ bool mouse_control = false;
srand(time(0));
InitWindow(800, 600, "hyperspace (demo)");
@@ -31,13 +32,27 @@ int main(int argc, char *argv[]) {
star->position = Generate3DPosition();
}
- StarUpdate(star);
+ float screen_center_x =
+ mouse_control ? GetMouseX() : GetScreenWidth() / 2.0;
+ float screen_center_y =
+ mouse_control ? GetMouseY() : GetScreenHeight() / 2.0;
+
+ StarUpdate(star, screen_center_x, screen_center_y);
DrawRectangle(star->renderPosition.x, star->renderPosition.y,
star->size.x, star->size.y, star->color);
}
EndDrawing();
+
+ // Listening for input
+ if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+ mouse_control = !mouse_control;
+ if (mouse_control)
+ HideCursor();
+ else
+ ShowCursor();
+ }
}
return 0;
diff --git a/src/star.c b/src/star.c
index a92e63f..24d2dd0 100644
--- a/src/star.c
+++ b/src/star.c
@@ -31,10 +31,7 @@ Star StarCreate() {
return (Star){Generate3DPosition(), {1, 1}, {0, 0}, velocity, BLACK};
}
-void StarUpdate(Star *star) {
- float screen_center_x = GetScreenWidth() / 2.0;
- float screen_center_y = GetScreenHeight() / 2.0;
-
+void StarUpdate(Star *star, float screen_center_x, float screen_center_y) {
float x = star->position.x / star->position.z + screen_center_x;
float y = star->position.y / star->position.z + screen_center_y;
diff --git a/src/star.h b/src/star.h
index db34db6..7de8e8e 100644
--- a/src/star.h
+++ b/src/star.h
@@ -8,6 +8,6 @@ typedef struct Star {
} Star;
Star StarCreate();
-void StarUpdate(Star *star);
+void StarUpdate(Star *star, float screen_center_x, float screen_center_y);
Vector3 Generate3DPosition();