attack animations and simple knockback

This commit is contained in:
Lephenixnoir 2021-06-10 00:07:01 +02:00
parent b7685fe9e5
commit 1560fbd8eb
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
12 changed files with 69 additions and 4 deletions

View File

@ -33,6 +33,10 @@ set(ASSETS
assets-cg/player-idle-right.png
assets-cg/player-idle-down.png
assets-cg/player-idle-left.png
assets-cg/player-attack-up.png
assets-cg/player-attack-right.png
assets-cg/player-attack-down.png
assets-cg/player-attack-left.png
)
fxconv_declare_assets(${ASSETS} ${ASSETS} WITH_METADATA)

View File

@ -21,3 +21,25 @@ player-idle-down.png:
player-idle-left.png:
next: anim_player_idle_left
player-attack-*.png:
custom-type: animation
name_regex: player-attack-(.*)\.png anim_player_attack_\1
frame_duration: 30, 60, 60, 30, 60, 60, 30
profile: p8
player-attack-down.png:
center: 12, 17
next: anim_player_idle_down
player-attack-up.png:
center: 12, 23
next: anim_player_idle_up
player-attack-right.png:
center: 13, 15
next: anim_player_idle_right
player-attack-left.png:
center: 19, 15
next: anim_player_idle_left

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 705 B

View File

@ -34,6 +34,7 @@ int main(void)
{
getkey_set_feature_function(getkey_global_shortcuts);
__printf_enable_fp();
__printf_enable_fixed();
srand(0xc0ffee);
prof_init();
@ -52,11 +53,11 @@ int main(void)
entity_movement_params_t emp_none = {
.max_speed = fix(0),
.propulsion = fix(0),
.propulsion = fix(12),
};
entity_movement_params_t emp_player = {
.max_speed = PLAYER_SPEED,
.propulsion = fix(11),
.propulsion = fix(12),
.dash_speed = fix(45),
.dash_duration = fix(1) / 32,
.dash_cooldown = fix(1) / 2,
@ -111,6 +112,11 @@ int main(void)
extern anim_frame_t anim_player_idle_up[];
extern anim_frame_t anim_player_idle_down[];
extern anim_frame_t anim_player_attack_left[];
extern anim_frame_t anim_player_attack_right[];
extern anim_frame_t anim_player_attack_up[];
extern anim_frame_t anim_player_attack_down[];
player->anim.frame = &anim_player_idle_down[0];
player->anim.elapsed = 0;
@ -169,8 +175,7 @@ int main(void)
dprint(15, 190, gray, "More with [cos], less with [,]");
}
// dprint(1, 1, C_WHITE, "Frame: %.3j ms", time_render);
dprint(1, 1, C_WHITE, "dash:%g", f2double(player->movement.dash));
dprint(1, 1, C_WHITE, "Frame: %.3D ms", time_render);
dupdate();
});
@ -293,12 +298,40 @@ int main(void)
player->movement.dash = next.dash;
}
/* Enemy movement */
for(int i = 0; i < game.entity_count; i++) {
entity_t *e = game.entities[i];
if(e == player) continue;
entity_movement_t next = entity_move(e, -1, dt);
shape_t e_hitbox = e->hitbox;
shape_translate(&e_hitbox, (fpoint_t){ next.x, next.y });
if(!game_shape_collides(&game, e, &e_hitbox)) {
e->movement = next;
}
else {
e->movement.facing = next.facing;
e->movement.vx = fix(0);
e->movement.vy = fix(0);
}
}
/* Attack */
if(attack) {
fixed_t reach2 = fmul(ATTACK_REACH, ATTACK_REACH);
fixed_t angle_cos2 = fmul(ATTACK_ANGLE_COS, ATTACK_ANGLE_COS);
fpoint_t dir = fdir(player->movement.facing);
anim_frame_t *dirs[4] = {
anim_player_attack_up,
anim_player_attack_right,
anim_player_attack_down,
anim_player_attack_left,
};
player->anim.frame = dirs[player->movement.facing];
player->anim.elapsed = 0;
for(int i = 0; i < game.entity_count; i++) {
entity_t *e = game.entities[i];
if(e == player) continue;
@ -316,6 +349,10 @@ int main(void)
/* Inflict damage */
e->hitbox.color = C_RED;
/* Knockback */
e->movement.vx += fmul(dir.x, KNOCKBACK_SPEED);
e->movement.vy += fmul(dir.y, KNOCKBACK_SPEED);
}
}
}

View File

@ -33,3 +33,5 @@
#define ATTACK_ANGLE_COS fix(1)/2 /* 60 degrees */
/* Overlay all hitboxes over entity sprites */
extern int OVERLAY_HITBOXES;
/* Knockback speed applied to hit enemies */
#define KNOCKBACK_SPEED fix(15)