Add simple dash

master
En Yi 2020-02-01 17:30:16 +08:00
parent 06460d6636
commit acd3fc114f
3 changed files with 31 additions and 3 deletions

View File

@ -5,6 +5,8 @@
#define BEZIER_POINTS 5
#define LEFT KEY_LEFT
#define RIGHT KEY_RIGHT
#define DOWN KEY_DOWN
#define UP KEY_UP
#define JUMP KEY_SPACE
#define DASH KEY_Z
@ -78,7 +80,7 @@ void scale_rect(struct kinematic_obj *obj);
void adjust_hitbox(struct kinematic_obj *obj);
// Math functions, math.c
long mag(Vector2 vec);
double mag(Vector2 vec);
int sign(float val);
Vector2 dir(Vector2 vec);
void approach(double *val, double target, float f);

View File

@ -19,6 +19,7 @@ static enum PLAYER_STATE state_buffer = IDLE;
const unsigned int run_start_frames = 10;
const unsigned int jump_squat_frames = 4;
const unsigned int land_lag_frames = 6;
const unsigned int dash_time_frames = 5;
unsigned int PLAYER_SIZE = 30;
@ -153,6 +154,7 @@ void player_input_check(struct player_obj *player){
player->kinematic.dim_reduction[3] = 0;
player->kinematic.set_dim_reduction[3] = 0;
player->kinematic.dim_reduction[1] = PLAYER_SIZE;
player->kinematic.set_dim_reduction[1] = 0;
on_ground = true;
state_buffer = IDLE;
}
@ -181,7 +183,10 @@ void player_input_check(struct player_obj *player){
break;
case DASHING:
++frame_counter;
if (frame_counter > dash_time_frames){
player->state = JUMPING;
}
break;
case DASH_END:
@ -197,6 +202,27 @@ void player_input_check(struct player_obj *player){
short_hop = false;
--jumps;
}
if (IsKeyPressed(DASH)){
player->kinematic.velocity.x = 0;
if (IsKeyDown(RIGHT))
++player->kinematic.velocity.x;
if (IsKeyDown(LEFT))
--player->kinematic.velocity.x;
player->kinematic.velocity.y = 0;
if (IsKeyDown(DOWN))
++player->kinematic.velocity.y;
if (IsKeyDown(UP))
--player->kinematic.velocity.y;
if (player->kinematic.velocity.x == 0 && player->kinematic.velocity.y == 0)
player->kinematic.velocity.x = sign(player->kinematic.velocity.x);
double m = mag(player->kinematic.velocity);
player->kinematic.velocity.x *= 500/m;
player->kinematic.velocity.y *= 500/m;
player->state = DASHING;
}
// Add mercy jump here
if (on_ground == true && !place_meeting(&player->kinematic, (Vector2){0,1}) && player->state != JUMP_SQUAT){

View File

@ -1,7 +1,7 @@
#include "header.h"
#include <math.h>
long mag(Vector2 vec){
double mag(Vector2 vec){
return sqrt(vec.x*vec.x + vec.y*vec.y);
}