Hay
I have been making my own version of Asteroids, and want to make it so the asteroids bounce off the sides of the screen in a random direction. When I try that the sprite goes haywire and sometimes gets stuck in the side of the screen from time to time. I was hoping for a better solution to this problem.
here is the code for my asteroids class
#include "DarkGDK.h"
class Asteroid
{
private:
int AsteroidImageNumber;
int AsteroidSpriteNumber;
int CurrX;
int CurrY;
public:
Asteroid();
Asteroid(char ImageName[], int ImageNumber, int SpriteNumber);
~Asteroid();
void SetUpAsteroid( char ImageName[], int ImageNumber, int SpriteNumber);
void Sprite();
void Show();
void Hide();
void Scale(int Amount);
void Bounce();
void Update();
void SetX(int NewX);
void SetY(int NewY);
int AsteroidX();
int AsteroidY();
};
Asteroid::Asteroid()
{
}
Asteroid::Asteroid(char ImageName[], int ImageNumber, int SpriteNumber)
{
AsteroidImageNumber = ImageNumber;
AsteroidSpriteNumber = SpriteNumber;
dbLoadImage(ImageName,ImageNumber);
}
Asteroid::~Asteroid()
{
}
void Asteroid::SetUpAsteroid(char ImageName[], int ImageNumber, int SpriteNumber)
{
AsteroidImageNumber = ImageNumber;
AsteroidSpriteNumber = SpriteNumber;
dbLoadImage(ImageName,ImageNumber);
}
void Asteroid::Sprite()
{
CurrX = 50;
CurrY = 50;
dbSprite(AsteroidSpriteNumber,CurrX,CurrY,AsteroidImageNumber);
dbOffsetSprite(AsteroidSpriteNumber,dbSpriteHeight(AsteroidSpriteNumber) / 2,
dbSpriteWidth(AsteroidSpriteNumber) / 2);
dbHideSprite(AsteroidSpriteNumber);
}
void Asteroid::Hide()
{
dbHideSprite(AsteroidSpriteNumber);
}
void Asteroid::Show()
{
dbShowSprite(AsteroidSpriteNumber);
}
void Asteroid::Scale(int Amount)
{
dbScaleSprite(AsteroidSpriteNumber,Amount);
}
void Asteroid::Update()
{
dbMoveSprite(AsteroidSpriteNumber,2);
CurrX = dbSpriteX(AsteroidSpriteNumber);
CurrY = dbSpriteY(AsteroidSpriteNumber);
}
int Asteroid::AsteroidX()
{
CurrX = dbSpriteX(AsteroidSpriteNumber);
return CurrX;
}
int Asteroid::AsteroidY()
{
CurrY = dbSpriteY(AsteroidSpriteNumber);
return CurrY;
}
void Asteroid::Bounce()
{
dbRotateSprite(AsteroidSpriteNumber,dbRND(359));
}
void Asteroid::SetX(int NewX)
{
CurrX = NewX;
dbSprite(AsteroidSpriteNumber,CurrX,CurrY,AsteroidImageNumber);
}
void Asteroid::SetY(int NewY)
{
CurrY = NewY;
dbSprite(AsteroidSpriteNumber,CurrX,CurrY,AsteroidImageNumber);
}
any help would be great!
All is revealed with time.