-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
157 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
#pragma once | ||
#include "../stdafx.h" | ||
|
||
#pragma pack(push, 1) | ||
typedef struct w_collision { | ||
struct { | ||
bool left : 1; | ||
bool right : 1; | ||
bool top : 1; | ||
bool bottom : 1; | ||
}; | ||
uint8_t all; | ||
} w_collision; | ||
#pragma pack(pop) | ||
|
||
#define smooth_float(current, target, speed) \ | ||
current = (current < target) ? fmin(current + speed, target) \ | ||
: fmax(current - speed, target); | ||
|
||
Vector2 center_camera_on_object(Camera2D *camera, Rectangle box); | ||
Vector2 center_object_on_camera(Rectangle box, Camera2D *camera); | ||
Rectangle get_camera_view(Camera2D *camera); | ||
|
||
void smooth_vec(Vector2 *position, Vector2 target, float move); | ||
void smooth_rect(Rectangle *box, Rectangle target, float move); | ||
|
||
Vector2 get_collision_resolution(w_collision *bc, Rectangle box, | ||
Rectangle target); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "player.h" | ||
|
||
void animate_player(w_player *player, float dt, bool should_walk) { | ||
player->animation += dt; | ||
if (abs(player->velocity.x) > 0.01f || should_walk) { | ||
if (player->animation > dt * 2) { | ||
player->animation = 0; | ||
player->state = (player->state == P_WALK_1) ? P_WALK_2 : P_WALK_1; | ||
} | ||
} else { | ||
if (player->animation > dt * 12) { | ||
player->animation = 0; | ||
player->state = (player->state == P_IDLE_1) ? P_IDLE_2 : P_IDLE_1; | ||
} | ||
} | ||
} | ||
|
||
void update_player_input(w_player *player, w_keyboard *keyboard) { | ||
if (keyboard->left && !player->collision.left) { | ||
if (player->src.width > 0) { | ||
player->src.width = -player->src.width; | ||
} | ||
player->velocity.x -= 1; | ||
} else if (keyboard->right && !player->collision.right) { | ||
if (player->src.width < 0) { | ||
player->src.width = -player->src.width; | ||
} | ||
player->velocity.x += 1; | ||
} | ||
|
||
/* | ||
if (keyboard->jump && player->collision.bottom) { | ||
player->velocity.y -= 10; | ||
} else if (!player->collision.bottom) { | ||
player->velocity.y += 1; | ||
} | ||
*/ | ||
} | ||
|
||
Vector2 get_camera_target_player(w_player *player, Camera2D *camera) { | ||
return center_camera_on_object(camera, | ||
(Rectangle){.x = player->position.x, | ||
.y = player->position.y, | ||
.width = player->dst.width, | ||
.height = player->dst.height}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters