More Squishyness

master
En Yi 2020-01-31 17:03:05 +08:00
parent f3a31cef50
commit 3754f3719a
2 changed files with 38 additions and 27 deletions

View File

@ -67,14 +67,48 @@ void player_input_check(struct player_obj *player){
accel.x = PLAYER_ACCEL*(IsKeyDown(KEY_RIGHT)-IsKeyDown(KEY_LEFT)); accel.x = PLAYER_ACCEL*(IsKeyDown(KEY_RIGHT)-IsKeyDown(KEY_LEFT));
} }
} }
set_squish_target_offset(player->image, 0, 0);
set_squish_target_offset(player->image, 2, 0);
if (player->kinematic.velocity.x == 0){
if (run_dir == 1){
player->kinematic.dim_reduction[0] = 20;
set_squish_target_offset(player->image, 0, 15);
}else{
player->kinematic.dim_reduction[2] = 20;
set_squish_target_offset(player->image, 2, 15);
}
}
break; break;
case RUN_END: case RUN_END:
if(player->kinematic.velocity.x < 10 && player->kinematic.velocity.x > -10){ if(player->kinematic.velocity.x < 10 && player->kinematic.velocity.x > -10){
set_squish_target_offset(player->image, 2, 0);
player->kinematic.dim_reduction[2] = 0;
set_squish_target_offset(player->image, 0, 0);
player->kinematic.dim_reduction[0] = 0;
if(IsKeyDown(LEFT) || IsKeyDown(RIGHT)){ if(IsKeyDown(LEFT) || IsKeyDown(RIGHT)){
player->state = RUNNING; player->state = RUNNING;
}else{ }else{
player->state = IDLE; player->state = IDLE;
} }
}else{
//Skidding
if (player->kinematic.velocity.x > 0){
if (!IsKeyDown(RIGHT)){
set_squish_target_offset(player->image, 0, 15);
player->kinematic.dim_reduction[0] = 10;
}else{
set_squish_target_offset(player->image, 0, 0);
player->kinematic.dim_reduction[0] = 0;
}
}else{
if (!IsKeyDown(LEFT)){
set_squish_target_offset(player->image, 2, 15);
player->kinematic.dim_reduction[2] = 10;
}else{
set_squish_target_offset(player->image, 2, 0);
player->kinematic.dim_reduction[2] = 0;
}
}
} }
break; break;
case TURN_AROUND: case TURN_AROUND:
@ -183,30 +217,5 @@ void player_input_check(struct player_obj *player){
move(&player->kinematic, accel); move(&player->kinematic, accel);
//Skidding
if (on_ground == true){
if (player->kinematic.velocity.x > 3){
if (!IsKeyDown(RIGHT)){
set_squish_target_offset(player->image, 0, 15);
player->kinematic.dim_reduction[0] = 10;
}else{
set_squish_target_offset(player->image, 0, 0);
player->kinematic.dim_reduction[0] = 0;
}
}else if (player->kinematic.velocity.x < -3){
if (!IsKeyDown(LEFT)){
set_squish_target_offset(player->image, 2, 15);
player->kinematic.dim_reduction[2] = 10;
}else{
set_squish_target_offset(player->image, 2, 0);
player->kinematic.dim_reduction[2] = 0;
}
}else{
player->kinematic.velocity.x = 0;
set_squish_target_offset(player->image, 2, 0);
player->kinematic.dim_reduction[2] = 0;
set_squish_target_offset(player->image, 0, 0);
player->kinematic.dim_reduction[0] = 0;
}
}
} }

View File

@ -1,9 +1,10 @@
#include "header.h" #include "header.h"
#include <rlgl.h> #include <rlgl.h>
#include <math.h>
#define INTERP_FACTOR 0.2 #define INTERP_FACTOR 0.2
#define OFFSET_VALUE 20 #define OFFSET_VALUE 20
#define SHEAR_NORMALISE 100
float shear_mat[16] = {1.0, 0.0, 0, 0, float shear_mat[16] = {1.0, 0.0, 0, 0,
0.1, 1.0, 0, 0, 0.1, 1.0, 0, 0,
0, 0, 1.0, 0, 0, 0, 1.0, 0,
@ -123,6 +124,7 @@ void calc_offsets(struct squishy_square *square){
void draw_squishy(struct squishy_square *square){ void draw_squishy(struct squishy_square *square){
rlPushMatrix(); rlPushMatrix();
// TODO: Need a correction term to put the square in the box???? // TODO: Need a correction term to put the square in the box????
shear_mat[4] = -square->parent->velocity.x / 600;
rlMultMatrixf(shear_mat); rlMultMatrixf(shear_mat);
translate_mat[12] = square->center.x; translate_mat[12] = square->center.x;
translate_mat[13] = square->center.y; translate_mat[13] = square->center.y;