I have made a out-of-screen-detection function!
bool outofscreen(int x, int y, int xsize = 0, int ysize = 0)
{
if(x < 1 || y < 1 || (x + xsize) > (dbScreenWidth() - 1) || (y + ysize) > (dbScreenHeight() - 1))
{
return true;
}
return false;
}
And then you can call it with for example to make a ball bounce:
int xspeed = 1, yspeed = 1;
void DarkGDK()
{
dbLoadImage([image], 1);
while(LoopGDK())
{
int x = SpriteX(1), y = SpriteY(1);
if outofscreen(x, y)
{
xspeed = 0 - xspeed;
yspeed = 0 - yspeed;
}
x = x + xspeed;
y = y + yspeed;
dbSprite(1, x, y, 1);
dbSync();
}
}
Very simple bouncing example, trough... -_-