SFML community forums
Help => General => Topic started by: aNewHobby on May 07, 2012, 12:59:53 pm
-
I have been trying to build a SFML version of Tetris using c++ as a project to help my learning process. Everyone says that it is a great starting point.
Anyway, I have kind of got a semi working prototype using arrays, one cell for each block, a number of blocks for each peace, a simple test to see if a cell is filled or not for collision. Then I was looking through the forum and I saw this post
http://en.sfml-dev.org/forums/index.php?topic=6992.msg46217#msg46217
Just a suggestion, but if you used sf::Rect's instead of vectors, you could reduce your code down to like 2 lines.
if(ballRect.Intersects(paddle1Rect) return PADDLE1HIT;
if(ballRect.Intersects(paddle2Rect) return PADDLE2HIT;
doe this mean the primitive squares and stuff have their own collision detection functions built in? Would this be usabe.. say using them and overlaying fancy sprites ontop or something?
-
SFML doesn't have real collision detection mechanisms, it can just find out if and how rectangles overlap. For more advanced tasks, you could look at Boost.Geometry or a full physics library like Box2D, although I doubt it's appropriate for a Tetris.