handle dash cooldown as normal skill cooldown
This commit is contained in:
parent
69baa8d319
commit
f5a9d796be
|
@ -39,9 +39,12 @@ typedef struct
|
|||
uint8_t combo_next;
|
||||
/* Delay until ideal time to start next hit */
|
||||
fixed_t combo_delay;
|
||||
/* Skill and item cooldowns (F2..F5).The "total" field is updated when
|
||||
switching skills/items. The base field is the dynamic value. */
|
||||
/* Cooldown to apply for each skill/item. 0 is the standard attack, while
|
||||
1..4 correspond to F1...F4. This value is fixed unless the skills/items
|
||||
are rearranged, which is only possible for the player. */
|
||||
fixed_t actions_cooldown_total[5];
|
||||
/* Current cooldown; positive while waiting, zero when the skill or item is
|
||||
ready. */
|
||||
fixed_t actions_cooldown[5];
|
||||
|
||||
} fighter_t;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "comp/mechanical.h"
|
||||
#include "comp/physical.h"
|
||||
#include "comp/fighter.h"
|
||||
#include <gint/defs/util.h>
|
||||
|
||||
// Movement functions
|
||||
|
||||
|
@ -49,15 +50,8 @@ void mechanical_move(entity_t *e, vec2 direction, fixed_t dt, map_t const *map)
|
|||
if(m->vx >= -256 && m->vx <= 255) m->vx = 0;
|
||||
if(m->vy >= -256 && m->vy <= 255) m->vy = 0;
|
||||
|
||||
/* Decrement dash duration or dash cooldown */
|
||||
if(m->dash > 0) {
|
||||
m->dash -= dt;
|
||||
if(m->dash <= 0) m->dash = -limits->dash_cooldown;
|
||||
}
|
||||
else if(m->dash < 0) {
|
||||
m->dash += dt;
|
||||
if(m->dash >= 0) m->dash = 0;
|
||||
}
|
||||
/* Decrement time left on the dash */
|
||||
m->dash = max(m->dash - dt, fix(0.0));
|
||||
|
||||
if(facing >= 0)
|
||||
p->facing = facing;
|
||||
|
@ -125,7 +119,7 @@ bool mechanical_dashing(entity_t const *e)
|
|||
fixed_t cur_v2 = fmul(m->vx, m->vx) + fmul(m->vy, m->vy);
|
||||
fixed_t max_v2 = fmul(limits->max_speed, limits->max_speed);
|
||||
|
||||
if(m->dash < 0 && 2 * cur_v2 > 3 * max_v2)
|
||||
if(2 * cur_v2 > 3 * max_v2)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
|
@ -24,8 +24,6 @@ typedef struct
|
|||
fixed_t dash_speed;
|
||||
/* Dash duration (s) */
|
||||
fixed_t dash_duration;
|
||||
/* Dash cooldown (s) */
|
||||
fixed_t dash_cooldown;
|
||||
|
||||
} mechanical_limits_t;
|
||||
|
||||
|
|
27
src/main.c
27
src/main.c
|
@ -107,7 +107,6 @@ int main(void)
|
|||
.friction = fix(0.7),
|
||||
.dash_speed = fix(20),
|
||||
.dash_duration = fix(1) / 8,
|
||||
.dash_cooldown = fix(1),
|
||||
},
|
||||
.stat_model = {
|
||||
.HP = fix(1.5),
|
||||
|
@ -133,6 +132,9 @@ int main(void)
|
|||
player_f->combo_next = 0;
|
||||
player_f->combo_delay = fix(0);
|
||||
player_f->enemy_data = NULL;
|
||||
/* F1: Dash */
|
||||
player_f->actions_cooldown_total[1] = fix(1.0);
|
||||
player_f->actions_cooldown[1] = fix(0.0);
|
||||
/* Initialize stats. This will level up to level 1 */
|
||||
player_add_xp(&player_data, 0);
|
||||
player_f->HP = player_f->HP_max;
|
||||
|
@ -261,10 +263,6 @@ int main(void)
|
|||
dprint(3, 145, C_WHITE, "Dash duration: %g s",
|
||||
f2double(player_data.mechanical_limits.dash_duration));
|
||||
dprint(15, 160, gray, "[)] -/+ [sin]");
|
||||
|
||||
dprint(3, 175, C_WHITE, "Dash cooldown: %g s",
|
||||
f2double(player_data.mechanical_limits.dash_cooldown));
|
||||
dprint(15, 190, gray, "[,] -/+ [cos]");
|
||||
}
|
||||
|
||||
if(debug.show_path) {
|
||||
|
@ -416,14 +414,6 @@ int main(void)
|
|||
player_data.mechanical_limits.dash_duration = 0;
|
||||
}
|
||||
|
||||
if(ev.key == KEY_COS)
|
||||
player_data.mechanical_limits.dash_cooldown += fix(1) / 8;
|
||||
if(ev.key == KEY_COMMA) {
|
||||
player_data.mechanical_limits.dash_cooldown -= fix(1) / 8;
|
||||
if(player_data.mechanical_limits.dash_cooldown <= 0)
|
||||
player_data.mechanical_limits.dash_cooldown = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if(ev.key == KEY_PLUS)
|
||||
camera_zoom(c, c->zoom + 1);
|
||||
|
@ -464,9 +454,12 @@ int main(void)
|
|||
if(keydown(KEY_LEFT)) dir = LEFT;
|
||||
if(keydown(KEY_RIGHT)) dir = RIGHT;
|
||||
|
||||
if(keydown(KEY_F1) && !keydown(KEY_VARS)) {
|
||||
if(keydown(KEY_F1) && !keydown(KEY_VARS)
|
||||
&& player_f->actions_cooldown[1] == 0) {
|
||||
int dash_dir = (dir >= 0) ? dir : player_p->facing;
|
||||
mechanical_dash(player, dash_dir);
|
||||
player_f->actions_cooldown[1] =
|
||||
player_f->actions_cooldown_total[1];
|
||||
}
|
||||
mechanical_move4(player, dir, dt, game.map);
|
||||
|
||||
|
@ -570,7 +563,13 @@ int main(void)
|
|||
game_update_particles(&game, dt);
|
||||
// TODO: Kill out-of-bounds entities
|
||||
game_remove_dead_entities(&game);
|
||||
|
||||
/* Update combo and action cooldowns */
|
||||
player_f->combo_delay -= dt;
|
||||
for(int i = 0; i < 5; i++) {
|
||||
fixed_t *cd = &player_f->actions_cooldown[i];
|
||||
*cd = max(*cd - dt, fix(0.0));
|
||||
}
|
||||
|
||||
/* Reset default anims */
|
||||
if(!player_v->anim.frame)
|
||||
|
|
14
src/render.c
14
src/render.c
|
@ -391,7 +391,6 @@ void render_game(game_t const *g, bool show_hitboxes)
|
|||
dfont(&font_rogue);
|
||||
|
||||
fighter_t *player_f = getcomp(g->player, fighter);
|
||||
mechanical_t *player_m = getcomp(g->player, mechanical);
|
||||
|
||||
/* Render life bar */
|
||||
extern bopti_image_t img_hud_life;
|
||||
|
@ -413,17 +412,10 @@ void render_game(game_t const *g, bool show_hitboxes)
|
|||
static const int skill_size = 23;
|
||||
static const int skill_box_size = 27;
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
for(int i = 0; i < 4; i++) {
|
||||
/* Activity and cooldown */
|
||||
fixed_t cooldown_total=0, cooldown_remaining=0;
|
||||
if(i == 0 && player_m->dash < 0) {
|
||||
cooldown_total = player_m->limits->dash_cooldown;
|
||||
cooldown_remaining = -player_m->dash;
|
||||
}
|
||||
else if(i > 0) {
|
||||
cooldown_total = player_f->actions_cooldown_total[i-1];
|
||||
cooldown_remaining = player_f->actions_cooldown[i-1];
|
||||
}
|
||||
fixed_t cooldown_total = player_f->actions_cooldown_total[i+1];
|
||||
fixed_t cooldown_remaining = player_f->actions_cooldown[i+1];
|
||||
|
||||
int x = 31 + 48*i + 64*(i>=3);
|
||||
int y = DHEIGHT - 33;
|
||||
|
|
Loading…
Reference in New Issue