mirror of https://git.sr.ht/~kikoodx/momento
Improved visuals of the game
New animations, reworked parts of tileset, code, etc.
This commit is contained in:
parent
7326e28e6b
commit
5d5cc7fb8c
|
@ -44,13 +44,17 @@ set(ASSETS
|
|||
assets/graphics/player.png
|
||||
assets/graphics/burst.png
|
||||
assets/graphics/coin-particle.png
|
||||
assets/graphics/switch-particle.png
|
||||
assets/graphics/switch-activated-particle.png
|
||||
assets/graphics/exit-active-particle.png
|
||||
assets/graphics/exit-unlock-particle.png
|
||||
)
|
||||
|
||||
set(FLAGS
|
||||
-Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum
|
||||
-Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes
|
||||
-Wold-style-definition -Werror-implicit-function-declaration
|
||||
-std=c11 -pedantic -Os)
|
||||
-std=c11 -pedantic -O3)
|
||||
|
||||
fxconv_declare_assets(${ASSETS} WITH_METADATA)
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 767 B |
Binary file not shown.
After Width: | Height: | Size: 788 B |
|
@ -10,3 +10,15 @@ burst.png:
|
|||
coin-particle.png:
|
||||
type: libimg-image
|
||||
name: img_coin_particle
|
||||
switch-particle.png:
|
||||
type: libimg-image
|
||||
name: img_switch_particle
|
||||
switch-activated-particle.png:
|
||||
type: libimg-image
|
||||
name: img_switch_activated_particle
|
||||
exit-active-particle.png:
|
||||
type: libimg-image
|
||||
name: img_exit_active_particle
|
||||
exit-unlock-particle.png:
|
||||
type: libimg-image
|
||||
name: img_exit_unlock_particle
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 510 B |
Binary file not shown.
After Width: | Height: | Size: 521 B |
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.5 KiB |
|
@ -14,10 +14,13 @@ struct Particle {
|
|||
int frame_height;
|
||||
int frame_duration;
|
||||
int frame;
|
||||
int life_ini;
|
||||
int life;
|
||||
int looping;
|
||||
};
|
||||
|
||||
void particles_init(void);
|
||||
void particles_update(void);
|
||||
void particles_draw(void);
|
||||
void particle_create(img_t *texture, int x, int y, int frame_width, int frame_duration);
|
||||
void particle_create(img_t *texture, int x, int y, int frame_width,
|
||||
int frame_duration, int particles);
|
||||
|
|
|
@ -26,29 +26,37 @@ void level_draw(void)
|
|||
const Tile tile =
|
||||
level.data[x + y * level.width];
|
||||
switch (tile) {
|
||||
case TILE_VOID: break;
|
||||
case TILE_VOID:
|
||||
break;
|
||||
case TILE_SOLID: {
|
||||
const int autotile = autotile_value(x, y) * TILE_WIDTH;
|
||||
img_render_vram(img_sub(img_tileset, autotile, TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT), draw_x, draw_y);
|
||||
}
|
||||
break;
|
||||
default: img_render_vram(
|
||||
img_sub(img_tileset,
|
||||
(int)(tile % tileset_width) *
|
||||
TILE_WIDTH,
|
||||
(int)(tile / tileset_width) *
|
||||
TILE_HEIGHT,
|
||||
TILE_WIDTH, TILE_HEIGHT),
|
||||
draw_x, draw_y);
|
||||
break;
|
||||
const int autotile =
|
||||
autotile_value(x, y) * TILE_WIDTH;
|
||||
img_render_vram(
|
||||
img_sub(img_tileset, autotile,
|
||||
TILE_HEIGHT, TILE_WIDTH,
|
||||
TILE_HEIGHT),
|
||||
draw_x, draw_y);
|
||||
} break;
|
||||
default:
|
||||
img_render_vram(
|
||||
img_sub(
|
||||
img_tileset,
|
||||
(int)(tile % tileset_width) *
|
||||
TILE_WIDTH,
|
||||
(int)(tile / tileset_width) *
|
||||
TILE_HEIGHT,
|
||||
TILE_WIDTH, TILE_HEIGHT),
|
||||
draw_x, draw_y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int autotile_value(int x, int y) {
|
||||
static int autotile_value(int x, int y)
|
||||
{
|
||||
return ((level_get_tile(x - 1, y) == TILE_SOLID) |
|
||||
((level_get_tile(x + 1, y) == TILE_SOLID) << 1) |
|
||||
((level_get_tile(x, y - 1) == TILE_SOLID) << 2) |
|
||||
((level_get_tile(x, y + 1) == TILE_SOLID) << 3));
|
||||
((level_get_tile(x + 1, y) == TILE_SOLID) << 1) |
|
||||
((level_get_tile(x, y - 1) == TILE_SOLID) << 2) |
|
||||
((level_get_tile(x, y + 1) == TILE_SOLID) << 3));
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
extern struct Level level;
|
||||
|
||||
Tile level_get_tile(int x, int y) {
|
||||
Tile level_get_tile(int x, int y)
|
||||
{
|
||||
if (x < 0 || y < 0 || x >= level.width || y >= level.height)
|
||||
return TILE_OOB;
|
||||
return level.data[x + y * level.width];
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include "conf.h"
|
||||
#include "level.h"
|
||||
#include "player.h"
|
||||
#include "particles.h"
|
||||
#include "player.h"
|
||||
#include <gint/clock.h>
|
||||
#include <gint/display.h>
|
||||
#include <gint/gint.h>
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
|
||||
extern struct Particle particles[MAX_PARTICLES];
|
||||
|
||||
void particle_create(img_t *texture, int x, int y, int frame_width, int frame_duration) {
|
||||
void particle_create(img_t *texture, int x, int y, int frame_width,
|
||||
int frame_duration, int looping)
|
||||
{
|
||||
/* find unused slot */
|
||||
int i = MAX_PARTICLES;
|
||||
while (i --> 0)
|
||||
while (i-- > 0)
|
||||
if (!particles[i].life)
|
||||
break;
|
||||
struct Particle *particle = &particles[i];
|
||||
|
@ -21,5 +23,8 @@ void particle_create(img_t *texture, int x, int y, int frame_width, int frame_du
|
|||
particle->frame_height = texture->height;
|
||||
particle->frame_duration = frame_duration;
|
||||
particle->frame = 0;
|
||||
particle->life = frame_duration * texture->width / frame_width;
|
||||
particle->life_ini =
|
||||
frame_duration * texture->width / frame_width;
|
||||
particle->life = particle->life_ini;
|
||||
particle->looping = looping;
|
||||
}
|
||||
|
|
|
@ -8,14 +8,21 @@ extern struct Particle particles[MAX_PARTICLES];
|
|||
|
||||
static void particle_draw(struct Particle particle);
|
||||
|
||||
void particles_draw(void) {
|
||||
void particles_draw(void)
|
||||
{
|
||||
int i = MAX_PARTICLES;
|
||||
while (i --> 0)
|
||||
while (i-- > 0)
|
||||
particle_draw(particles[i]);
|
||||
}
|
||||
|
||||
static void particle_draw(struct Particle particle) {
|
||||
if (!particle.life) return;
|
||||
static void particle_draw(struct Particle particle)
|
||||
{
|
||||
if (!particle.life)
|
||||
return;
|
||||
|
||||
img_render_vram(img_sub(*particle.texture, particle.frame * particle.frame_width, 0, particle.frame_width, particle.frame_height), particle.x, particle.y);
|
||||
img_render_vram(img_sub(*particle.texture,
|
||||
particle.frame * particle.frame_width,
|
||||
0, particle.frame_width,
|
||||
particle.frame_height),
|
||||
particle.x, particle.y);
|
||||
}
|
||||
|
|
|
@ -5,16 +5,19 @@
|
|||
|
||||
struct Particle particles[MAX_PARTICLES];
|
||||
|
||||
void particles_init(void) {
|
||||
void particles_init(void)
|
||||
{
|
||||
int i = MAX_PARTICLES;
|
||||
while (i --> 0) {
|
||||
while (i-- > 0) {
|
||||
particles[i] = (struct Particle){
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.texture = NULL,
|
||||
.frame_width = 0,
|
||||
.frame = 0,
|
||||
.life = 0,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.texture = NULL,
|
||||
.frame_width = 0,
|
||||
.frame = 0,
|
||||
.life_ini = 0,
|
||||
.life = 0,
|
||||
.looping = 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,16 +7,25 @@ extern struct Particle particles[MAX_PARTICLES];
|
|||
|
||||
static void particle_update(struct Particle *particle);
|
||||
|
||||
void particles_update(void) {
|
||||
void particles_update(void)
|
||||
{
|
||||
int i = MAX_PARTICLES;
|
||||
while (i --> 0)
|
||||
while (i-- > 0)
|
||||
particle_update(&particles[i]);
|
||||
}
|
||||
|
||||
static void particle_update(struct Particle *particle) {
|
||||
if (!particle->life) return;
|
||||
static void particle_update(struct Particle *particle)
|
||||
{
|
||||
if (!particle->life)
|
||||
return;
|
||||
|
||||
particle->life -= 1;
|
||||
if (!(particle->life % particle->frame_duration))
|
||||
particle->frame += 1;
|
||||
|
||||
/* looping */
|
||||
if (!particle->life && particle->looping) {
|
||||
particle->frame = 0;
|
||||
particle->life = particle->life_ini;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,14 +3,18 @@
|
|||
|
||||
#include "conf.h"
|
||||
#include "level.h"
|
||||
#include "particles.h"
|
||||
#include "player.h"
|
||||
#include "tiles.h"
|
||||
#include "particles.h"
|
||||
#include <libimg.h>
|
||||
|
||||
extern struct Level level;
|
||||
|
||||
extern img_t img_coin_particle;
|
||||
extern img_t img_switch_particle;
|
||||
extern img_t img_switch_activated_particle;
|
||||
extern img_t img_exit_active_particle;
|
||||
extern img_t img_exit_unlock_particle;
|
||||
|
||||
static Tile collide_single(int x, int y);
|
||||
static int collide_sub_single(int x, int y, Tile sub, Tile rep);
|
||||
|
@ -75,9 +79,56 @@ static int collide_sub_single(int x, int y, Tile sub, Tile rep)
|
|||
const int tile_index =
|
||||
(int)(x / TILE_WIDTH) +
|
||||
(int)(y / TILE_WIDTH) * level.width;
|
||||
const int px = (int)(x / TILE_WIDTH) * TILE_WIDTH;
|
||||
const int py = (int)(y / TILE_HEIGHT) * TILE_HEIGHT;
|
||||
|
||||
/* replace tile */
|
||||
level.data[tile_index] = rep;
|
||||
if (sub == TILE_GOLD)
|
||||
particle_create(&img_coin_particle, (int)(x / TILE_WIDTH) * TILE_WIDTH, (int)(y / TILE_HEIGHT) * TILE_HEIGHT, TILE_WIDTH, 2);
|
||||
|
||||
/* spawn animations */
|
||||
switch (sub) {
|
||||
case TILE_GOLD:
|
||||
particle_create(&img_coin_particle, px, py,
|
||||
TILE_WIDTH, 2, 0);
|
||||
break;
|
||||
case TILE_SWITCH:
|
||||
/* still image */
|
||||
particle_create(&img_switch_activated_particle,
|
||||
px, py, TILE_WIDTH, 1, 1);
|
||||
/* activation animation */
|
||||
particle_create(&img_switch_particle, px, py,
|
||||
TILE_WIDTH, 8, 0);
|
||||
/* exit unlock animation */
|
||||
{
|
||||
int ty = level.height;
|
||||
int tx = 0;
|
||||
while (ty-- > 0) {
|
||||
tx = level.width;
|
||||
while (tx-- > 0) {
|
||||
if (level.data
|
||||
[tx +
|
||||
ty *
|
||||
level
|
||||
.width] ==
|
||||
TILE_EXIT)
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
found:
|
||||
tx *= TILE_WIDTH;
|
||||
ty *= TILE_HEIGHT;
|
||||
particle_create(
|
||||
&img_exit_active_particle, tx, ty,
|
||||
TILE_WIDTH, 2, 1);
|
||||
particle_create(
|
||||
&img_exit_unlock_particle, tx, ty,
|
||||
TILE_WIDTH, 4, 0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -31,6 +31,10 @@ struct Player player_init(void)
|
|||
while (y-- > 0) {
|
||||
if (level.data[x + y * level.width] ==
|
||||
TILE_START) {
|
||||
/* erase start tile */
|
||||
level.data[x + y * level.width] =
|
||||
TILE_VOID;
|
||||
/* set player position */
|
||||
player.x =
|
||||
x * TILE_WIDTH +
|
||||
(TILE_WIDTH - PLAYER_WIDTH) / 2;
|
||||
|
|
Loading…
Reference in New Issue