Setup basic things

This commit is contained in:
2022-06-02 21:34:29 -05:00
commit baa580fa24
5 changed files with 169 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
bin/
obj/
+41
View File
@@ -0,0 +1,41 @@
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
+16
View File
@@ -0,0 +1,16 @@
#include "cell.h"
#include <stdlib.h>
Cell* CreateCell(SDL_Rect rect) {
Cell* newCell = calloc(1, sizeof(Cell));
if (!newCell) {
return NULL;
}
newCell->Status = Alive;
newCell->Hitbox = rect;
return newCell;
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef CELL_H
#define CELL_H
#include <SDL2/SDL_rect.h>
typedef enum {
Alive,
Dead
} State;
typedef struct cell {
struct cell* TopLeft;
struct cell* Top;
struct cell* TopRight;
struct cell* Left;
struct cell* Right;
struct cell* BottomLeft;
struct cell* Botttom;
struct cell* BottomRight;
State Status;
SDL_Rect Hitbox;
} Cell;
Cell* CreateCell(SDL_Rect);
#endif
+84
View File
@@ -0,0 +1,84 @@
#include "SDL2/SDL.h"
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_hints.h>
#include <SDL2/SDL_keycode.h>
#include <SDL2/SDL_rect.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_thread.h>
#include <SDL2/SDL_timer.h>
#include <SDL2/SDL_video.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 720;
typedef struct {
SDL_Window *window;
SDL_Renderer *renderer;
TTF_Font* font;
} App;
App app;
void Cleanup(void);
void HandleInput(void);
int main(int argc, char** argv) {
memset(&app, 0, sizeof(app));
atexit(Cleanup);
if (SDL_Init(SDL_INIT_VIDEO) < 0){
printf("SDL failed: %s\n", SDL_GetError());
return -1;
}
app.window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (app.window == NULL){
printf("Window creation failed: %s\n", SDL_GetError());
return -1;
}
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
app.renderer = SDL_CreateRenderer(app.window, -1, SDL_RENDERER_ACCELERATED);
if (app.renderer == NULL) {
printf("Renderer failed: %s\n", SDL_GetError());
return -1;
}
while(1){
HandleInput();
SDL_Delay(16);
SDL_RenderPresent(app.renderer);
}
}
void Cleanup(void) {
SDL_DestroyWindow(app.window);
SDL_DestroyRenderer(app.renderer);
TTF_Quit();
SDL_Quit();
}
void HandleInput(void) {
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
exit(0);
break;
case SDL_MOUSEBUTTONDOWN:
exit(0);
case SDL_KEYDOWN:
default:
break;
}
}
}