Nathan Lane

Greenhorn
+ Follow
since Aug 12, 2011
Nathan likes ...
Eclipse IDE Java Ubuntu
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nathan Lane

Alright I think what you need to do is ensure that the position of the ball is outside of the bounds of the paddle. Here is an example:


See changes on lines 48-59. Here I check whether the ball's location sits within the bounds of the paddle, and if it does I reposition the ball. Another option would be to set a flag until the ball clears the paddle after it has been set and then reset it. this is a little more work, but it would probably look better (less choppy).
10 years ago
I thought that a code example might illustrate my point:


If you run this example, you get the following output:


Why, you may ask? Because the reference to Name myName is not retained inside of the NamePrinter instance, only the original value is retained.
10 years ago
Part of the problem here also may be that in Java, when you reset p to be a newly compiled object, it's reference changed, and the matcher is still pointing to the original p. In Java everything is passed by value, so the Pattern that the Matcher uses does not change when you change the value of the reference-type Pattern p. Essentially, what you are trying to do will not work, ever, and it's not because Java is broken, rather it's because your code is not the Java-way of doing things. You really need to create two Patterns and two Matchers. But you might step back even further and ask yourself, what are you really trying to do, and why? You may find that what you are trying to do can be done in a better way.
10 years ago
In Tic-Tac-Toe there actually aren't too many possible winning moves, and therefore, in a C++ implementation that I created a while back I provided a static lookup table to determine whether a player won. My squares were numbered 1-9, but my lookup table looks like:




And this method is fairly performant -- I'm not recalculating every time. Now my implementation doesn't include an AI, so that might change my decision, but I don't think so.
10 years ago
First off -- nice game. I really like it. Very well done. Second, I played it a few times and I think that I understand what your saying:

when I move the paddle towards the ball as it is passing it appears two of my collision points are within the paddle and therefore the ball keeps repeatedly bouncing up and down within the paddle.


however I don't think that I was able to reproduce the issue at all. I tried moving the paddle left or right into the ball as it was passing the paddle -- is this when you're saying you're seeing this problem occur? It seems like a difficult issue to reproduce. Most of the time I guess I was too slow, and the ball passed by, and the other half of the time I think I was just barely too fast and caught the ball before it started by me -- there seems to be a rectangle around the ball and so maybe the collision doesn't seem as natural as I would have expected. Do you have any more detail on what exactly is happening and how to reproduce it?

As an aside to my blabbering, there are several more complicated collision algorithms around. I can search some up if you'd like, but I'll just be using Google probably. So let me know.
10 years ago