How to do this:

I made a little game in Swing, that when you press space it slowly lifts you 10 pixels per second, and then lowers you down. However, it lets people just press space repeatedly to stay at the top, therefore cheating. How do I stop that? Also, how would I make the ball rotate as it moves forward? I cannot just rotate with g2d.rotate() because if it rotates, say 90 degrees when you press space it will jump in THAT direction and not just up as it always should. Will provide code if necessary

TL;DR how do I make the ball rotate repeatedly but always go up instead of in the direction it is facing?

Re: How to do this:

Moving an object around and rotating an object are not related. You can move a rotating object in any direction. You can rotate an object a specific amount for each press of a key. You can rotate and move an object for each press of a key. So I am not certain what problems you are having. Have you successfully rotated an object in place yet? That is the first thing you should try. Then you can modify its location and keep it rotating. That is the next thing you should try.

How to keep players from cheating, as you describe it is up to you. You can limit their moves per unit time. You can exponentially decrease their moving increment per unit time. You can weight the free fall increment more than the rate of increase. It's up to you.

Re: How to do this:

Originally Posted by jim829

Moving an object around and rotating an object are not related. You can move a rotating object in any direction. You can rotate an object a specific amount for each press of a key. You can rotate and move an object for each press of a key. So I am not certain what problems you are having. Have you successfully rotated an object in place yet? That is the first thing you should try. Then you can modify its location and keep it rotating. That is the next thing you should try.

How to keep players from cheating, as you describe it is up to you. You can limit their moves per unit time. You can exponentially decrease their moving increment per unit time. You can weight the free fall increment more than the rate of increase. It's up to you.

Regards,
Jim

Hi Jim, I have gotten it to rotate in place. It is rotating every second. It is kind of uneven because I can't figure out the exact point of rotation, but that doesn't really matter. So yes I do have it rotating in place with g2d.rotate(x) x increments every second.

Re: How to do this:

I am not certain how you are locating the center of rotation. Usually I want the center of rotation to be the center of the object. So if I have a rectangle of size (w,h) and I want to draw it at (x, y) I do the following:

Java Code:

g2d.rotate(angle, x + w/2, y + h/2);
g2d.drawRect(x, y, w, h);

I'm done for the evening. If you attach the images I will check it out tomorrow.