Change dashing end state
parent
e8dbdc68b3
commit
b031b26ed8
|
@ -126,4 +126,5 @@ struct player_obj init_player_obj();
|
||||||
void player_input_check(struct player_obj *player);
|
void player_input_check(struct player_obj *player);
|
||||||
|
|
||||||
//Debug stuff, debug.c
|
//Debug stuff, debug.c
|
||||||
void state_string(char *str, enum PLAYER_STATE state);
|
void state_string(char *str, enum PLAYER_STATE state);
|
||||||
|
void display_input(char *dir);
|
8
main.c
8
main.c
|
@ -17,6 +17,11 @@
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
/* Issues:
|
||||||
|
Playing with a USB keyboard: Cannot handle simultaneous key input. I think this is more
|
||||||
|
of a GLFW issue.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "header.h"
|
#include "header.h"
|
||||||
extern struct kinematic_obj_node *kinematic_HEAD;
|
extern struct kinematic_obj_node *kinematic_HEAD;
|
||||||
int PLAYER_ACCEL = 1500;
|
int PLAYER_ACCEL = 1500;
|
||||||
|
@ -31,6 +36,7 @@ int main()
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
char current_state[20];
|
char current_state[20];
|
||||||
char current_spd[50];
|
char current_spd[50];
|
||||||
|
//char dir[7];
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib");
|
InitWindow(screenWidth, screenHeight, "raylib");
|
||||||
|
|
||||||
|
@ -104,6 +110,8 @@ int main()
|
||||||
DrawFPS(0,0);
|
DrawFPS(0,0);
|
||||||
state_string(current_state, player.state);
|
state_string(current_state, player.state);
|
||||||
DrawText(current_state, 250, 0, 12, BLACK);
|
DrawText(current_state, 250, 0, 12, BLACK);
|
||||||
|
//display_input(dir);
|
||||||
|
//DrawText(dir, 0, 50, 12, BLACK);
|
||||||
sprintf(current_spd, "Velocity: {%.2f,%.2f}", player.kinematic.velocity.x,player.kinematic.velocity.y);
|
sprintf(current_spd, "Velocity: {%.2f,%.2f}", player.kinematic.velocity.x,player.kinematic.velocity.y);
|
||||||
DrawText(current_spd, 350, 0, 12, BLACK);
|
DrawText(current_spd, 350, 0, 12, BLACK);
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
41
obj/player.c
41
obj/player.c
|
@ -27,7 +27,7 @@ static Vector2 dash_vec = (Vector2){0.0, 0.0};
|
||||||
|
|
||||||
const unsigned int run_start_frames = 10;
|
const unsigned int run_start_frames = 10;
|
||||||
const unsigned int jump_squat_frames = 4;
|
const unsigned int jump_squat_frames = 4;
|
||||||
const unsigned int land_lag_frames = 6;
|
const unsigned int land_lag_frames = 2;
|
||||||
const unsigned int dash_time_frames = 8;
|
const unsigned int dash_time_frames = 8;
|
||||||
const unsigned int afterimage_frames = 10;
|
const unsigned int afterimage_frames = 10;
|
||||||
|
|
||||||
|
@ -126,9 +126,6 @@ void player_input_check(struct player_obj *player){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case TURN_AROUND:
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case JUMP_SQUAT:
|
case JUMP_SQUAT:
|
||||||
player->kinematic.set_dim_reduction[1] = 10;
|
player->kinematic.set_dim_reduction[1] = 10;
|
||||||
|
@ -188,29 +185,24 @@ void player_input_check(struct player_obj *player){
|
||||||
else
|
else
|
||||||
player->state = IDLE;
|
player->state = IDLE;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case DASH_START:
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case DASHING:
|
case DASHING:
|
||||||
player->kinematic.velocity.x = dash_vec.x;
|
player->kinematic.velocity.x = dash_vec.x;
|
||||||
player->kinematic.velocity.y = dash_vec.y;
|
player->kinematic.velocity.y = dash_vec.y;
|
||||||
++frame_counter;
|
++frame_counter;
|
||||||
if (frame_counter > dash_time_frames){
|
if (frame_counter > dash_time_frames){
|
||||||
player->kinematic.velocity.x *= 0.7;
|
player->kinematic.velocity.x *= 0.8;
|
||||||
player->kinematic.velocity.y *= 0.7;
|
player->kinematic.velocity.y *= 0.8;
|
||||||
if (!place_meeting(&player->kinematic, (Vector2){0,1})){
|
if (!on_ground){
|
||||||
player->state = JUMPING;
|
player->state = JUMPING;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
player->state = FALLING;
|
player->state = RUNNING;
|
||||||
dash_count = 1;
|
dash_count = 1;
|
||||||
|
jumps = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DASH_END:
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This accounts for player leaving the ground without jumping (dashing or falling)
|
// This accounts for player leaving the ground without jumping (dashing or falling)
|
||||||
|
@ -235,25 +227,19 @@ void player_input_check(struct player_obj *player){
|
||||||
|
|
||||||
// Air friction is less than ground friction
|
// Air friction is less than ground friction
|
||||||
if (on_ground == true)
|
if (on_ground == true)
|
||||||
accel.x -= player->kinematic.velocity.x * 7.0;
|
accel.x -= player->kinematic.velocity.x * 6.0;
|
||||||
else
|
else
|
||||||
accel.x -= player->kinematic.velocity.x * 1.0;
|
accel.x -= player->kinematic.velocity.x * 3.0;
|
||||||
|
|
||||||
// Handle wall jumping
|
// Handle wall jumping
|
||||||
// TODO: define the wall jump values
|
// TODO: define the wall jump values
|
||||||
if (IsKeyPressed(JUMP)){
|
if (IsKeyPressed(JUMP)){
|
||||||
if (on_ground == false){
|
if (on_ground == false){
|
||||||
if (place_meeting(&player->kinematic, (Vector2){-8,0})){
|
bool left_check = place_meeting(&player->kinematic, (Vector2){-8,0});
|
||||||
|
bool right_check = place_meeting(&player->kinematic, (Vector2){8,0});
|
||||||
|
if (left_check || right_check){
|
||||||
player->kinematic.velocity.y = -350;
|
player->kinematic.velocity.y = -350;
|
||||||
player->kinematic.velocity.x = 400;
|
player->kinematic.velocity.x = left_check? 400 : -400;
|
||||||
player->state = JUMPING;
|
|
||||||
afterimage_fcounter = 5;
|
|
||||||
afterimage_c.r = 128;
|
|
||||||
afterimage_c.g = 128;
|
|
||||||
afterimage_c.b = 128;
|
|
||||||
}else if (place_meeting(&player->kinematic, (Vector2){8, 0})){
|
|
||||||
player->kinematic.velocity.y = -350;
|
|
||||||
player->kinematic.velocity.x = -400;
|
|
||||||
player->state = JUMPING;
|
player->state = JUMPING;
|
||||||
afterimage_fcounter = 5;
|
afterimage_fcounter = 5;
|
||||||
afterimage_c.r = 128;
|
afterimage_c.r = 128;
|
||||||
|
@ -281,6 +267,8 @@ void player_input_check(struct player_obj *player){
|
||||||
// Default a direction
|
// Default a direction
|
||||||
if (dash_vec.x == 0 && dash_vec.y == 0){
|
if (dash_vec.x == 0 && dash_vec.y == 0){
|
||||||
dash_vec.x = sign(player->kinematic.velocity.x);
|
dash_vec.x = sign(player->kinematic.velocity.x);
|
||||||
|
if (place_meeting(&player->kinematic, (Vector2){dash_vec.x,0}))
|
||||||
|
dash_vec.y = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the scalar value, normalised to the unit direction
|
// Apply the scalar value, normalised to the unit direction
|
||||||
|
@ -296,6 +284,7 @@ void player_input_check(struct player_obj *player){
|
||||||
player->state = DASHING;
|
player->state = DASHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All velocity modification must be done before calling the move function
|
||||||
move(&player->kinematic, accel);
|
move(&player->kinematic, accel);
|
||||||
|
|
||||||
// Handle jumping
|
// Handle jumping
|
||||||
|
|
|
@ -15,4 +15,11 @@ void state_string(char *str, enum PLAYER_STATE state){
|
||||||
case RUN_END: sprintf(str, "%s", "RUN_END");break;
|
case RUN_END: sprintf(str, "%s", "RUN_END");break;
|
||||||
case TURN_AROUND: sprintf(str, "%s", "TURN_AROUND");break;
|
case TURN_AROUND: sprintf(str, "%s", "TURN_AROUND");break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void display_input(char *dir){
|
||||||
|
sprintf(dir, " %c \n%c%c%c", IsKeyDown(UP)? '|':' ',
|
||||||
|
IsKeyDown(LEFT)? '-':' ',
|
||||||
|
IsKeyDown(DOWN)? '|':' ',
|
||||||
|
IsKeyDown(RIGHT)? '-':' ');
|
||||||
}
|
}
|
Loading…
Reference in New Issue