crystal-tower/src/shatter.c

45 lines
1.1 KiB
C
Raw Permalink Normal View History

2021-11-10 20:44:53 +01:00
#include "shatter.h"
#include "anim.h"
#include "conf.h"
#include "level.h"
#include "particles.h"
2021-11-16 23:11:16 +01:00
#include "raygint/display.h"
2021-11-10 20:44:53 +01:00
#include "tile.h"
#include "vec.h"
2021-11-17 14:51:05 +01:00
#include <stddef.h>
2021-11-10 20:44:53 +01:00
static void callback(struct Anim *);
void
shatter(int x, int y)
{
2021-11-17 14:51:05 +01:00
#ifdef GINT
2021-11-10 20:44:53 +01:00
extern bopti_image_t bimg_shatter;
2021-11-17 14:51:05 +01:00
#endif
#ifdef RAYLIB
bopti_image_t bimg_shatter = 0;
#endif
2021-11-10 20:44:53 +01:00
const int ax = (int)(x / TILE_SIZE) * TILE_SIZE;
const int ay = (int)(y / TILE_SIZE) * TILE_SIZE;
struct Anim p = anim_new(&bimg_shatter, ax, ay, TILE_SIZE, 2, false);
p.callback = callback;
2021-11-10 23:29:12 +01:00
if (level_get_px(ax, ay) == TILE_SOLID && !particles_here(ax, ay))
particles_add(p);
2021-11-10 20:44:53 +01:00
}
static void
callback(struct Anim *a)
{
2021-11-12 15:42:07 +01:00
const int x = a->pos.x / TILE_SIZE;
const int y = a->pos.y / TILE_SIZE;
level_set(x, y, TILE_SHATTERED);
if (level_get(x - 1, y) == TILE_SPIKE_L)
level_set(x - 1, y, TILE_VOID);
if (level_get(x + 1, y) == TILE_SPIKE_R)
level_set(x + 1, y, TILE_VOID);
if (level_get(x, y - 1) == TILE_SPIKE_U)
level_set(x, y - 1, TILE_VOID);
if (level_get(x, y + 1) == TILE_SPIKE_D)
level_set(x, y + 1, TILE_VOID);
2021-11-10 20:44:53 +01:00
}