From 91aef268319a77ee8f5a082ca89264bf2671e212 Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 6 May 2023 10:39:19 +1000 Subject: Map rendering and camera movement. --- player.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'player.c') 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--; } -- cgit v1.2.3-54-g00ecf