0

Ok so I have the program set up for initial movement of two sprites that move toward one another and when they collide they return to their orignial position. But I need to know how to have them have randomized starting points and continue to move and bounce of the edges of the screen until they collide and start again at another random point. The problem is I am unsure of how to make the edges of the screen solid so the ball wont bounce out of view and I dont know how to make them move randomly about the screen. Any help would be appreciated.

here is what I got so far....

#include "DarkGDK.h"

const int BALL1_IMAGE_NUM = 1;  // Ball 1's image number
const int BALL2_IMAGE_NUM = 2;  // Ball 2's image number
const int BALL1_SPRITE_NUM = 1; // Ball 1's sprite number
const int BALL2_SPRITE_NUM = 2; // Ball 2's sprite number
const int BALL1_X = 0;          // Ball 1's initial X position
const int BALL2_X = 511;        // Ball 2's initial X position
const int BALL_Y = 175;         // Both ball's Y position
const int DISTANCE = 10;        // Distance to move the balls
const int REFRESH_RATE = 10;    // Refresh rate

void setUp();
void moveBowlingBalls();
void detectCollision();

void DarkGDK()
{
    setUp();

    while ( LoopGDK() )
    {
        moveBowlingBalls();

        detectCollision();

        dbSync();
    }
}

void setUp()
{
    dbSetImageColorKey(0, 255, 0);
    dbLoadImage("BowlingBall1.bmp", BALL1_IMAGE_NUM);
    dbLoadImage("BowlingBall2.bmp", BALL2_IMAGE_NUM);

    dbSprite(BALL1_SPRITE_NUM, BALL1_X, BALL_Y,
             BALL1_IMAGE_NUM);
    dbSprite(BALL2_SPRITE_NUM, BALL2_X, BALL_Y,
             BALL2_IMAGE_NUM);

    dbSyncOn();
    dbSyncRate(REFRESH_RATE);
}

void moveBowlingBalls()
{
    int x,y;

    x = dbSpriteX(BALL1_SPRITE_NUM);
    x += DISTANCE;
	
	y = dbSpriteY(BALL1_SPRITE_NUM);
	y+= 5;

    dbSprite(BALL1_SPRITE_NUM, x, BALL_Y,
             BALL1_IMAGE_NUM);

    x = dbSpriteX(BALL2_SPRITE_NUM);
    x -= DISTANCE;

	y = dbSpriteY(BALL2_SPRITE_NUM);
	y+= 5;

    dbSprite(BALL2_SPRITE_NUM, x, BALL_Y,
             BALL2_IMAGE_NUM);

}

void detectCollision()
{
    if ( dbSpriteCollision(BALL1_SPRITE_NUM, BALL2_SPRITE_NUM) )
    {
        dbSprite(BALL1_SPRITE_NUM, BALL1_X, BALL_Y,
                 BALL1_IMAGE_NUM);
        dbSprite(BALL2_SPRITE_NUM, BALL2_X, BALL_Y,
                 BALL2_IMAGE_NUM);
    }
}

Edited by MindTrixz: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by MindTrixz
0

Ok so I got a random starting point but now they continue to blur around the screen the screen. how do I get them to move at a steady pace?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.