It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
Greetings fellow Americans,
Or any other nation...since I am not american either...my programming skills are again unsurpassed...unsurpassed to such extent that I again need urgent assistance. Is here anyone with good knowledge of VB.net who would be able to assist me with my often screw ups? For 2 days of intense chatting lets say.


The problem I am dealing with right now is that I am making Pong game using only one picture box for everything and my collisions wont work.

Public Sub Collisions()

If (Me.position.X + Me.width >= _ball.position.X) = True And (Me.position.Y <= _ball.position.Y) = True And (_ball.position.Y <= Me.position.Y + Me.height) = True Then

MessageBox.Show("Bang")

End If

End Sub

This is my code snippet for the collisions, yet it only works when the paddle is on top left corner.

For anyone who would be able to assist me and help me make at least slightly functional game (mind you I am not saying "do the work for me, I am saying I will most likely annoy you with my frequent questions"). I will give you a 6 dollar game (sorry cant spare more right now).
Hello Detlik,

I don't have much VB.net experience but a fair amount of experience in other languages such as Python, Java, and C, so I would be interested in helping. Let me know.
avatar
Detlik: The problem I am dealing with right now is that I am making Pong game using only one picture box for everything and my collisions wont work.


This is my code snippet for the collisions, yet it only works when the paddle is on top left corner.
This is something you would normally use a test suite for. Plug in various values and test the result to what they should be.

Alternatively, you could recreate the formula in a spreadsheet and have a table of various possible values and their results. You might be able to spot the issue more easily that way.

It's hard to tell what is wrong with the code as you've posted it because we don't know what the paddle position origin is. Is it the centre of the paddle, top left....? Same with the ball position (the ball also seems to have no size..)
avatar
Detlik: The problem I am dealing with right now is that I am making Pong game using only one picture box for everything and my collisions wont work.

This is my code snippet for the collisions, yet it only works when the paddle is on top left corner.
avatar
xyem: This is something you would normally use a test suite for. Plug in various values and test the result to what they should be.

Alternatively, you could recreate the formula in a spreadsheet and have a table of various possible values and their results. You might be able to spot the issue more easily that way.

It's hard to tell what is wrong with the code as you've posted it because we don't know what the paddle position origin is. Is it the centre of the paddle, top left....? Same with the ball position (the ball also seems to have no size..)
I was trying to make it so the paddle default position and ball one would be 0,0 so I could compare them without adding or subtracting anything.

Both Y, X are top left of the objects. Ball has size of 10,10. Paddle 20,40 (width, height). I am starting to suspect main culprit is the location of objects.
It looks like you want a classic bounding box collision detection, but you're not checking all the sides. The way you are doing it looks like it would only be true if the top left corner of the ball is inside the paddle. Try on paper what would happen if the ball was at screen position 5,5 and the paddle at 10,10.
Me.position.X = 10;
Me.position.Y = 10;
_ball.position.X = 5;
_ball.position.Y = 5;
So your Collisions() function would say:
if (10 >= 5) -> results in true
and (10 <= 5) -> false
and 5 < 10 + 20 -> true
then collision hasn't occurred because not everything is true. However, on paper the ball with a width of 10 and a height of 10 is clearly inside the paddle.

I would do it this way (in C++ mind you):

Collision()
{
if ( (paddle.y + paddle.height) <= ball.y )
return false;
if (paddle.y >= (ball.y + ball.height) )
return false;
if ( (paddle.x + paddle.width) <= ball.x )
return false;
if ( paddle.x >= (ball.x + ball.width) )
return false;

//otherwise collision has occurred
return true;
}
Post edited June 15, 2013 by SCPM
It may be different in VB.net but those If statements look odd to me. I usually see them structured like:

If (A + B = C) andif (X + Y = Z) Then DoSomething



Also the way you have the >= statements written I would assume that the ball could be just about anywhere on the screen and still have the equation be true. If it is a paddle and ball Pong game then I would try something like this.

If (Ball.positionX = Me.positionX + (Me.width/2))

If (Ball.positionY < Me.positionY + (Me.width/2)) andif (Ball.positionY > Me.positionY - (Me.width/2))

Typically the Me.positionX would represent the center of the paddle so the center plus half the width would mark the surface. For Y position you want to count the impact when it is between the two edges of the paddle. The edges are the center of the paddle plus +/- half the width. The formulas I give are probably not right but hopefully this gets you thinking in the right direction. Or I may have completley misunderstood what you are doing.
Thanks for all the tips, I am just having tiny bity problem with top bottom paddle collision, but otherwise it works fine. I have a question though, how would you make proper AI? I was thinking about the paddle always matching the ball position, but that way you would never win.

Atm, when the ball is on player´s side, the enemy moves normally, when its on his side he begans moving crazy fast like squirrel on cocaine.

What do you think?
avatar
Detlik: Thanks for all the tips, I am just having tiny bity problem with top bottom paddle collision, but otherwise it works fine. I have a question though, how would you make proper AI? I was thinking about the paddle always matching the ball position, but that way you would never win.

Atm, when the ball is on player´s side, the enemy moves normally, when its on his side he begans moving crazy fast like squirrel on cocaine.

What do you think?
Limit its maximum movement speed, for starters. Easy = slow, hard = fast, insane = no limit :P
avatar
xyem: Alternatively, you could recreate the formula in a spreadsheet and have a table of various possible values and their results. You might be able to spot the issue more easily that way.
This. The use of Excel (or another spreadsheet program) for algorithmic testing is seriously underrated. It is also of great value for generating scripts for calling stored procedures in a database with lots of differing input values.

Basically, spreadsheets are so versatile that they can help with lots of tasks people usually don't associate them with. I once made a graphical simulation of gravitic interaction between planetary bodies of varying size and mass in Excel. That was pretty fun.
avatar
xyem: Alternatively, you could recreate the formula in a spreadsheet and have a table of various possible values and their results. You might be able to spot the issue more easily that way.
avatar
Wishbone: This. The use of Excel (or another spreadsheet program) for algorithmic testing is seriously underrated. It is also of great value for generating scripts for calling stored procedures in a database with lots of differing input values.

Basically, spreadsheets are so versatile that they can help with lots of tasks people usually don't associate them with. I once made a graphical simulation of gravitic interaction between planetary bodies of varying size and mass in Excel. That was pretty fun.
Side note - have you tried this? http://carywalkin.wordpress.com/download-arena-xlsm/
avatar
amok: Side note - have you tried this? http://carywalkin.wordpress.com/download-arena-xlsm/
Hehe, no, but I've tried several other Excel games, including a complete recreation of the arcade version of PacMan, where each individual pixel was a cell in the sheet.

I'll definitely try that though.