LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a really basic pong game for a beginner

Right-click the array-to-cluster and set the cluster size to 2. 🙂
0 Kudos
Message 21 of 34
(2,816 Views)

Ahaha, is it really that simple?  Wow, now I feel silly.  D'oh!

I promise that someday I'll have really challenging questions for you!

But tomorrow, I'll just need to finish THIS thing. 

Would I start out by inserting a line, and then adding another for loop that would reverse the direction of the "ball" as the one for the "walls" does?

 

And thank you very much once more!  I'd still be frustrated and trying to figure out the code from that other vi if it was not for you!

0 Kudos
Message 22 of 34
(2,808 Views)

EchoWolf wrote:

Would I start out by inserting a line, and then adding another for loop that would reverse the direction of the "ball" as the one for the "walls" does?


No, do everything in ther same loop. All you need to do add a little more code to detect collisions with the line. The rest remains the same.

0 Kudos
Message 23 of 34
(2,798 Views)

Ok, I have questions about the line first.  There is an "absolute coordinates" and an "end point" node on the module for "DrawLine".  Do I need to build a cluster that will give it the positions which will the with one wire connect into the "endpoint" node?

The other question I have is what do I need to wire "keys pressed" of the the "AqcureInfo" vi to set it so that it recognizes that up and down arrow keys will move the "paddle" once I get it to that point?

 

Right now my code is starting to look a little crude, so I'll post it here in a little bit to see if there is a better way to make these things work. >.<

0 Kudos
Message 24 of 34
(2,769 Views)

Ok, what I did there was that I unbundled the cluster so that I could get the x and y coordinates separate.  Since the line(paddle) will only be moving up and down, I want to restrict the x coodrinates of it, and keep it the same throughout.

As I've mentioned before, I've never used the picture functions, so I don't even know what the line output is like aside from what I read about it here.

What I want to do is then set a length for the line of about 60 pixels (so I am thinking of making one coordinate to be center - 30 and the other to be center + 30)  The "center" I mentioned will originally be height/2 as you see I put there, and then change this center point with inputs from the keyboard(though I am not sure yet how to tell it that the down key should decrease the value for this center and the up key should increase it.

Should I declare a local variable to serve as "center"?

 

Now, the further challenging part would be to teach the ball to "bounce" off the line AND to teach the line to "bounce off the walls"  However, I believe that I could do the exact same thing for the line as I did for the "ball" in terms of simply reversing it's y velocity when it touches the sides.  As for the ball, I don't know how to use the same loop, as you mentioned, to teach it to "bounce" off a new obstacle with new coordinates.

 

Message Edited by EchoWolf on 01-03-2010 05:53 PM
0 Kudos
Message 25 of 34
(2,761 Views)

EchoWolf wrote:

Ok, I have questions about the line first. 


You need two functions. First you move the pen to the desired starting point of your line and then draw the a line to the desired end point.

 

Later, you simply need a little bit more logic before determinig the speed after bouncing.

 

Here's one possible solutions. Of course if you have many lines or obstacles, it might be better to keep a single bitmap of all the objects and develop some generic bounce logic subVI. Shouldn't be too hard. 😉

0 Kudos
Message 26 of 34
(2,759 Views)

I see.  That makes sense.  However your example works for a stationary line, the location of which is set.  But since I want to make a movable one, how would I implement a more dynamic structure for the locations both for the bouncing of the ball off the line AND for the location of DrawLine and MovePen?

 

And how do I build those structures (which I am guessing are clusters) that contain the coordinates for MovePen and DrawLine, and the cluster that has the 3 and <>Solid v  ?

Similarly, what about the arrays that you connected to the Inrange/Coerce module?  As you can see, I have practically no experience with building my own arrays or clusters in LabView. >.<

Message Edited by EchoWolf on 01-03-2010 06:11 PM
0 Kudos
Message 27 of 34
(2,754 Views)

Ok, I figured a few things out, but the question about how to insert the keyboard interface and to make the y values dynamic remain.

Also, I am curious about your appending of the array with the additional Boolean(True) expression.  Removing it does not appear to change anything.  What is its purpose?

Message Edited by EchoWolf on 01-03-2010 06:38 PM
0 Kudos
Message 28 of 34
(2,735 Views)

This is what I have so far.  I believe I am only a step away (albeit a very large step) from accomplishing what I want.

I do not know how to tell the program to recognize the up and down arrow keys as the inputs, and how to add and subtract y values from the line position to make it move.  Once I get that, I can add the increase and decrease in y based on the input and wire that to both the height of the cluster that feeds into the MovePen and DrawLine as well as into the InRangeandCoerce module.

At least I really hope that that is all >.<

As you can see, my ideas are appear a lot easier on paper.

 

0 Kudos
Message 29 of 34
(2,725 Views)

First, to create a cluster constant of the right type, it is easiest to simply right-click the terminal and select "create constant". (Similarly, you can also create controls and indicators). To built such a cluster from scratch, place an empty cluster container and drop two numeric diagram constants inside it. Adjust the labels and representation as needed.


EchoWolf wrote:
Also, I am curious about your appending of the array with the additional Boolean(True) expression.  Removing it does not appear to change anything.  What is its purpose?

Yes, it makes a difference. The line is vertical, so we only should invert the x speed, leaving the y speed alone. Building the array ensures that only the first element of the array reverts on collision. If you remove the array building, notice what happens if the ball hits the line. It will reverse both the x and y, so the ball bouces back in the direction of where it came from, instead of bouncing off naturally. 😉 (e.g. if it came from the upper right, it will bounce back to the upper right instead of the lower right).

0 Kudos
Message 30 of 34
(2,723 Views)