Add scaling

master
En Yi 2020-01-13 21:45:17 +08:00
parent 1353bd4084
commit 3480c4cdd3
3 changed files with 32 additions and 3 deletions

View File

@ -12,6 +12,10 @@ struct kinematic_obj
{
Rectangle rect;
Vector2 velocity;
double scale;
double set_scale;
int ori_width;
int ori_height;
};
struct kinematic_obj_node

View File

@ -4,7 +4,11 @@ extern struct kinematic_obj_node *kinematic_HEAD;
struct kinematic_obj init_kinematic_obj(int width, int height){
struct kinematic_obj obj = {
.velocity = {0.0f,0.0f},
.rect = {0,0,width,height}
.rect = {0,0,width,height},
.scale = 1.0,
.set_scale = 1.0,
.ori_width = width,
.ori_height = height
};
return obj;
@ -30,10 +34,18 @@ void move(struct kinematic_obj *obj, Vector2 acceleration){
if (CheckCollisionRecs(obj->rect, current->obj->rect)){
collide_rect = GetCollisionRec(obj->rect, current->obj->rect);
if(collide_rect.width < collide_rect.height){
obj->rect.x -= sign(obj->velocity.x) * collide_rect.width;
if (!place_meeting(obj, (Vector2){-collide_rect.width,0})){
obj->rect.x -= collide_rect.width;
}else{
obj->rect.x += collide_rect.width;
}
obj->velocity.x = 0;
}else{
obj->rect.y -= sign(obj->velocity.y) * collide_rect.height;
if (!place_meeting(obj, (Vector2){0,-collide_rect.height})){
obj->rect.y -= collide_rect.height;
}else{
obj->rect.y += collide_rect.height;
}
obj->velocity.y = 0;
}
}

View File

@ -139,6 +139,19 @@ void player_input_check(struct player_obj *player){
break;
}
// TODO: Add a key to resize the rect and see what happens?
if (IsKeyDown(KEY_P)){
player->kinematic.set_scale = 1.2;
}
else if (IsKeyDown(KEY_O)){
player->kinematic.set_scale = 0.85;
}else{
player->kinematic.set_scale = 1;
}
approach(&player->kinematic.scale, player->kinematic.set_scale, 0.5);
player->kinematic.rect.width = player->kinematic.scale * player->kinematic.ori_width;
player->kinematic.rect.height = player->kinematic.scale * player->kinematic.ori_height;
if (IsKeyPressed(JUMP) && jumps > 0){
player->state = JUMP_SQUAT;
allow_friction = true;