Integrate afterimages
parent
c1e58bb6c3
commit
da1f38cc88
|
@ -12,6 +12,8 @@
|
|||
|
||||
struct afterImage
|
||||
{
|
||||
Vector2 velocity;
|
||||
Vector2 pos;
|
||||
Vector2 top_vertices[BEZIER_POINTS+1];
|
||||
Vector2 bottom_vertices[BEZIER_POINTS+1];
|
||||
Vector2 left_vertices[BEZIER_POINTS+1];
|
||||
|
@ -116,6 +118,7 @@ struct squishy_square init_squishy_square(struct kinematic_obj *parent, Color co
|
|||
void update_squishy(struct squishy_square *square);
|
||||
void draw_squishy(struct squishy_square *square);
|
||||
void set_squish_target_offset(struct squishy_square *square, unsigned int dir, int val);
|
||||
void draw_afterimages(struct player_obj *player);
|
||||
|
||||
//Player stuff, player.c
|
||||
struct player_obj init_player_obj();
|
||||
|
|
2
main.c
2
main.c
|
@ -81,6 +81,7 @@ int main()
|
|||
|
||||
ClearBackground(RAYWHITE);
|
||||
draw_squishy(&sqr);
|
||||
draw_afterimages(&player);
|
||||
|
||||
BeginMode2D(camera);
|
||||
current = kinematic_HEAD;
|
||||
|
@ -96,6 +97,7 @@ int main()
|
|||
EndMode2D();
|
||||
|
||||
EndDrawing();
|
||||
remove_last_afterimage(&player);
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
|
36
obj/player.c
36
obj/player.c
|
@ -17,11 +17,12 @@ static unsigned int frame_counter = 0;
|
|||
static int run_dir = 1;
|
||||
static enum PLAYER_STATE state_buffer = IDLE;
|
||||
static unsigned int dash_count = 1;
|
||||
static Vector2 dash_vec = (Vector2){0.0, 0.0};
|
||||
|
||||
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 = 3;
|
||||
const unsigned int dash_time_frames = 5;
|
||||
|
||||
unsigned int PLAYER_SIZE = 30;
|
||||
|
||||
|
@ -186,10 +187,13 @@ void player_input_check(struct player_obj *player){
|
|||
|
||||
break;
|
||||
case DASHING:
|
||||
create_afterimage(player);
|
||||
player->kinematic.velocity.x = dash_vec.x;
|
||||
player->kinematic.velocity.y = dash_vec.y;
|
||||
++frame_counter;
|
||||
if (frame_counter > dash_time_frames){
|
||||
player->state = JUMPING;
|
||||
allow_friction = true;
|
||||
//allow_friction = true;
|
||||
}
|
||||
break;
|
||||
case DASH_END:
|
||||
|
@ -208,31 +212,32 @@ void player_input_check(struct player_obj *player){
|
|||
}
|
||||
if (IsKeyPressed(DASH) && dash_count > 0){
|
||||
// Determine the direction of dashing
|
||||
Vector2 dash_dir = (Vector2){0.0, 0.0};
|
||||
dash_vec.x = 0;
|
||||
if (IsKeyDown(RIGHT))
|
||||
++dash_dir.x;
|
||||
++dash_vec.x;
|
||||
if (IsKeyDown(LEFT))
|
||||
--dash_dir.x;
|
||||
--dash_vec.x;
|
||||
|
||||
dash_vec.y = 0;
|
||||
//if (player->kinematic.velocity.y > 0)
|
||||
if (IsKeyDown(DOWN))
|
||||
++dash_dir.y;
|
||||
++dash_vec.y;
|
||||
if (IsKeyDown(UP))
|
||||
--dash_dir.y;
|
||||
--dash_vec.y;
|
||||
|
||||
// Default a direction
|
||||
if (dash_dir.x == 0 && dash_dir.y == 0){
|
||||
dash_dir.x = sign(player->kinematic.velocity.x);
|
||||
|
||||
if (dash_vec.x == 0 && dash_vec.y == 0){
|
||||
dash_vec.x = sign(player->kinematic.velocity.x);
|
||||
}
|
||||
|
||||
// Apply the scalar value, normalised to the unit direction
|
||||
double m = mag(dash_dir);
|
||||
player->kinematic.velocity.x = dash_dir.x * DASH_SPD/m;
|
||||
double m = mag(dash_vec);
|
||||
dash_vec.x = dash_vec.x * DASH_SPD/m;
|
||||
//if (player->kinematic.velocity.y == 0)
|
||||
player->kinematic.velocity.y = dash_dir.y * DASH_SPD/m;
|
||||
allow_friction = false;
|
||||
dash_vec.y = dash_vec.y * DASH_SPD/m;
|
||||
//allow_friction = false;
|
||||
--dash_count;
|
||||
frame_counter=0;
|
||||
player->state = DASHING;
|
||||
}
|
||||
|
||||
|
@ -250,7 +255,8 @@ void player_input_check(struct player_obj *player){
|
|||
else
|
||||
accel.x -= player->kinematic.velocity.x * 1.0;
|
||||
|
||||
if (player->state != DASHING && !place_meeting(&player->kinematic, (Vector2){0,1}) ){
|
||||
//if (player->state != DASHING && !place_meeting(&player->kinematic, (Vector2){0,1}) ){
|
||||
if (!place_meeting(&player->kinematic, (Vector2){0,1}) ){
|
||||
accel.y = GRAV;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,6 +140,30 @@ void draw_squishy(struct squishy_square *square){
|
|||
rlPopMatrix();
|
||||
}
|
||||
|
||||
void draw_afterimages(struct player_obj *player){
|
||||
struct afterImage *current = player->after_img_head;
|
||||
int i;
|
||||
while (current != NULL){
|
||||
rlPushMatrix();
|
||||
shear_mat[4] = -current->velocity.x / 600;
|
||||
rlMultMatrixf(shear_mat);
|
||||
translate_mat[12] = current->pos.x;
|
||||
translate_mat[13] = current->pos.y;
|
||||
rlMultMatrixf(translate_mat);
|
||||
Color c = (Color){ 0, 0, 0, 255 * current->opacity};
|
||||
for(i=0;i<BEZIER_POINTS;++i){
|
||||
DrawTriangle(current->top_vertices[i], (Vector2){0,0}, current->top_vertices[i+1], c);
|
||||
DrawTriangle(current->bottom_vertices[i], (Vector2){0,0}, current->bottom_vertices[i+1], c);
|
||||
DrawTriangle(current->left_vertices[i], (Vector2){0,0}, current->left_vertices[i+1], c);
|
||||
DrawTriangle(current->right_vertices[i], (Vector2){0,0}, current->right_vertices[i+1], c);
|
||||
}
|
||||
current->opacity -= 0.1;
|
||||
rlPopMatrix();
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void three_point_beizer(Vector2 start, Vector2 mid, Vector2 end, Vector2* arr){
|
||||
/* Generate the vertices for a beizer curve
|
||||
*/
|
||||
|
|
|
@ -44,6 +44,8 @@ void create_afterimage(struct player_obj *player){
|
|||
img->left_vertices[i] = player->image->left_vertices[i];
|
||||
img->right_vertices[i] = player->image->right_vertices[i];
|
||||
}
|
||||
img->pos = (Vector2){player->image->center.x, player->image->center.y};
|
||||
img->velocity = (Vector2){player->kinematic.velocity.x, player->kinematic.velocity.y};
|
||||
img->opacity = 1.0;
|
||||
img->prev = NULL;
|
||||
if (player->after_img_head == NULL){
|
||||
|
@ -66,11 +68,13 @@ void remove_last_afterimage(struct player_obj *player){
|
|||
player->after_img_tail = player->after_img_tail->prev;
|
||||
last->prev = NULL;
|
||||
free(last);
|
||||
player->after_img_tail->next = NULL;
|
||||
}
|
||||
// This happens if the last tail is the head
|
||||
if (player->after_img_tail == NULL)
|
||||
player->after_img_head == NULL;
|
||||
if (player->after_img_tail == NULL){
|
||||
player->after_img_head = NULL;
|
||||
}else{
|
||||
player->after_img_tail->next = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,4 +90,4 @@ void free_afterimages(struct player_obj *player){
|
|||
}
|
||||
player->after_img_head = NULL;
|
||||
player->after_img_tail = NULL;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue