@@ -50,11 +50,13 @@ void Plane::Draw(Bitmap& dst) {
5050 int src_x = -ox - GetRenderOx ();
5151 int src_y = -oy - GetRenderOy ();
5252
53+ int offset_x = 0 ;
54+
5355 // Apply screen shaking
5456 const int shake_x = Main_Data::game_screen->GetShakeOffsetX ();
5557 const int shake_y = Main_Data::game_screen->GetShakeOffsetY ();
5658 if (Game_Map::LoopHorizontal ()) {
57- src_x + = shake_x;
59+ offset_x = shake_x;
5860 } else {
5961 // The panorama occupies the same rectangle as the whole map.
6062 // Using coordinates where the top-left of the screen is the origin...
@@ -82,11 +84,26 @@ void Plane::Draw(Bitmap& dst) {
8284 dst_rect.x = bg_x;
8385 dst_rect.width = bg_width;
8486
87+ if (Game_Map::GetDisplayX () / 16 + Player::screen_width > Game_Map::GetTilesX () * TILE_SIZE) {
88+ // Do not draw out of bounds to the right
89+ dst_rect.width -= (Game_Map::GetDisplayX () / 16 + Player::screen_width) - (Game_Map::GetTilesX () * TILE_SIZE);
90+ }
91+
8592 // Correct the offset if the top-left corner moved.
86- src_x + = shake_x + bg_x;
93+ offset_x = shake_x + bg_x;
8794 }
8895 src_y += shake_y;
8996
90- dst.TiledBlit (src_x, src_y, source->GetRect (), *source, dst_rect, 255 );
91- }
97+ dst.TiledBlit (src_x + offset_x, src_y, source->GetRect (), *source, dst_rect, 255 );
9298
99+ if (!Game_Map::LoopHorizontal ()) {
100+ // Clear out of bounds map area visible during shake
101+ if (offset_x < 0 && src_x + offset_x < 0 ) {
102+ auto clear_rect = Rect (dst.GetRect ().x , dst.GetRect ().y , -offset_x, dst.GetRect ().height );
103+ dst.ClearRect (clear_rect);
104+ } else if (dst_rect.width < Player::screen_width) {
105+ auto clear_rect = Rect (dst_rect.width , dst.GetRect ().y , Player::screen_width - dst_rect.width , dst.GetRect ().height );
106+ dst.ClearRect (clear_rect);
107+ }
108+ }
109+ }
0 commit comments