From 16adefc98106a7f401a00864122f65f64305ecce Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 30 Apr 2026 19:07:38 +0200 Subject: Refactor crosshair --- Makefile | 2 +- all.h | 3 +++ game.c | 5 +---- interface.c | 8 ++++++++ 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 interface.c diff --git a/Makefile b/Makefile index 0eee797..57b58db 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ LDFLAGS := ./vendor/$(RAYLIB_VER)/lib/libraylib.a -lm GAME := bin/stalag HEXDUMP := bin/hexdump PACKER := bin/packer -SOURCES := main.c map.c game.c player.c +SOURCES := main.c map.c game.c player.c interface.c ifeq ($(SYSTEM), linux_amd64) LDFLAGS += -lX11 diff --git a/all.h b/all.h index 6c17f7f..ec07c39 100644 --- a/all.h +++ b/all.h @@ -138,6 +138,9 @@ void DrawGame(void); bool LoadMap(const char *filename); void UnloadMap(void); +// Interface +void DrawCrosshair(void); + // Player void UpdatePlayer(void); diff --git a/game.c b/game.c index 19a1875..dc54ce5 100644 --- a/game.c +++ b/game.c @@ -324,10 +324,7 @@ void DrawGame(void) { EndMode3D(); - int screenWidth = GetScreenWidth(); - int screenHeight = GetScreenHeight(); - DrawLine(screenWidth / 2 - 10, screenHeight / 2, screenWidth / 2 + 10, screenHeight / 2, GREEN); - DrawLine(screenWidth / 2, screenHeight / 2 - 10, screenWidth / 2, screenHeight / 2 + 10, GREEN); + DrawCrosshair(); DrawTextEx(game.font_ui, TextFormat("%i FPS", GetFPS()), (Vector2){ 10, 10 }, 20, 2, GREEN); DrawTextEx(game.font_ui, TextFormat("VSync: %s", game.vsync ? "ON" : "OFF"), (Vector2){ 10, 35 }, 20, 2, GREEN); diff --git a/interface.c b/interface.c new file mode 100644 index 0000000..a376ed2 --- /dev/null +++ b/interface.c @@ -0,0 +1,8 @@ +#include "all.h" + +void DrawCrosshair(void) { + int screenWidth = GetScreenWidth(); + int screenHeight = GetScreenHeight(); + DrawLine(screenWidth / 2 - 10, screenHeight / 2, screenWidth / 2 + 10, screenHeight / 2, GREEN); + DrawLine(screenWidth / 2, screenHeight / 2 - 10, screenWidth / 2, screenHeight / 2 + 10, GREEN); +} -- cgit v1.2.3