Skip to content

Commit 2cad121

Browse files
committed
Hopefully limited the brick edge cases
1 parent 5280d80 commit 2cad121

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Ball.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,22 @@ blit::Point Ball::get_render_location( void )
8585

8686
blit::Rect Ball::get_bounds( void )
8787
{
88-
return blit::Rect(
89-
location - blit::Vec2( ball_size[ball_type] / 2 - 1, ball_size[ball_type] / 2 - 1 ),
90-
location + blit::Vec2( ball_size[ball_type] / 2 - 1, ball_size[ball_type] / 2 - 1 )
91-
);
88+
/* Work out the corners. */
89+
blit::Point l_tl = location - blit::Vec2( ball_size[ball_type] / 2 - 1, ball_size[ball_type] / 2 - 1 );
90+
blit::Point l_br = location + blit::Vec2( ball_size[ball_type] / 2 - 1, ball_size[ball_type] / 2 - 1 );
91+
92+
/* Clamp the left/right edges of the screen - unsigned, so may have wrapped. */
93+
if ( ( l_tl.x < 0 ) || ( l_tl.x > blit::screen.bounds.w ) )
94+
{
95+
l_tl.x = 0;
96+
}
97+
if ( l_br.x > blit::screen.bounds.w )
98+
{
99+
l_br.x = blit::screen.bounds.w;
100+
}
101+
102+
/* And return the resulting rectangle. */
103+
return blit::Rect( l_tl, l_br );
92104
}
93105

94106

GameState.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ blit::Rect GameState::brick_to_screen( uint8_t p_row, uint8_t p_column )
160160

161161
blit::Point GameState::screen_to_brick( blit::Point p_location )
162162
{
163-
return blit::Point( p_location.x / 32, ( p_location.y - 10 ) / 16 );
163+
/* Clamp the location to the screen, in case a bounding box has slipped */
164+
/* off somewhere, which can get ... messy. */
165+
blit::Point l_location = blit::screen.clip.clamp( p_location );
166+
167+
return blit::Point( l_location.x / 32, ( l_location.y - 10 ) / 16 );
164168
}
165169

166170

metadata.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ splash:
99
file: assets/32blox-image.png
1010
icon:
1111
file: assets/32blox-icon.png
12-
version: v0.9.1
12+
version: v0.9.2
1313

1414
# End of metadata.yml

0 commit comments

Comments
 (0)