flappychik

Silly SDL2 game
git clone git://bsandro.tech/flappychik
Log | Files | Refs

commit 0bcdc35ccd086bbf9b1a4449cbd600844428fb70
Author: bsandro <brian.drosan@gmail.com>
Date:   Mon, 14 Feb 2022 00:03:05 +0200

init

Diffstat:
A.gitignore | 3+++
AMakefile | 20++++++++++++++++++++
Akohina.jpg | 0
Amain.c | 43+++++++++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +*.o +flappychik diff --git a/Makefile b/Makefile @@ -0,0 +1,20 @@ +NAME=$(shell basename ${PWD}) +SDL2FLAGS=$(shell pkg-config --cflags sdl2 sdl2_image) +CFLAGS?=-std=c99 -Wall -Wextra -pedantic -I. -O0 -g +LDFLAGS?=$(shell pkg-config --libs sdl2 sdl2_image) +SRC=$(wildcard *.c) +DEPS:=$(wildcard *.h) +OBJ:=$(SRC:.c=.o) + +all: $(NAME) + +.PHONY: clean + +clean: + rm -f $(OBJ) $(NAME) + +%.o : %.c $(DEPS) + $(CC) $(CFLAGS) $(SDL2FLAGS) -c $< -o $@ + +$(NAME): $(OBJ) + $(CC) $(OBJ) -o $@ $(LDFLAGS) diff --git a/kohina.jpg b/kohina.jpg Binary files differ. diff --git a/main.c b/main.c @@ -0,0 +1,43 @@ +#include <stdlib.h> +#include <stdio.h> +#include <stdbool.h> +#include <assert.h> +#include <SDL.h> +#include <SDL_image.h> + +int main(void) { + bool quit = false; + SDL_Event event; + + SDL_Init(SDL_INIT_VIDEO); + SDL_Window *screen = SDL_CreateWindow("flappychik", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0); + assert(screen != NULL); + + SDL_Renderer *renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + assert(renderer != NULL); + + SDL_Surface *jpg = IMG_Load("kohina.jpg"); + assert(jpg != NULL); + + SDL_Texture *tex = SDL_CreateTextureFromSurface(renderer, jpg); + + while (!quit) { + SDL_WaitEvent(&event); + switch (event.type) { + case SDL_QUIT: + quit = true; + break; + } + + SDL_RenderCopy(renderer, tex, NULL, NULL); + SDL_RenderPresent(renderer); + } + + SDL_DestroyTexture(tex); + SDL_FreeSurface(jpg); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(screen); + SDL_Quit(); + + return 0; +}