minor adjustments

This commit is contained in:
Lephenixnoir 2021-08-30 17:48:44 +02:00
parent dc37d1f533
commit 10b289d5eb
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
8 changed files with 56 additions and 29 deletions

View File

@ -1,3 +1,7 @@
A fun game about smashing monsters in a dungeon.
A fun game about smashing monsters in a dungeon.i
By Lephe' & Masséna
Compiling requires py\_aseprite by Eiyeron: [https://github.com/Eiyeron/py\_aseprite](https://github.com/Eiyeron/py_aseprite)
[Topic on Planète Casio](https://www.planet-casio.com/Fr/forums/topic16864-last-rogue-life-ou-tabasser-des-monstres-dans-une-ruelle-en-toute-legalite.html)

Binary file not shown.

View File

@ -64,6 +64,6 @@ void anim_state_update(anim_state_t *state, fixed_t dt)
if(state->elapsed < state->frame->duration) return;
/* Switch to next frame */
state->elapsed = 0;
state->elapsed -= state->frame->duration;
state->frame = state->frame->next;
}

View File

@ -335,3 +335,8 @@ void effect_area_apply(game_t *game, effect_area_t *ea, entity_t *e)
rec->lifetime = ea->lifetime;
}
bool effect_area_is_background(effect_area_t const *ea)
{
return ea->type == EFFECT_ATTACK_SHOCK;
}

View File

@ -190,3 +190,6 @@ void effect_area_set_anim(effect_area_t *ea, anim_frame_t *frame);
/* Apply effect of area on entity */
struct game;
void effect_area_apply(struct game *g, effect_area_t *ea, entity_t *e);
/* Whether the area should be rendered in background (floor level) */
bool effect_area_is_background(effect_area_t const *ea);

View File

@ -342,7 +342,7 @@ void game_sort_entities(game_t *g)
game_sort_entities_compare);
}
/* Compare the y valeus of two particles. */
/* Compare the y values of two particles. */
static int game_sort_particles_compare(void const *v1, void const *v2)
{
particle_t const *p1 = *(particle_t const **)v1;

View File

@ -66,7 +66,7 @@ int main(void)
//---
entity_movement_params_t emp_player = {
.max_speed = fix(4),
.max_speed = fix(4.5),
.propulsion = fix(12),
.dash_speed = fix(55),
.dash_duration = fix(1) / 32,
@ -124,6 +124,8 @@ int main(void)
while(!stop) {
while(!frame_tick) sleep();
frame_tick = 0;
bool attack = false;
/* This assumes the frame is not late; can do better with libprof */
@ -132,7 +134,6 @@ int main(void)
perf_render = prof_make();
prof_enter(perf_render);
dclear(C_BLACK);
render_game(&game, debug.show_hitboxes);
/* Developer/tweaking menu */
@ -331,6 +332,7 @@ int main(void)
}
/* Camera movement */
#if 0
fixed_t vx = CAMERA_SPEED_X;
fixed_t vy = CAMERA_SPEED_Y;
@ -342,6 +344,7 @@ int main(void)
camera_move(c, 0, -fmul(dt, vy));
if(keydown(KEY_2) || keydown(KEY_1) || keydown(KEY_3))
camera_move(c, 0, fmul(dt, vy));
#endif
/* Player movement */
if(player->HP > 0) {

View File

@ -111,22 +111,23 @@ fixed_t camera_ppu(camera_t const *c)
// Rendering
//---
/* TODO: render_map(): Split into render_game() which takes the game
structure as input (including the player) */
void render_map(map_t const *m, camera_t const *c)
{
extern bopti_image_t img_tileset_base;
extern bopti_image_t img_tileset_decor;
/* Render floor and walls */
for(int row = 0; row < m->height; row++)
for(int col = 0; col < m->width; col++) {
for(int row = -2; row < m->height + 1; row++)
for(int col = -1; col < m->width + 1; col++) {
struct tile *t = map_tile(m, col, row);
if(!t) continue;
fpoint_t tile_pos = { fix(col), fix(row) };
ipoint_t p = camera_map2screen(c, tile_pos);
if(!t) {
drect(p.x, p.y, p.x+15, p.y+15, C_BLACK);
continue;
}
/* Floor/wall layer */
dsubimage(p.x, p.y, &img_tileset_base,
TILE_WIDTH * (t->base % 16), TILE_HEIGHT * (t->base / 16),
@ -138,6 +139,26 @@ void render_map(map_t const *m, camera_t const *c)
}
}
static void render_effect_area(effect_area_t const *ea, camera_t const *c,
bool show_hitboxes)
{
ipoint_t anchor = camera_map2screen(c, ea->anchor);
if(ea->anim.frame) {
fpoint_t top_left = {
ea->anchor.x + ea->sprite.l,
ea->anchor.y + ea->sprite.t };
ipoint_t p = camera_map2screen(c, top_left);
anim_frame_render(p.x, p.y, ea->anim.frame);
}
if(!ea->anim.frame || show_hitboxes) {
frect_t r = ea->sprite;
r = rect_scale(r, camera_ppu(c));
r = rect_translate(r, point_i2f(anchor));
rect_draw(r, C_RGB(31, 31, 0));
}
}
void render_game(game_t const *g, bool show_hitboxes)
{
camera_t const *c = &g->camera;
@ -152,6 +173,12 @@ void render_game(game_t const *g, bool show_hitboxes)
particle_render(center.x, center.y, p);
}
/* Render background effect areas */
for(int i = 0; i < g->effect_area_count; i++) {
if(!effect_area_is_background(g->effect_areas[i])) continue;
render_effect_area(g->effect_areas[i], c, show_hitboxes);
}
/* Render entities */
for(int i = 0; i < g->entity_count; i++) {
entity_t *e = g->entities[i];
@ -180,25 +207,10 @@ void render_game(game_t const *g, bool show_hitboxes)
}
}
/* Render effect areas */
/* Render background effect areas */
for(int i = 0; i < g->effect_area_count; i++) {
effect_area_t *ea = g->effect_areas[i];
ipoint_t anchor = camera_map2screen(c, ea->anchor);
if(ea->anim.frame) {
fpoint_t top_left = {
ea->anchor.x + ea->sprite.l,
ea->anchor.y + ea->sprite.t };
ipoint_t p = camera_map2screen(c, top_left);
anim_frame_render(p.x, p.y, ea->anim.frame);
}
if(!ea->anim.frame || show_hitboxes) {
frect_t r = ea->sprite;
r = rect_scale(r, camera_ppu(c));
r = rect_translate(r, point_i2f(anchor));
rect_draw(r, C_RGB(31, 31, 0));
}
if(effect_area_is_background(g->effect_areas[i])) continue;
render_effect_area(g->effect_areas[i], c, show_hitboxes);
}
/* Render foreground particles */