flappychik

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

commit 10466d2948dbe639e4089fd31aef75e25cc7666d
parent a5ece423766f9be0cedcbf237e756aa84c0cf963
Author: bsandro <brian.drosan@gmail.com>
Date:   Mon, 14 Feb 2022 01:44:16 +0200

Moving a picture on any event, Metal usage and highdpi flags

Diffstat:
MMakefile | 3+++
AchikaiKnife.png | 0
Mmain.c | 37+++++++++++++++++++++++++++++--------
3 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile @@ -18,3 +18,6 @@ clean: $(NAME): $(OBJ) $(CC) $(OBJ) -o $@ $(LDFLAGS) + +run: $(NAME) + ./$(NAME) diff --git a/chikaiKnife.png b/chikaiKnife.png Binary files differ. diff --git a/main.c b/main.c @@ -5,21 +5,36 @@ #include <SDL.h> #include <SDL_image.h> -int main(void) { +int main(int argc, char *argv[]) { + (void)argc; + (void)argv; + 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); + SDL_Window *screen = SDL_CreateWindow("flappychik", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_METAL | SDL_WINDOW_ALLOW_HIGHDPI); 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_Surface *bg = IMG_Load("kohina.jpg"); + assert(bg != NULL); + + SDL_Surface *knife = IMG_Load("chikaiKnife.png"); // 56x56px + assert(knife != NULL); + + SDL_Texture *tex_bg = SDL_CreateTextureFromSurface(renderer, bg); + SDL_Texture *tex_knife = SDL_CreateTextureFromSurface(renderer, knife); + SDL_FreeSurface(knife); + SDL_FreeSurface(bg); - SDL_Texture *tex = SDL_CreateTextureFromSurface(renderer, jpg); + SDL_RenderCopy(renderer, tex_bg, NULL, NULL); + SDL_Rect knife_rect = {0, 0, 56, 56}; + SDL_RenderCopy(renderer, tex_knife, NULL, &knife_rect); + + SDL_RenderPresent(renderer); while (!quit) { SDL_WaitEvent(&event); @@ -28,16 +43,22 @@ int main(void) { quit = true; break; } + SDL_RenderClear(renderer); - SDL_RenderCopy(renderer, tex, NULL, NULL); + knife_rect.x += 1; + knife_rect.y += 1; + SDL_RenderCopy(renderer, tex_bg, NULL, NULL); + SDL_RenderCopy(renderer, tex_knife, NULL, &knife_rect); SDL_RenderPresent(renderer); + //printf("hello\n"); } - SDL_DestroyTexture(tex); - SDL_FreeSurface(jpg); + SDL_DestroyTexture(tex_bg); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(screen); SDL_Quit(); + printf("bye!\n"); + return 0; }