Exemplo n.º 1
0
void Enemy::move( std::vector<SDL_Rect>& otherColliders )
{
	mVelY++;

    //Move the dot left or right
    mPosX += mVelX;
    shiftColliders();

    //If the dot collided or went too far to the left or right
    if( ( mPosX < 0 ) || ( mPosX + ENEMY_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
    {
        //Move back
		POINTS +=100;
       mPosX = randomRange(0, SCREEN_WIDTH);
	   mVelX = 0;
	   shiftColliders();

    }

    //Move the dot up or down
    mPosY += mVelY - mPosY/2;
	shiftColliders();

    //If the dot collided or went too far up or down
    if( ( mPosY < 0 ) || ( mPosY + ENEMY_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
    {
        //Move back
		POINTS +=100;
        mPosY = randomRange(0, SCREEN_HEIGHT);
		mVelY = 0;
		shiftColliders();
    }

}
void Dot::move( std::vector<SDL_Rect>& otherColliders )
{
    //Move the dot left or right
    mPosX += mVelX;
    shiftColliders();

    //If the dot collided or went too far to the left or right
    if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
    {
        //Move back
        mPosX -= mVelX;
		shiftColliders();
    }

    //Move the dot up or down
    mPosY += mVelY;
	shiftColliders();

    //If the dot collided or went too far up or down
    if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
    {
        //Move back
        mPosY -= mVelY;
		shiftColliders();
    }
}
Exemplo n.º 3
0
void Bullet::moveUp( std::vector<SDL_Rect>& otherColliders )
{
	mVelY++;

    //Move the dot left or right
    mPosX += mVelX;
    shiftColliders();

    //If the dot collided or went too far to the left or right
    if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
    {
        if (!bulletsUp.empty())
		{
			bulletsUp.pop_back();
		}
		mVelY = 0;
    }

    //Move the dot up or down
    mPosY -= mVelY;
	shiftColliders();

    //If the dot collided or went too far up or down
    if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
    {
        if (!bulletsUp.empty())
		{
			bulletsUp.pop_back();
			mVelY = 0;
		}
    }
}
Exemplo n.º 4
0
void Bullet::enemyMove( std::vector<SDL_Rect>& otherColliders )
{
	mVelX++;
	mVelY++;

    //Move the dot left or right
    mPosX -= mVelX;
    shiftColliders();

    //If the dot collided or went too far to the left or right
    if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH >= SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
    {
		if (!enemyBullets.empty())
		{
			enemyBullets.pop_back();
		}
    }

    //Move the dot up or down
    mPosY += mVelY;
	shiftColliders();

    //If the dot collided or went too far up or down
    if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT >= SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
    {
        if (!enemyBullets.empty())
		{
			enemyBullets.pop_back();
		}
    }
}
Exemplo n.º 5
0
void Paddle::move(int width, int height, std::vector<SDL_Rect>& otherColliders) {
    // Up or down
    mPosY += mVelY;
    shiftColliders();

    // Check if the Paddle moved to far up or down
    if ((mPosY < 0) || (mPosY + PADDLE_HEIGHT > height)) {
        mPosY -= mVelY;     // Move back
        shiftColliders();
    }
}
Exemplo n.º 6
0
void Block::checkCollision()
{
	//If the block goes off of the top of the screen
	if (bCollider.y < 0) {
		//Put the block back at the top of the screen and set its velocity to 0
		bPosY = 0;
		shiftColliders();
	}
	//If the block goes off of the bottom of the screen
	if (bCollider.y + bCollider.h > SCREEN_HEIGHT) {
		//Put the block back at the bottom of the screen and set its velocity to 0
		bPosY = SCREEN_HEIGHT - bCollider.h;
		shiftColliders();
	}
}
Exemplo n.º 7
0
Paddle::Paddle(int posx, int posy):
mPosX(posx), mPosY(posy), mVelX(0), mVelY(0) {
    // Create the necessary SDL_Rects
    mColliders.resize(6);

    // Initialize the collision boxes' width and height
    mColliders[0].w = 10;
    mColliders[0].h = 15;

    mColliders[1].w = 10;
    mColliders[1].h = 15;

    mColliders[2].w = 10;
    mColliders[2].h = 15;

    mColliders[3].w = 10;
    mColliders[3].h = 15;

    mColliders[4].w = 10;
    mColliders[4].h = 15;

    mColliders[5].w = 10;
    mColliders[5].h = 15;

    // Initialize colliders relative to position
    shiftColliders();
}
Exemplo n.º 8
0
void Block::move(double timeForMovement)
{
	//Move the dot up or down
	bPosY += bVelY * timeForMovement;

	//Shift the colliders
	shiftColliders();

	//Deal with collisions
	checkCollision();
}
Exemplo n.º 9
0
void Block::setDim(int x, int y, int w, int h)
{
	bPosX = x;
	bCollider.x = x;
	bPosY = y;

	bWidth = bCollider.w = w;
	bHeight = bCollider.h = h;

	shiftColliders();
}
Exemplo n.º 10
0
Dot::Dot( int x, int y )
{
    //Initialize the offsets
    mPosX = x;
    mPosY = y;

	hp = 100;

    //Create the necessary SDL_Rects
    mColliders.resize( 11 );

    //Initialize the velocity
    mVelX = 0;
    mVelY = 0;

    //Initialize the collision boxes' width and height
    mColliders[ 0 ].w = 6;
    mColliders[ 0 ].h = 1;

    mColliders[ 1 ].w = 10;
    mColliders[ 1 ].h = 1;

    mColliders[ 2 ].w = 14;
    mColliders[ 2 ].h = 1;

    mColliders[ 3 ].w = 16;
    mColliders[ 3 ].h = 2;

    mColliders[ 4 ].w = 18;
    mColliders[ 4 ].h = 2;

    mColliders[ 5 ].w = 20;
    mColliders[ 5 ].h = 6;

    mColliders[ 6 ].w = 18;
    mColliders[ 6 ].h = 2;

    mColliders[ 7 ].w = 16;
    mColliders[ 7 ].h = 2;

    mColliders[ 8 ].w = 14;
    mColliders[ 8 ].h = 1;

    mColliders[ 9 ].w = 10;
    mColliders[ 9 ].h = 1;

    mColliders[ 10 ].w = 6;
    mColliders[ 10 ].h = 1;

	//Initialize colliders relative to position
	shiftColliders();
}
Exemplo n.º 11
0
void Dot::move( SDL_Rect& square, Circle& circle ) {
  //Move the dot left or right
  mPosX += mVelX;
  shiftColliders();

  //If the dot collided or went too far to the left or right
  if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mCollider, square ) || checkCollision( mCollider, circle ) ) {
    //Move back
    mPosX -= mVelX;
    shiftColliders();
  }

  //Move the dot up or down
  mPosY += mVelY;
  shiftColliders();

  //If the dot collided or went too far up or down
  if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mCollider, square ) || checkCollision( mCollider, circle ) ) {
    //Move back
    mPosY -= mVelY;
    shiftColliders();
  }
}
Exemplo n.º 12
0
Dot::Dot( int x, int y ) {
  //Initialize the offsets
  mPosX = x;
  mPosY = y;

  //Set collision circle size
  mCollider.r = DOT_WIDTH / 2;

  //Initialize the velocity
  mVelX = 0;
  mVelY = 0;

  //Move collider relative to the circle
  shiftColliders();
}