From a0f8dc499b60bb326a8765bf435c4a4344df0b20 Mon Sep 17 00:00:00 2001 From: Devyn Challman Date: Fri, 27 Mar 2026 11:59:34 -0700 Subject: add basic raylib client --- .gitignore | 2 ++ Makefile | 7 ++++--- client/main.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 31d23c5..410984a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ a.out *~ build/ bin/ +.* +compile_commands.json diff --git a/Makefile b/Makefile index 4b45de6..a14dbf8 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,12 @@ SERVER_TARGET = bin/server SERVER_SRC = $(shell find server -name "*.c") SERVER_OBJ = $(SERVER_SRC:server/%.c=$(SERVER_BUILD)/%.o) - CLIENT_BUILD = build/client CLIENT_TARGET = bin/client CLIENT_SRC = $(shell find client -name "*.c") CLIENT_OBJ = $(CLIENT_SRC:client/%.c=$(CLIENT_BUILD)/%.o) +CLIENT_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags raylib) +CLIENT_LDFLAGS = $(shell pkg-config --libs raylib) all: $(SERVER_TARGET) $(CLIENT_TARGET) @@ -25,7 +26,7 @@ $(SERVER_TARGET): $(SERVER_OBJ) $(CLIENT_TARGET): $(CLIENT_OBJ) mkdir -p bin - $(CC) $(CFLAGS) $(CLIENT_OBJ) -o $(CLIENT_TARGET) + $(CC) $(CLIENT_CFLAGS) $(CLIENT_OBJ) $(CLIENT_LDFLAGS) -o $(CLIENT_TARGET) $(SERVER_BUILD)/%.o: server/%.c mkdir -p $(dir $@) @@ -33,7 +34,7 @@ $(SERVER_BUILD)/%.o: server/%.c $(CLIENT_BUILD)/%.o: client/%.c mkdir -p $(dir $@) - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(CLIENT_CFLAGS) -c $< -o $@ clean: rm -rf build bin diff --git a/client/main.c b/client/main.c index 237c8ce..a38f470 100644 --- a/client/main.c +++ b/client/main.c @@ -1 +1,57 @@ -int main() {} +#include "raylib.h" +#include + +int main() { + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "Pants - MMO"); + + SetTargetFPS(60); + + char* message = "Welcome to Pants a game by Matthew & Devyn Challman"; + int fontSize = 25; + + int messageWidth = MeasureText(message, fontSize); + int messagePosX = (screenWidth - messageWidth) / 2; + int messagePosY = (screenHeight - fontSize) / 2; + + int buttonW = 150; + int buttonH = 50; + int buttonPosX = (screenWidth - buttonW) / 2; + int buttonPosY = (screenHeight - buttonH) / 2 + 100; + + char *connect = "Connect"; + int connectWidth = MeasureText(connect, fontSize); + int connectPosX = (screenWidth - connectWidth) / 2; + int connectPosY = (screenHeight - fontSize) / 2 + 100; + + while (!WindowShouldClose()) { + + bool connecting = false; + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) { + struct Vector2 mousePos = GetMousePosition(); + + if (mousePos.x >= buttonPosX && mousePos.x <= buttonPosX + buttonW && + mousePos.y >= buttonPosY && mousePos.y <= buttonPosY + buttonH) { + + connecting = true; + } + } + + BeginDrawing(); + ClearBackground(RAYWHITE); + DrawText(message, messagePosX, messagePosY, fontSize, LIGHTGRAY); + DrawRectangle(buttonPosX, buttonPosY, buttonW, buttonH, GREEN); + + if(connecting) + DrawText(connect, connectPosX, connectPosY, fontSize, RED); + else + DrawText(connect, connectPosX, connectPosY, fontSize, BLUE); + + DrawFPS(0,0); + EndDrawing(); + } + + return 0; +} -- cgit v1.2.3