/* SPDX-License-Identifier: GPL-3.0-or-later */ /* Copyright (C) 2021 KikooDX */ #include "particles.h" #include extern struct Particle particles[MAX_PARTICLES]; void particles_draw(void) { int i = MAX_PARTICLES; while (i-- > 0) particle_draw(particles[i]); } void particle_draw(struct Particle particle) { if (!particle.life) return; /* create image to apply transformations on */ /* alloc */ const img_t transformed_img = img_create(particle.frame_width, particle.frame_height); /* check */ if (img_null(transformed_img)) return; /* fill image with transparent */ img_fill(transformed_img, IMG_ALPHA); /* get frame subimage */ const img_t frame_simg = img_sub(*particle.texture, particle.frame * particle.frame_width, 0, particle.frame_width, particle.frame_height); /* apply transformations if needed */ if (particle.flip_h) img_hflip(frame_simg, transformed_img); else img_render(frame_simg, transformed_img); /* render image */ img_render_vram(transformed_img, particle.x, particle.y); /* free */ img_destroy(transformed_img); }