aboutsummaryrefslogtreecommitdiff
path: root/player.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-06 10:39:19 +1000
committerquou <quou@disroot.org>2023-05-06 10:39:19 +1000
commit91aef268319a77ee8f5a082ca89264bf2671e212 (patch)
tree7deb9a4a9e928d4b78f7c3398e7d9c97a4649140 /player.c
parent2ab411c4b8855d11d48454a93262e8eae3ba7fc7 (diff)
Map rendering and camera movement.
Diffstat (limited to 'player.c')
-rw-r--r--player.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/player.c b/player.c
index 592ef4a..d79beed 100644
--- a/player.c
+++ b/player.c
@@ -55,7 +55,7 @@ void init_player(Player* player, World* world) {
}
void update_player(Player* player, World* world) {
- int dx, dy;
+ int dx, dy, cbx, cby;
int face, moving = 0;
Entity e;
CPosition* pos;
@@ -132,6 +132,26 @@ void update_player(Player* player, World* world) {
game_change_state(&game, game_state_dead);
}
+ world->cam_x = pos->x - ((renderer_w / 2) << fbits);
+ world->cam_y = pos->y - ((renderer_h / 2) << fbits);
+
+ if (world->cam_x < 0) {
+ world->cam_x = 0;
+ }
+
+ if (world->cam_y < 0) {
+ world->cam_y = 0;
+ }
+
+ cbx = (mbmp_w - renderer_w) << fbits;
+ if (world->cam_x > cbx) {
+ world->cam_x = cbx;
+ }
+ cby = (mbmp_h - renderer_h) << fbits;
+ if (world->cam_y > cby) {
+ world->cam_y = cby;
+ }
+
player->shoot_countdown--;
}