From 3480c4cdd31489de67f3fdb6fa0ec75321fd97b1 Mon Sep 17 00:00:00 2001 From: En Yi Date: Mon, 13 Jan 2020 21:45:17 +0800 Subject: [PATCH] Add scaling --- include/header.h | 4 ++++ obj/kinematics.c | 18 +++++++++++++++--- obj/player.c | 13 +++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/include/header.h b/include/header.h index 877d8f3..695c44b 100644 --- a/include/header.h +++ b/include/header.h @@ -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 diff --git a/obj/kinematics.c b/obj/kinematics.c index b323af2..38c3411 100644 --- a/obj/kinematics.c +++ b/obj/kinematics.c @@ -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; } } diff --git a/obj/player.c b/obj/player.c index ef0b73d..e393eac 100644 --- a/obj/player.c +++ b/obj/player.c @@ -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;