little help

Started by
12 comments, last by phil67rpg 12 years, 5 months ago
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]
Advertisement
So, do you have a question?


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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.
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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

thanks yogurt for all the help.I will try your code.
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]
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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

can you go into detail a little bit.

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.

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.

This topic is closed to new replies.

Advertisement