mirror of https://git.sr.ht/~kikoodx/momento
Trail of swag
This commit is contained in:
parent
d585e2db6f
commit
9761a8f341
|
@ -33,6 +33,9 @@ set(SOURCES
|
|||
src/player/draw.c
|
||||
src/player/update.c
|
||||
src/player/collide.c
|
||||
src/trail/init.c
|
||||
src/trail/update.c
|
||||
src/trail/draw.c
|
||||
src/input/init.c
|
||||
src/input/update.c
|
||||
src/particles/init.c
|
||||
|
@ -56,7 +59,7 @@ set(SOURCES
|
|||
|
||||
set(ASSETS
|
||||
assets/graphics/tileset.png
|
||||
assets/graphics/burst.png
|
||||
assets/graphics/trail.png
|
||||
assets/graphics/coin-particle.png
|
||||
assets/graphics/switch-particle.png
|
||||
assets/graphics/switch-activated-particle.png
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 715 B |
|
@ -2,11 +2,11 @@
|
|||
tileset.png:
|
||||
type: bopti-image
|
||||
name: bimg_tileset
|
||||
burst.png:
|
||||
type: bopti-image
|
||||
name: bimg_burst
|
||||
|
||||
# libimg img_t
|
||||
trail.png:
|
||||
type: libimg-image
|
||||
name: img_trail
|
||||
coin-particle.png:
|
||||
type: libimg-image
|
||||
name: img_coin_particle
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 616 B |
|
@ -30,6 +30,7 @@ struct Player {
|
|||
struct Particle idle_anim;
|
||||
struct Particle jump_anim;
|
||||
struct Particle walk_anim;
|
||||
int trail_state;
|
||||
};
|
||||
|
||||
/* used for collisions */
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
#include "player.h"
|
||||
#include <libimg.h>
|
||||
|
||||
#define TRAIL_LIFE 33
|
||||
#define TRAIL_FRAMES 3
|
||||
#define TRAIL_SIZE 10
|
||||
#define TRAIL_FRAME_DURATION (TRAIL_LIFE / TRAIL_FRAMES)
|
||||
|
||||
struct Trail {
|
||||
int x;
|
||||
int y;
|
||||
int life;
|
||||
int frame;
|
||||
color_t color;
|
||||
};
|
||||
|
||||
void trail_init(void);
|
||||
void trail_update(struct Player player);
|
||||
void trail_draw(void);
|
|
@ -10,6 +10,7 @@
|
|||
#include "particles.h"
|
||||
#include "player.h"
|
||||
#include "titlescreen.h"
|
||||
#include "trail.h"
|
||||
#include "transition.h"
|
||||
#include "zxcolors.h"
|
||||
#include <gint/clock.h>
|
||||
|
@ -33,6 +34,7 @@
|
|||
if (fatal_error == -1) \
|
||||
PANIC(fatal_error_msg); \
|
||||
particles_init(); \
|
||||
trail_init(); \
|
||||
player = player_init(); \
|
||||
} while (0);
|
||||
|
||||
|
@ -52,7 +54,6 @@ main(void)
|
|||
int timer;
|
||||
int player_return_code;
|
||||
int frameskip = 0;
|
||||
int toskip = 0;
|
||||
/* int level_pack_beaten; */
|
||||
enum TransitionMode transition_previous_mode;
|
||||
enum GameState game_state = TitleScreen;
|
||||
|
@ -89,7 +90,6 @@ main(void)
|
|||
while (!keydown(KEY_EXIT)) {
|
||||
/* skip render frames */
|
||||
i = 1 + frameskip;
|
||||
toskip = frameskip;
|
||||
while (i-- > 0) {
|
||||
/* frameskip adjustement */
|
||||
if (has_ticked - 1 > frameskip)
|
||||
|
@ -126,6 +126,7 @@ main(void)
|
|||
break;
|
||||
case Playing:
|
||||
if (transition.mode == TransitionNone) {
|
||||
trail_update(player);
|
||||
particles_update();
|
||||
player_return_code =
|
||||
player_update(&player, input);
|
||||
|
@ -212,6 +213,7 @@ main(void)
|
|||
break;
|
||||
case Playing:
|
||||
level_draw();
|
||||
trail_draw();
|
||||
particles_draw();
|
||||
trail_draw();
|
||||
player_draw(player);
|
||||
|
|
|
@ -29,7 +29,7 @@ particle_draw(struct Particle particle)
|
|||
return;
|
||||
|
||||
/* fill image with transparent */
|
||||
img_fill(transformed_img, IMG_ALPHA);
|
||||
img_clear(transformed_img);
|
||||
|
||||
/* get frame subimage */
|
||||
const img_t frame_simg =
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
extern struct Level level;
|
||||
|
||||
extern bopti_image_t bimg_burst;
|
||||
|
||||
void
|
||||
player_draw(struct Player player)
|
||||
{
|
||||
|
@ -25,10 +23,6 @@ player_draw(struct Player player)
|
|||
/* draw animation */
|
||||
particle_draw(anim);
|
||||
|
||||
/* draw burst */
|
||||
if (player.air_state == AirRising && player.jumps_left < AIR_JUMPS)
|
||||
dimage(player.x, player.y + PLAYER_HEIGHT, &bimg_burst);
|
||||
|
||||
/* print level name
|
||||
* this shouldn't be in player code */
|
||||
dprint_opt(DWIDTH - 4, DHEIGHT, ZX_WHITE, C_NONE, DTEXT_RIGHT,
|
||||
|
|
|
@ -29,11 +29,12 @@ player_init(void)
|
|||
.jump_grace = 0,
|
||||
.jumps_left = 0,
|
||||
.air_state = AirNeutral,
|
||||
.trail_state = 0,
|
||||
};
|
||||
|
||||
/* initialize animations */
|
||||
player.blink_anim = particle_init(&img_player_blink, 0, 0, 10, 4, 0, 0);
|
||||
player.idle_anim = particle_init(&img_player_idle, 0, 0, 10, 1, 1, 1);
|
||||
player.idle_anim = particle_init(&img_player_idle, 0, 0, 10, 1, 1, 0);
|
||||
player.jump_anim = particle_init(&img_player_jump, 0, 0, 8, 6, 0, 0);
|
||||
player.walk_anim = particle_init(&img_player_walk, 0, 0, 12, 6, 1, 0);
|
||||
player.anim = player.idle_anim;
|
||||
|
|
|
@ -94,6 +94,7 @@ player_update(struct Player *player, struct Input input)
|
|||
}
|
||||
/* air jump (burst) */
|
||||
else {
|
||||
player->trail_state = !player->trail_state;
|
||||
player->jumps_left -= 1;
|
||||
player->spd_y = AIR_JMP_SPD;
|
||||
/* burst boost */
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "trail.h"
|
||||
#include <libimg.h>
|
||||
|
||||
extern struct Trail trail[TRAIL_LIFE];
|
||||
extern const img_t img_trail;
|
||||
|
||||
static void trail_atom_draw(struct Trail atom);
|
||||
|
||||
void
|
||||
trail_draw(void)
|
||||
{
|
||||
int i = TRAIL_LIFE;
|
||||
while (i-- > 0)
|
||||
trail_atom_draw(trail[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
trail_atom_draw(struct Trail atom)
|
||||
{
|
||||
if (!atom.life)
|
||||
return;
|
||||
|
||||
/* get frame subimage */
|
||||
const img_t frame_simg = img_sub(img_trail, atom.frame * TRAIL_SIZE, 0,
|
||||
TRAIL_SIZE, TRAIL_SIZE);
|
||||
|
||||
/* tint the frame */
|
||||
const img_t transformed_img = img_dye_create(frame_simg, atom.color);
|
||||
/* check */
|
||||
if (img_null(transformed_img))
|
||||
return;
|
||||
|
||||
/* render image */
|
||||
img_render_vram(transformed_img, atom.x, atom.y);
|
||||
|
||||
/* free */
|
||||
img_destroy(transformed_img);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "trail.h"
|
||||
|
||||
struct Trail trail[TRAIL_LIFE];
|
||||
|
||||
void
|
||||
trail_init(void)
|
||||
{
|
||||
int i = TRAIL_LIFE;
|
||||
while (i-- > 0) {
|
||||
trail[i] = (struct Trail){
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.life = 0,
|
||||
.frame = 0,
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/* 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;
|
||||
}
|
Loading…
Reference in New Issue