From 9a285cc3bdb8d5870fea5f07235a3e44786a0317 Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Tue, 13 Apr 2021 02:23:22 +0200 Subject: Add controller to its own header file Signed-off-by: Johnny Richard --- .gitignore | 4 +++- Makefile | 24 +++++++++++++++++++----- src/controller.h | 21 +++++++++++++++++++++ src/main.c | 11 +++-------- 4 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 src/controller.h diff --git a/.gitignore b/.gitignore index f18d57b..ff853ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.exe -main +*.o +/build +blast_attack diff --git a/Makefile b/Makefile index 5d398f2..68d2425 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ -.PHONY: build clean run +TARGET ?= blast_attack +SOURCE_DIR ?= ./src +BUILD_DIR ?= ./build CFLAGS := -Wall +OBJS := $(BUILD_DIR)/main.o ifeq ($(OS),Windows_NT) CC := gcc @@ -10,11 +13,22 @@ else CFLAGS += -Wall $(shell pkg-config sdl2 --cflags --libs) endif -build: - $(CC) src/main.c -o main $(CFLAGS) +.PHONY: build clean run $(TARGET) + +all: $(TARGET) + +$(TARGET): $(BUILD_DIR) $(OBJS) + $(CC) $(OBJS) -o $(TARGET) $(CFLAGS) + +$(BUILD_DIR): + @mkdir -p $@ + +$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c + $(CC) $(CFLAGS) -c $< -o $@ clean: - rm ./game; + @rm -rf $(OBJS) + @rm $(TARGET) run: - ./game; + ./$(TARGET) diff --git a/src/controller.h b/src/controller.h new file mode 100644 index 0000000..bf22335 --- /dev/null +++ b/src/controller.h @@ -0,0 +1,21 @@ +#ifndef CONTROLLER_H +#define CONTROLLER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct controller_t { + bool up; + bool down; + bool left; + bool right; +} controller_t; + +#ifdef __cplusplus +} +#endif + +#endif /* CONTROLLER_H */ diff --git a/src/main.c b/src/main.c index 022a888..4f685b2 100644 --- a/src/main.c +++ b/src/main.c @@ -3,16 +3,11 @@ #include #include +#include "controller.h" + const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; -typedef struct Controller { - bool up; - bool down; - bool left; - bool right; -} Controller; - int main (int argc, char *args[]) @@ -41,7 +36,7 @@ main (int argc, SDL_Rect rect = { .x = 0, .y = 0, .w = 20, .h = 20 }; bool quit = false; - Controller controller = {0}; + controller_t controller = {0}; while (!quit) { screenSurface = SDL_GetWindowSurface(window); -- cgit v1.2.3