diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..add1faf --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +CC = gcc +CFLAGS=-g -Wall -DDEBUG -Wpedantic -lSDL2 -lSDL2_ttf +SRCDIR=src +OBJDIR=obj +SRCS=$(wildcard $(SRCDIR)/*.c) + +# Substitute all .c with .o from SRCS +OBJS=$(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRCS)) +BINDIR=bin +BIN=$(BINDIR)/game + +all: $(BIN) +release: CFLAGS=-Wall -Wpedantic -O2 -lSDL2 -lSDL2_ttf +release: clean +release: $(BIN) + +$(BIN): $(OBJS) $(BINDIR) + $(CC) $(CFLAGS) $(OBJS) -o $@ + +$(OBJDIR)/%.o: $(SRCDIR)/%.c $(OBJDIR) + $(CC) $(CFLAGS) -c $< -o $@ + +$(BINDIR): + mkdir $@ + +$(OBJDIR): + mkdir $@ + +.PHONY: clean +.PHONY: test +.PHONY: disass + +clean: + rm -rf $(BINDIR)/* $(OBJDIR)/* +test: + $(BIN) +disass: + objdump -S --disassemble $(OBJDIR)/$(FILE).o > $(OBJDIR)/$(FILE).s \ No newline at end of file diff --git a/bin/game b/bin/game new file mode 100755 index 0000000..674de52 Binary files /dev/null and b/bin/game differ diff --git a/list.c b/list.c new file mode 100644 index 0000000..076dbd5 --- /dev/null +++ b/list.c @@ -0,0 +1,7 @@ +#include "list.h" + +#define DEFAULTLISTSIZE 64 + +List* CreateList(void) { + +} \ No newline at end of file diff --git a/list.h b/list.h new file mode 100644 index 0000000..ae6fff7 --- /dev/null +++ b/list.h @@ -0,0 +1,12 @@ +#ifndef LIST_H +#define LIST_H + +typedef struct { + unsigned int Capcity; + unsigned int Size; + char** Strings; +} List; + +List* CreateList(void); + +#endif \ No newline at end of file diff --git a/obj/main.o b/obj/main.o new file mode 100644 index 0000000..e43f637 Binary files /dev/null and b/obj/main.o differ diff --git a/main.c b/src/main.c similarity index 56% rename from main.c rename to src/main.c index 4a11b7e..36e188f 100644 --- a/main.c +++ b/src/main.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -19,6 +20,7 @@ const int SCREEN_WIDTH = 1280; const int SCREEN_HEIGHT = 720; +int MouseDown = 0; typedef struct { SDL_Window *window; @@ -30,6 +32,8 @@ App app; void HandleInput(void); int Exit = 0; +int XRel, YRel; +int XOrg, YOrg; void Cleanup(void) { SDL_DestroyWindow(app.window); @@ -41,6 +45,10 @@ void Cleanup(void) { int main(int argc, char** argv){ memset(&app, 0, sizeof(app)); + XRel = 0; + YRel = 0; + XOrg = 0; + YOrg = 0; atexit(Cleanup); @@ -76,6 +84,60 @@ int main(int argc, char** argv){ printf("Renderer failed: %s\n", SDL_GetError()); return -1; } + + //SDL_SetRelativeMouseMode(SDL_TRUE); + + SDL_Rect rect; + + rect.x = SCREEN_WIDTH / SCREEN_HEIGHT; + rect.y = SCREEN_WIDTH / SCREEN_HEIGHT; + rect.w = SCREEN_WIDTH / 2; + rect.h = SCREEN_HEIGHT / 2; + + SDL_Rect rect2; + + rect2.x = 250;// / SCREEN_HEIGHT; + rect2.y = 250;// / SCREEN_HEIGHT; + rect2.w = SCREEN_WIDTH / 4; + rect2.h = SCREEN_HEIGHT / 4; + + // Uint64 start = 0; + // Uint64 end = 0; + // float frameCount = 0; + // int count = 0; + + while(!Exit) { + //start = SDL_GetPerformanceCounter(); + + SDL_Delay(16); + + HandleInput(); + + SDL_SetRenderDrawColor(app.renderer, 0, 0, 255, 0); + + SDL_RenderClear(app.renderer); + + // if (count >= 100) { + // snprintf(buffer, sizeof(buffer), "FPS: %.2f", count / frameCount); + // count = 0; + // frameCount = 0; + // } + SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0); + + SDL_RenderFillRect(app.renderer, &(SDL_Rect){rect.x + XRel, rect.y + YRel, rect.w, rect.h}); + + SDL_SetRenderDrawColor(app.renderer, 128, 0, 0, 0); + + SDL_RenderFillRect(app.renderer, &(SDL_Rect){rect2.x + XRel, rect2.y + YRel, rect2.w, rect2.h}); + + SDL_RenderPresent(app.renderer); + + // end = SDL_GetPerformanceCounter(); + + // frameCount += (end - start) / (float)SDL_GetPerformanceFrequency(); + + // count++; + } } void HandleInput(void) { @@ -83,11 +145,20 @@ void HandleInput(void) { while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: - case SDL_MOUSEBUTTONDOWN: Exit = 1; break; + case SDL_MOUSEBUTTONDOWN: + MouseDown = 1; + break; + case SDL_MOUSEBUTTONUP: + MouseDown = 0; + break; case SDL_MOUSEMOTION: //if (MainMenu->HitCheck(event.motion.x, event.motion.y, &MainMenu->Area)) { + if (MouseDown){ + XRel += event.motion.xrel; + YRel += event.motion.yrel; + } case SDL_TEXTINPUT: case SDL_KEYDOWN: default: