Skip to content

Instantly share code, notes, and snippets.

@Mikepicker
Created November 18, 2017 14:37
Show Gist options
  • Save Mikepicker/c1c51d468d6be6632c604e8c93022676 to your computer and use it in GitHub Desktop.
Save Mikepicker/c1c51d468d6be6632c604e8c93022676 to your computer and use it in GitHub Desktop.
void render() {
// Clear screen
SDL_RenderClear(gRenderer);
// Render zombies
for (int i = 0; i < ZOMBIE_COUNT; i++) {
if (zombies[i].alive) {
SDL_Rect srcZombie = { .x = (zombies[i].frameX / zombieAnimSpeed) * zombieWidth, .y = zombies[i].frameY * zombieHeight, .w = zombieWidth, .h = zombieHeight };
SDL_Rect dstZombie = { .x = (int)zombies[i].x, .y = (int)zombies[i].y, .w = zombieWidth, .h = zombieHeight };
SDL_RendererFlip flip = zombies[i].dir == 1 ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
SDL_RenderCopyEx(gRenderer, zombieTexture, &srcZombie, &dstZombie, 0, NULL, flip);
}
}
// Update the screen
SDL_RenderPresent(gRenderer);
// Update animation frame
for (int i = 0; i < ZOMBIE_COUNT; i++) {
zombies[i].frameX++;
if (zombies[i].alive && zombies[i].frameX / zombieAnimSpeed >= 4) {
zombies[i].frameX = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment