Stopping image from going off surface

Hello all,

How can I keep a surface (in this case, square) from going beyond the boundaries of a surface (my playing field). This is for my tetris I’m trying to make. So that when the block is going down, it can’t go off the playing feild.

Regards,
Rafik

Rafik Rezzik wrote:

How can I keep a surface (in this case, square) from going beyond the
boundaries of a surface (my playing field). This is for my tetris I’m
trying to make. So that when the block is going down, it can’t go off
the playing feild.

Surfaces don’t have a position; they just ‘exist’ and you can copy their
contents from one to another. The way in which you copy that data to the
screen can give the illusion of movement, but in reality, nothing moves
at all. Therefore the concept of SDL_Surfaces is pretty much irrelevant
to your question, except for the fact that their width and height will
probably correspond to your square size. I could have sworn that someone
posted a good ‘rubber stamp’ analogy recently, but I don’t see it in the
archives.

The algorithm you need is pretty simple: check the 4 sides of the
square, and ensure that they are not past the corresponding side of the
playing field. You may want to search Google, or indeed these archives,
for simple collision detection.–
Kylotan
http://pages.eidosnet.co.uk/kylotan

if block.xmin > display.xmax ||
block.xmax < display.xmin ||
block.ymin > display.ymax ||
block.ymax < display.ymin ) don’t draw it.
effecitve.(x/y)(min/max) = block.(x/y)(min/max);
if( block.xmax > display.xmax ) effective.xmax = display.xmax
if( block.ymax > display.ymax ) effective.ymax = display.ymax
similarly with x,y mins…
your resulting effective x,y min,max is what you can draw…

how easy is that? not much of a programmer, yet, eh?> ----- Original Message -----

From: rafik@hotpop.com (Rafik Rezzik)
To:
Sent: Saturday, March 29, 2003 11:54 AM
Subject: [SDL] Stopping image from going off surface

Hello all,

How can I keep a surface (in this case, square) from going beyond the
boundaries of a surface (my playing field). This is for my tetris I’m trying
to make. So that when the block is going down, it can’t go off the playing
feild.

Regards,
Rafik


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Jim,

I think I get it, but I’m confused about the effective. It is a variable of type SDL_Surface or what? Yah, I am not much of a programmer yet, as I am 14 and only have a book that I try to learn from.

Regards,
RafikOn Sat, 29 Mar 2003 14:54:30 -0500 Rafik Rezzik wrote:

Hello all,

How can I keep a surface (in this case, square) from going beyond the boundaries of a surface (my playing field). This is for my tetris I’m trying to make. So that when the block is going down, it can’t go off the playing feild.

Regards,
Rafik


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl