Beispiel #1
0
// update the game logic here
void updateGame() {
	updateBallPosition(ball);
	movePlayer(player1);
	if(ball.speed.x < 0)
		seek(player2, ball);
	
	if( testOnScreen(ball) ) {
		// ball hit side of screen
		if(ball.position.x < 50) {
			// player 1 lost
			player2Score++;
		}
		else {
			// player 2 lost
			player1Score++;
		}
	}

	if(g_gameOver == false) {
		if( abs(player1Score - player2Score) >= 3) {
			// Game Over
			g_gameOver = true;

			int highestScore = player1Score;
			if(player2Score > highestScore) {
				highestScore = player2Score;
			}

			for(int i=0; i<5; i++) {
				if(highestScore > g_highScores[i]) {
					g_highScores[i] = highestScore;
					break;
				}
			}

			// sort the high scores array
			sort(g_highScores, 5);
		}
	}

	if(ball.speed.x < 0) {
		if(checkPaddleCollision(ball, player1) == true)  {
			ball.speed.x *= -1;
		}
	}
	else {
		if(checkPaddleCollision(ball, player2) == true)  {
			ball.speed.x *= -1;
		}
	}


	RotateSprite(player1.sprite, 0);
	MoveSprite(player1.sprite, player1.position.x, player1.position.y);

	RotateSprite(player2.sprite, 0 );
	MoveSprite(player2.sprite, player2.position.x, player2.position.y);

	MoveSprite(ball.sprite, (int)ball.position.x, (int)ball.position.y);
}
Beispiel #2
0
void Projectile::update() {
	x += xDir * speed;
	y += yDir * speed;
	if(abs(xDir) > 0) {
		pixelsTravellable -= (int)(abs(xDir) * speed);
	} else if(abs(yDir) > 0) {
		pixelsTravellable -= (int)(abs(yDir) * speed);
	} else {
		pixelsTravellable--;
	}

	for(int index = 0; index < 2; index++) {
		if(currentRotation > rotation) {
			currentRotation -= 5;
		} else if(currentRotation < rotation) {
			currentRotation += 5;
		}
	}

	RotateSprite(texture, currentRotation);
	MoveSprite(texture, x, y);

	if(pixelsTravellable <= 0) {
		getApplication()->removeDrawable(this);
		return;
	}
}
Beispiel #3
0
//update the game logic here
void updateGame()
{
	if( g_bGameOver != true )
	{
	updateBallPosition(g_ball);
	}

	if( !g_bGameOver )
	{
		//player 1 on auto
		seek(g_player1, g_ball);
	
		//input for player 2
		movePlayer(g_player2);
	}

	if( testOnScreen(g_ball, SCREEN_X, SCREEN_Y) )
	{
		//ball hit side of screen
		if(g_ball.v2Position.fX < 100 )
		{
			//player 1 lost
			g_iPlayer2Score++;
		}
		else
		{
			//player 2 lost
			g_iPlayer1Score++;
		}
	}

	if( g_bGameOver == false )
	{
		if( abs(g_iPlayer1Score - g_iPlayer2Score) >= 3 )
		{
			//game over
			g_bGameOver = true;

			int iHighestScore = g_iPlayer1Score;
			if( g_iPlayer2Score > g_iPlayer1Score )
			{
				iHighestScore = g_iPlayer2Score;
			}

			for(int i = 0; i < 5; i++ )
			{
				if( iHighestScore > g_aiHighScores[i])
				{
					g_aiHighScores[i] = iHighestScore;
					break;
				}
			}

			//sort the scores array
			sort(g_aiHighScores, 5);
		}
	}

	if( g_ball.v2Speed.fX < 0 )
	{
		if(checkPaddleCollision(g_ball, g_player1) == true)
		{
			g_ball.v2Speed.fX *= -1;
		}
	}
	else
	{
		if( checkPaddleCollision(g_ball, g_player2) == true)
		{
			g_ball.v2Speed.fX *= -1;
		}
	}

	RotateSprite(g_player1.iSprite, 0);
	MoveSprite(g_player1.iSprite, g_player1.v2Position.fX, g_player1.v2Position.fY );

	RotateSprite(g_player2.iSprite, 0);
	MoveSprite(g_player2.iSprite, g_player2.v2Position.fX, g_player2.v2Position.fY);

	MoveSprite(g_ball.iSprite, (int)g_ball.v2Position.fX, (int)g_ball.v2Position.fY);
}
void Player::Draw()
{
	RotateSprite(textureID, rotation);
	MoveSprite(textureID, x, y);
	DrawSprite(textureID);
}
Beispiel #5
0
void createSprite(OamState * oam, SpriteInfo *spriteInfo, const void* spriteName_Pal, uint32 spriteName_Pal_Len,
          const void* spriteName_Tiles, uint32 spriteName_Tiles_Len,int OAM_ID, bool isMainScreen,int width, int height, int angle, int x, int y, int size)
{

	/* Create the sprite. */
    assert(OAM_ID < SPRITE_COUNT);
    spriteInfo = &spriteInfo[OAM_ID];
    SpriteEntry * spriteEntry = &oam->oamMemory[OAM_ID];
	
	/* Initialize spriteEntry */
    spriteInfo->oamId = OAM_ID;
    spriteInfo->width = width;
    spriteInfo->height = height;
    spriteInfo->angle = angle;
    spriteInfo->entry = spriteEntry;
	//spriteInfo->gfx = oamAllocateGfx(oam, SpriteSize_32x32, SpriteColorFormat_16Color);
	
	/*
     *  Configure attribute 0. 
     *
     *  OBJCOLOR_16 will make a 16-color sprite. We specify that we want an
     *  affine sprite (via isRotateScale) here because we would like to rotate
     *  the ship.
     */
    //spriteEntry->y = SCREEN_HEIGHT / 2 - spriteInfo->height;
	spriteEntry->y = y;
    spriteEntry->isRotateScale = true;
    /* This assert is a check to see a matrix is available to store the affine
     * transformation matrix for this sprite. Of course, you don't have to have
     * the matrix id match the affine id, but if you do make them match, this
     * assert can be helpful. */
    assert(!spriteEntry->isRotateScale || (spriteInfo->oamId < MATRIX_COUNT));
    spriteEntry->isSizeDouble = false;
    spriteEntry->blendMode = OBJMODE_NORMAL;
    spriteEntry->isMosaic = false;
    spriteEntry->colorMode = OBJCOLOR_16;
    spriteEntry->shape = OBJSHAPE_SQUARE;
	
    /*
     *  Configure attribute 1.
     *
     *  rsMatrixId refers to the loation of affine transformation matrix. We
     *  set it to a location computed with a macro. OBJSIZE_32, in our case
     *  since we are making a square sprite, creates a 32x32 sprite.
     */
    //spriteEntry->x = SCREEN_WIDTH / 2 - spriteInfo->width * 2 +
    //                spriteInfo->width / 2;
	spriteEntry->x = x;
    spriteEntry->rotationIndex = spriteInfo->oamId;
    
	if (size == 32)
		spriteEntry->size = OBJSIZE_32;
	if (size == 64)
		spriteEntry->size = OBJSIZE_64;

    /* 
     *  Configure attribute 2.
     * 
     *  Configure which tiles the sprite will use, which priority layer it will
     *  be placed onto, which palette the sprite should use, and whether or not
     *  to show the sprite.
     */
	if(isMainScreen) 
	{
		spriteEntry->gfxIndex = nextAvailableTileIdxMain;
		nextAvailableTileIdxMain += spriteName_Tiles_Len / BYTES_PER_16_COLOR_TILE;
	}
	if(!isMainScreen)
	{
		spriteEntry->gfxIndex = nextAvailableTileIdxSub;
		nextAvailableTileIdxSub += spriteName_Tiles_Len / BYTES_PER_16_COLOR_TILE;
	}
	
    spriteEntry->priority = OBJPRIORITY_1;
    spriteEntry->palette = spriteInfo->oamId;

    /* Rotate the sprite */
    RotateSprite(&oam->oamRotationMemory[spriteInfo->oamId],
                 spriteInfo->angle);


	if(isMainScreen == true)
	{
		/* Copy over the sprite palettes */
		dmaCopyHalfWords(SPRITE_DMA_CHANNEL,
						 spriteName_Pal,
						 &SPRITE_PALETTE[spriteInfo->oamId *
										 COLORS_PER_PALETTE],
						 spriteName_Pal_Len);
						 
		/* Copy the sprite graphics to sprite graphics memory */
		dmaCopyHalfWords(SPRITE_DMA_CHANNEL,
						 spriteName_Tiles,
						 &SPRITE_GFX[spriteEntry->gfxIndex * OFFSET_MULTIPLIER],
						 spriteName_Tiles_Len);
	}
	else
	{
		/* Copy over the sprite palettes */
		dmaCopyHalfWords(SPRITE_DMA_CHANNEL,
						 spriteName_Pal,
						 &SPRITE_PALETTE_SUB[spriteInfo->oamId *
										 COLORS_PER_PALETTE],
						 spriteName_Pal_Len);
						 
	/* Copy the sprite graphics to sprite graphics memory */
		dmaCopyHalfWords(SPRITE_DMA_CHANNEL,
						 spriteName_Tiles,
						 &SPRITE_GFX_SUB[spriteEntry->gfxIndex * OFFSET_MULTIPLIER_SUB],
						 spriteName_Tiles_Len);
	}
}