Prepare linked list for afterimages
parent
7c9045af7e
commit
c1e58bb6c3
|
@ -10,6 +10,18 @@
|
|||
#define JUMP KEY_SPACE
|
||||
#define DASH KEY_Z
|
||||
|
||||
struct afterImage
|
||||
{
|
||||
Vector2 top_vertices[BEZIER_POINTS+1];
|
||||
Vector2 bottom_vertices[BEZIER_POINTS+1];
|
||||
Vector2 left_vertices[BEZIER_POINTS+1];
|
||||
Vector2 right_vertices[BEZIER_POINTS+1];
|
||||
|
||||
float opacity;
|
||||
struct afterImage *prev;
|
||||
struct afterImage *next;
|
||||
};
|
||||
|
||||
struct kinematic_obj
|
||||
{
|
||||
Rectangle rect;
|
||||
|
@ -48,6 +60,8 @@ struct player_obj
|
|||
struct kinematic_obj kinematic;
|
||||
enum PLAYER_STATE state;
|
||||
struct squishy_square *image;
|
||||
struct afterImage *after_img_head;
|
||||
struct afterImage *after_img_tail;
|
||||
};
|
||||
|
||||
extern unsigned int PLAYER_SIZE;
|
||||
|
@ -71,6 +85,8 @@ struct squishy_square
|
|||
Vector2 right_vertices[BEZIER_POINTS+1];
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Object functions, kinematics.c
|
||||
struct kinematic_obj init_kinematic_obj(int width, int height);
|
||||
void move(struct kinematic_obj *obj, Vector2 acceleration);
|
||||
|
@ -91,6 +107,9 @@ void create_list(void);
|
|||
void add_node(struct kinematic_obj *obj);
|
||||
//struct kinematic_obj_node **get_list();
|
||||
void free_list(void);
|
||||
void create_afterimage(struct player_obj *player);
|
||||
void remove_last_afterimage(struct player_obj *player);
|
||||
void free_afterimages(struct player_obj *player);
|
||||
|
||||
// Squishy Square functions, squishy.c
|
||||
struct squishy_square init_squishy_square(struct kinematic_obj *parent, Color color);
|
||||
|
|
5
main.c
5
main.c
|
@ -41,7 +41,9 @@ int main()
|
|||
|
||||
struct player_obj player = {
|
||||
.kinematic = init_kinematic_obj(PLAYER_SIZE, PLAYER_SIZE),
|
||||
.state = IDLE
|
||||
.state = IDLE,
|
||||
.after_img_head = NULL,
|
||||
.after_img_tail = NULL
|
||||
};
|
||||
|
||||
struct kinematic_obj tile = init_kinematic_obj(900, 100);
|
||||
|
@ -100,6 +102,7 @@ int main()
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
free_list();
|
||||
free_afterimages(&player);
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ static unsigned int jumps = 1;
|
|||
static unsigned int frame_counter = 0;
|
||||
static int run_dir = 1;
|
||||
static enum PLAYER_STATE state_buffer = IDLE;
|
||||
static unsigned int dash_count = 1;
|
||||
|
||||
const unsigned int run_start_frames = 10;
|
||||
const unsigned int jump_squat_frames = 4;
|
||||
|
@ -169,6 +170,7 @@ void player_input_check(struct player_obj *player){
|
|||
}
|
||||
else{
|
||||
jumps = 1;
|
||||
dash_count = 1;
|
||||
frame_counter = 0;
|
||||
if (state_buffer == JUMP_SQUAT){
|
||||
player->state = state_buffer;
|
||||
|
@ -204,7 +206,7 @@ void player_input_check(struct player_obj *player){
|
|||
short_hop = false;
|
||||
--jumps;
|
||||
}
|
||||
if (IsKeyPressed(DASH)){
|
||||
if (IsKeyPressed(DASH) && dash_count > 0){
|
||||
// Determine the direction of dashing
|
||||
Vector2 dash_dir = (Vector2){0.0, 0.0};
|
||||
if (IsKeyDown(RIGHT))
|
||||
|
@ -230,6 +232,7 @@ void player_input_check(struct player_obj *player){
|
|||
//if (player->kinematic.velocity.y == 0)
|
||||
player->kinematic.velocity.y = dash_dir.y * DASH_SPD/m;
|
||||
allow_friction = false;
|
||||
--dash_count;
|
||||
player->state = DASHING;
|
||||
}
|
||||
|
||||
|
@ -252,6 +255,4 @@ void player_input_check(struct player_obj *player){
|
|||
}
|
||||
|
||||
move(&player->kinematic, accel);
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -28,8 +28,62 @@ void free_list(){
|
|||
struct kinematic_obj_node *next;
|
||||
while(current){
|
||||
next = current->next;
|
||||
current->next = NULL;
|
||||
free(current);
|
||||
current = next;
|
||||
}
|
||||
kinematic_HEAD = NULL;
|
||||
}
|
||||
|
||||
void create_afterimage(struct player_obj *player){
|
||||
struct afterImage *img = malloc(sizeof(struct afterImage));
|
||||
if (img){
|
||||
for (int i=0;i<=BEZIER_POINTS;++i){
|
||||
img->top_vertices[i] = player->image->top_vertices[i];
|
||||
img->bottom_vertices[i] = player->image->bottom_vertices[i];
|
||||
img->left_vertices[i] = player->image->left_vertices[i];
|
||||
img->right_vertices[i] = player->image->right_vertices[i];
|
||||
}
|
||||
img->opacity = 1.0;
|
||||
img->prev = NULL;
|
||||
if (player->after_img_head == NULL){
|
||||
img->next = NULL;
|
||||
player->after_img_head = img;
|
||||
player->after_img_tail = img;
|
||||
}else{
|
||||
img->next = player->after_img_head;
|
||||
player->after_img_head->prev = img;
|
||||
player->after_img_head = img;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void remove_last_afterimage(struct player_obj *player){
|
||||
struct afterImage *last;
|
||||
if (player->after_img_tail != NULL){
|
||||
if (player->after_img_tail->opacity <= 0){
|
||||
last = player->after_img_tail;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void free_afterimages(struct player_obj *player){
|
||||
struct afterImage *current = player->after_img_head;
|
||||
struct afterImage *next;
|
||||
while(current != NULL){
|
||||
next = current->next;
|
||||
current->next = NULL;
|
||||
current->prev = NULL;
|
||||
free(current);
|
||||
current = next;
|
||||
}
|
||||
player->after_img_head = NULL;
|
||||
player->after_img_tail = NULL;
|
||||
}
|
Loading…
Reference in New Issue