#include #include #include #include "demo.h" #include "pacman.h" #include "map.h" #include "collision.h" #define WINDOW_WIDTH 800 #define WINDOW_HEIGHT 600 int main() { int counter = 0; SDL_Init(SDL_INIT_EVERYTHING); struct demo demo = {0}; demo.win = SDL_CreateWindow("Pacman", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI); demo.ren = SDL_CreateRenderer(demo.win, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); bool running = true; SDL_Event e; struct pacman pacman = {0}; map_init(&demo); struct map map = {0}; load_map("assets/Maps/maze.csv", &map); for(int i = 0; i < 4; i++) init_animation(&pacman.animations[i], &(struct animation_init){ .ren = demo.ren, .spritesheet = "assets/Sprites/sprites.png", .initial_angle = 90.0 * i, .initial_frame_count = 3, .initial_frame_times = (float[]){0.05, 0.05, 0.05}, .initial_frames = (SDL_Rect[]) { { .x = 0, .y = 285, .w = 180, .h = 195 }, { .x = 240, .y = 285, .w = 180, .h = 195 }, { .x = 465, .y = 285, .w = 195, .h = 195 } } }); pacman.facing = FACING_DOWN; int then = SDL_GetTicks(); while(running) { while(SDL_PollEvent(&e)) { if(e.type == SDL_QUIT) { running = false; } handle_pacman_input(&e, &pacman); } int now = SDL_GetTicks(); float dt = (float)(now - then) / 1000; then = now; SDL_RenderClear(demo.ren); update_pacman(&pacman, dt); update_demo(&demo); draw_map(&demo, &map); draw_pacman(&demo, &pacman); SDL_RenderPresent(demo.ren); SDL_Rect r = { .x = pacman.xpos, .y = pacman.ypos, .w = 40, .h = 40 }; for(int i = 0; i < map.collider_count; i++) { if(is_colliding(&r, &map.colliders[i])) { printf("%d: Collision!\n", counter); counter++; break; } } } SDL_DestroyRenderer(demo.ren); SDL_DestroyWindow(demo.win); SDL_Quit(); return 0; }