I'm working on a Lunar Lander game and am having some problems figuring out the best way to handle left and right movement. I have up and down working with gravity and adjusting the velocity. In my Ship objects motion function, which paints the ship at the new location I have the following:
dy posy, gravity, and thrust are just floats initial values. When I press the up arrow key, the thrust is greater than gravity so eventually the ship begins to climb. When released, it eventually begins to fall again.
With regards to my problem of moving left and right I just can't seem to get it. I've tried the following:
The ship will move in the direction I press but way too fast and it immediately moves in the opposite direction when I press that key, there is no gradule change like there should be, the same as up and down. [ December 13, 2008: Message edited by: Gregg Bolinger ]
Physics aside, I think the main issue here is the use of +/- and positive/negative values. Let 'dx' be positive for motion to the right, and negative for motion to the left. Therefore you want to subtract from dx for left motion, and add to it for right motion. But when you compute the new position, you should always add; i.e., the position in the next frame is always x + dx. dx can be negative (meaning actually moving to the left), 0 (meaning stationary) or positive (meaning moving to the right.) If you're moving fast to the right, and you press left once, then you want dx to become somewhat less positive; we still are moving to the right, but slightly less fast. If there's no horizontal keypress at all, you want to continue to move just as fast to the right as before: you're in space and there's no horizontal damping. So the code could look like
[ December 09, 2008: Message edited by: Ernest Friedman-Hill ]
I hadn't learned anything about JavaFX before, so this gave me an excuse to download the SDK. I tried to build your code "cold", without reading any instructions. It too me a number of tries. I was a little surprised to find that the compiler was almost as picky about filenames as is the Java compiler.
Originally posted by Ernest Friedman-Hill: So why didn't they base it on Groovy?
I've asked the same question. I believe it was because Groovy's syntax isn't IDE friendly enough. They wanted something quite a bit more human readable? Something that non-developers could grasp fairly easily.
You might be interested in this though and Andres told me that since all of JavaFX media capabilities will be available through Java then there is certainly something in the works on the groovy side of things.
I played LL on a DEC GT40 graphics workstation in 77 or so. It was a PDP-11 with a big bitmapped display. You would toggle the front panel switches to control the rocket motor. This was in the big corporate marketing room in Marlboro, the PHB didn't like us playing it during working hours.