Add scaling
parent
1353bd4084
commit
3480c4cdd3
|
@ -12,6 +12,10 @@ struct kinematic_obj
|
||||||
{
|
{
|
||||||
Rectangle rect;
|
Rectangle rect;
|
||||||
Vector2 velocity;
|
Vector2 velocity;
|
||||||
|
double scale;
|
||||||
|
double set_scale;
|
||||||
|
int ori_width;
|
||||||
|
int ori_height;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct kinematic_obj_node
|
struct kinematic_obj_node
|
||||||
|
|
|
@ -4,7 +4,11 @@ extern struct kinematic_obj_node *kinematic_HEAD;
|
||||||
struct kinematic_obj init_kinematic_obj(int width, int height){
|
struct kinematic_obj init_kinematic_obj(int width, int height){
|
||||||
struct kinematic_obj obj = {
|
struct kinematic_obj obj = {
|
||||||
.velocity = {0.0f,0.0f},
|
.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;
|
return obj;
|
||||||
|
@ -30,10 +34,18 @@ void move(struct kinematic_obj *obj, Vector2 acceleration){
|
||||||
if (CheckCollisionRecs(obj->rect, current->obj->rect)){
|
if (CheckCollisionRecs(obj->rect, current->obj->rect)){
|
||||||
collide_rect = GetCollisionRec(obj->rect, current->obj->rect);
|
collide_rect = GetCollisionRec(obj->rect, current->obj->rect);
|
||||||
if(collide_rect.width < collide_rect.height){
|
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;
|
obj->velocity.x = 0;
|
||||||
}else{
|
}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;
|
obj->velocity.y = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
obj/player.c
13
obj/player.c
|
@ -139,6 +139,19 @@ void player_input_check(struct player_obj *player){
|
||||||
break;
|
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){
|
if (IsKeyPressed(JUMP) && jumps > 0){
|
||||||
player->state = JUMP_SQUAT;
|
player->state = JUMP_SQUAT;
|
||||||
allow_friction = true;
|
allow_friction = true;
|
||||||
|
|
Loading…
Reference in New Issue