PDA

Click to See Complete Forum and Search --> : My 1st game


lil_bugga
Aug 13th, 2007, 06:52 PM
Hi all, im trying to create my own version of the classic Pong with realistic physics.

I have the game set up for testing at the moment, i want to get things right so i can have the ball bounce of all 4 sides of the form. Unfortunatley my coding only works on the top and left walls where I have set the value 0.

On the right and bottom walls the ball just continues right on through rather than bouncing back. I've tried using specific values to make the ball bounce as well as using the forms width added to the left and height added to the top but still to no avail.

Can someone have a look an see where I've gone wrong, im assuming its something I've done or missed.

Many Thanks
Ben

Lord Orwell
Aug 13th, 2007, 08:30 PM
it's a comon problem. Without even looking, i would bet you didn't divide the twips properly.

lil_bugga
Aug 13th, 2007, 08:33 PM
it's a comon problem. Without even looking, i would bet you didn't divide the twips properly.

As far as im aware i should be working in twips, and its 1 pixel to 15 twips i believe.

To get the figures for the right and bottom i placed the image of the ball at the furthest point i want it to be then took the left and top co ords :(

Lord Orwell
Aug 13th, 2007, 08:42 PM
ok i was wrong. Your problem is a little more simple than that. You are mixing data types. You are treating xangle and yangle as strings by using the replace function on them. This is wrong. When you replace -10 with a + it makes it 10, not +10, so when you get to the other side of the screen and check for the boundary, there is no + to replace.

lil_bugga
Aug 13th, 2007, 08:51 PM
ok i was wrong. Your problem is a little more simple than that. You are mixing data types. You are treating xangle and yangle as strings by using the replace function on them. This is wrong. When you replace -10 with a + it makes it 10, not +10, so when you get to the other side of the screen and check for the boundary, there is no + to replace.
Ok im with you there and now you've pointed it out to me it makes sence.

Is there a way in which i can still get the same effect that I was aiming for in my attempt, whats the best way for me to do this, to mirror the angle of bounce that is?

Thanks for the quick responces :thumb:

Lord Orwell
Aug 13th, 2007, 11:29 PM
say for example that xangle = - 10

xangle = xangle * -1

now xangle = 10
(works both ways)

Lord Orwell
Aug 13th, 2007, 11:34 PM
As far as im aware i should be working in twips, and its 1 pixel to 15 twips i believe.

To get the figures for the right and bottom i placed the image of the ball at the furthest point i want it to be then took the left and top co ords :(
This is exactly why microsoft did away with twips in vb.net.

there is not a standard relationship between twips and pixels. The number changes depending on monitor size and screen resolution. It's supposed to be something like 1000 per inch, no matter what. As you can see the ration would change if you had less pixels per inch or more from changing display settings or having a bigger monitor. You would have a much easier time of it i think if you used pixels, but in your particular case, it might be easier to make the ball move at angles more precisely using twips because of the multiple-twips-per-pixel.

lil_bugga
Aug 14th, 2007, 03:17 AM
Thanks so much for your help :thumb:

I've modified my coding to impliment the codeing that you suggested and it now works well.

:D

Lord Orwell
Aug 14th, 2007, 10:16 AM
i forgot to mention that you can convert twips to pixels by dividing by screen.twipsperpixelx and screen.twipsperpixely respectively

fix23
Sep 16th, 2007, 03:42 PM
this looks really good.. keep up the good work