mirror of https://git.sr.ht/~kikoodx/momento
49 lines
1012 B
C
49 lines
1012 B
C
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
/* Copyright (C) 2021 KikooDX */
|
|
|
|
#include "player.h"
|
|
#include "trail.h"
|
|
#include "zxcolors.h"
|
|
#include <libimg.h>
|
|
|
|
extern struct Trail trail[TRAIL_LIFE];
|
|
|
|
static void trail_atom_update(struct Trail *atom);
|
|
static void trail_create(int x, int y, color_t color);
|
|
|
|
void
|
|
trail_update(struct Player player)
|
|
{
|
|
int i = TRAIL_LIFE;
|
|
color_t color = player.trail_state ? ZX_WHITE : ZX_GRAY;
|
|
/* update trail */
|
|
while (i-- > 1) {
|
|
trail[i] = trail[i - 1];
|
|
trail_atom_update(&trail[i]);
|
|
}
|
|
/* create atom */
|
|
trail_create(player.x + (PLAYER_WIDTH - TRAIL_SIZE) / 2,
|
|
player.y + (PLAYER_HEIGHT - TRAIL_SIZE) / 2, color);
|
|
}
|
|
|
|
static void
|
|
trail_atom_update(struct Trail *atom)
|
|
{
|
|
if (!atom->life)
|
|
return;
|
|
|
|
atom->life -= 1;
|
|
if (!(atom->life % TRAIL_FRAME_DURATION))
|
|
atom->frame += 1;
|
|
}
|
|
|
|
static void
|
|
trail_create(int x, int y, color_t color)
|
|
{
|
|
trail[0].x = x;
|
|
trail[0].y = y;
|
|
trail[0].life = TRAIL_LIFE;
|
|
trail[0].frame = 0;
|
|
trail[0].color = color;
|
|
}
|