Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

little help

This topic is 2562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to get my ball to move around the screen and bounce off the edges.
[font="Consolas"][font="Consolas"]D3DXVECTOR3 vecPos_ball = D3DXVECTOR3(ball,400,0);

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"](ball==0)

{

i=1;

}

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]else[/font][/font][/font][font="Consolas"][font="Consolas"] [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"](ball==780)

{

i=-1;

}

ball += i;

the globals for ball=400 and i=0


[/font][/font]

Share this post


Link to post
Share on other sites
Advertisement
yes how do I move a ball around a screen.I am usign a 800 by 600 screen. and a 20 x 20 ball ..let me know if you need more info.

Share this post


Link to post
Share on other sites
FLOAT xVel = 1.0f;
FLOAT yVel = 1.0f;
FLOAT posX = 400.0f;
FLOAT posY = 300.0f;




posX += xVel;
posY += yVel;
if ( posX <= 0.0f + 10.0f ) {
posX = 0.0f + 10.0f;
xVel = 1.0f;
}
else if ( posX >= 800.0f - 10.0f ) {
posX = 800.0f - 10.0f;
xVel = -1.0f;
}


if ( posY <= 0.0f + 10.0f ) {
posY = 0.0f + 10.0f;
yVel = 1.0f;
}
else if ( posY >= 600.0f - 10.0f ) {
posY = 600.0f - 10.0f;
yVel = -1.0f;
}



L. Spiro

Share this post


Link to post
Share on other sites
cool your code works thanks.I have one more little question.I want to move my paddle left and right using the arrow keys, but I am confused about how to use vectrors to manipulate my paddle.here is some of my code.
[font="Consolas"][font="Consolas"]D3DXVECTOR3 vecPos_lower = D3DXVECTOR3(320,560,0);

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]for[/font][/font][/font][font="Consolas"][font="Consolas"]([/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]float[/font][/font][/font][font="Consolas"][font="Consolas"] 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);

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"] (g_pD3DXSprite && g_pTexture)

{

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_ball, NULL, NULL, &vecPos_ball, 0xffffffff);

g_pD3DXSprite->End();

}



}

}

g_pD3DDevice->EndScene();





[/font][/font][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"]// Frame buffer to Front buffer

[/font][/font][/font][font="Consolas"][font="Consolas"]g_pD3DDevice->Present( NULL, NULL, NULL, NULL );

}

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]void[/font][/font][/font][font="Consolas"][font="Consolas"] Paddle_Left()

{

D3DXVECTOR3 vecPos_lower = D3DXVECTOR3(320+m,560,0);

g_pD3DXSprite->Draw(g_pTexture, NULL, NULL, &vecPos_lower, 0xffffffff);

m--;

}

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]void[/font][/font][/font][font="Consolas"][font="Consolas"] Paddle_Right()

{

D3DXVECTOR3 vecPos_lower = D3DXVECTOR3(320+n,560,0);

g_pD3DXSprite->Draw(g_pTexture, NULL, NULL, &vecPos_lower, 0xffffffff);

n++;

}

the lower vector is the paddle I want to move.

[/font][/font]

Share this post


Link to post
Share on other sites
Paddle_Left() and Paddle_Right() are functions for moving the paddle, not rendering them. They need to be rendered every frame, not just when they are moving.

If they are meant to control the same paddle they should be using the same variable for the offset. Either m or n.


L. Spiro

Share this post


Link to post
Share on other sites

can you go into detail a little bit.


Those two functions only change values associated with the paddle's position. They do not render it.

Rendering the paddle, however, needs to use that position in order to draw it in the right place on the screen each frame.

You should never mix input and draw code.

Share this post


Link to post
Share on other sites

Paddle_Left() and Paddle_Right() are functions for moving the paddle, not rendering them. They need to be rendered every frame, not just when they are moving.

If they are meant to control the same paddle they should be using the same variable for the offset. Either m or n.


L. Spiro


well I tried a few things but am still confused.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!