void RenderFrame( )
{
if (!g_pD3DDevice && !g_pD3DXSprite && !g_pTexture)
return;
// Clear the frame & depth buffer ready for drawing (Black color)
g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0 );
g_pD3DDevice->BeginScene();
{
int index=0;
//-------------------------
// Render the sprite
//
SPRITE sprite1;
SPRITE sprite2;
sprite1.x=posX;
sprite1.y=posY;
sprite1.width = 10.0f;
sprite1.height = 10.0f;
sprite2.x=0.0f;
sprite2.y=200.0f;
sprite2.width = 160.0f;
sprite2.height = 40.0f;
if(Sprite_Collide(&sprite1,&sprite2)==1)
{
yVel=0.25f;
index=1;
}
sprite2.x=160.0f;
sprite2.y=200.0f;
sprite2.width = 160.0f;
sprite2.height = 40.0f;
if(Sprite_Collide(&sprite1,&sprite2)==1)
{
yVel=0.25f;
index=2;
}
sprite2.x=320.0f;
sprite2.y=200.0f;
sprite2.width = 160.0f;
sprite2.height = 40.0f;
if(Sprite_Collide(&sprite1,&sprite2)==1)
{
yVel=0.25f;
index=3;
}
sprite2.x=480.0f;
sprite2.y=200.0f;
sprite2.width = 160.0f;
sprite2.height = 40.0f;
if(Sprite_Collide(&sprite1,&sprite2)==1)
{
yVel=0.25f;
index=4;
}
sprite2.x=640.0f;
sprite2.y=200.0f;
sprite2.width = 160.0f;
sprite2.height = 40.0f;
if(Sprite_Collide(&sprite1,&sprite2)==1)
{
yVel=0.25f;
index=5;
}
D3DXVECTOR3 vecPos_ball = D3DXVECTOR3(posX,posY,0);
posX += xVel;
posY += yVel;
if(posX <= 10.0f)
{
posX=10.0f;
xVel = 0.25f;
}
else if(posX >= 790.0f)
{
posX=790.0f;
xVel =-0.25f;
}
if(posY <= 10.0f)
{
posY=10.0f;
yVel=0.25f;
}
else if(posY >= 590.0f)
{
posY=590.0f;
yVel=-0.25f;
}
D3DXVECTOR3 vecPos_upper = D3DXVECTOR3(j,0,0);
if(bAdd)
{
j+=0.25f;
}
else
{
j-=0.25f;
}
if(j>=640)
{
bAdd = false;
}
else if(j<=0)
{
bAdd = true;
}
for(float i=0; i<=640; i+=160)
{
D3DXVECTOR3 vecPos_brickone = D3DXVECTOR3(i,120,0);
D3DXVECTOR3 vecPos_bricktwo = D3DXVECTOR3(i,160,0);
D3DXVECTOR3 vecPos_brickthree = D3DXVECTOR3(i,200,0);
// D3DXVECTOR3 vecPos_brickfour = D3DXVECTOR3(0,200,0);
D3DXVECTOR3 vecPos_lower = D3DXVECTOR3(320,560,0);
if (g_pD3DXSprite && g_pTexture)
{
if(index==1)
{
yVel=0.25f;
D3DXVECTOR3 vecPos_brickfour = D3DXVECTOR3(0,200,0);
}
g_pD3DXSprite->Begin( D3DXSPRITE_ALPHABLEND );
g_pD3DXSprite->Draw(g_pTexture, NULL, NULL, &vecPos_upper, 0xffffffff);
g_pD3DXSprite->Draw(g_pTexture, NULL, NULL, &vecPos_lower, 0xffffffff);
g_pD3DXSprite->Draw(g_pTexture_two, NULL, NULL, &vecPos_brickone, 0xffffffff);
g_pD3DXSprite->Draw(g_pTexture_three, NULL, NULL, &vecPos_bricktwo, 0xffffffff);
g_pD3DXSprite->Draw(g_pTexture_four, NULL, NULL, &vecPos_brickthree, 0xffffffff);
// g_pD3DXSprite->Draw(g_pTexture_five, NULL, NULL, &vecPos_brickfour, 0xffffffff);
g_pD3DXSprite->Draw(g_pTexture_ball, NULL, NULL, &vecPos_ball, 0xffffffff);
g_pD3DXSprite->End();
}
}
}
g_pD3DDevice->EndScene();
// Frame buffer to Front buffer
g_pD3DDevice->Present( NULL, NULL, NULL, NULL );
}
moving a paddle in a breakout game
Page 1 of 12 Replies - 390 Views - Last Post: 01 February 2012 - 09:37 PM
Topic Sponsor:
#1
moving a paddle in a breakout game
Posted 29 January 2012 - 05:52 PM
well I am working on a breaout game using dx9 and c++.I am unsure in my code where I should insert a movement routine. I have tried putting a movement routine in the RenderFrame() function.I have also done some reading about dx9 and googled some tutorials.I am confused about animating sprites and how vectors operate.Here is some of the code I am working on.
Replies To: moving a paddle in a breakout game
#2
Re: moving a paddle in a breakout game
Posted 30 January 2012 - 09:27 AM
You shouldn't put that code where you are drawing the scene. You should have a clear difference between everything that works in your engine. And by engine, I mean a collection of systems that serves some purpose, in this case a game. The graphics system should only do graphics, nothing else.
You should have the physics system just handle doing physics. When it updates, it checks collision and resolves them and moves all the objects etc. Graphics does what it needs to. The part where you are having problems is you need a player controller. The player controller needs to listen to key input messages from your input system and react to that.
You should have the physics system just handle doing physics. When it updates, it checks collision and resolves them and moves all the objects etc. Graphics does what it needs to. The part where you are having problems is you need a player controller. The player controller needs to listen to key input messages from your input system and react to that.
This post has been edited by The Adrian: 30 January 2012 - 09:28 AM
#3
Re: moving a paddle in a breakout game
Posted 01 February 2012 - 09:37 PM
well here is some of the code I am working on.
case VK_LEFT:
g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0 );
g_pD3DDevice->BeginScene();
if (g_pD3DXSprite && g_pTexture)
{
D3DXVECTOR3 vecPos_lower = D3DXVECTOR3(320+m,560,0);
m++;
g_pD3DXSprite->Begin( D3DXSPRITE_ALPHABLEND );
g_pD3DXSprite->Draw(g_pTexture, NULL, NULL, &vecPos_lower, 0xffffffff);
g_pD3DXSprite->End();
}
g_pD3DDevice->EndScene();
g_pD3DDevice->Present( NULL, NULL, NULL, NULL );
break;
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|