PDA

View Full Version : Flying game

1101Student
05-01-2011, 07:42 AM
Hi all,

I'm after some help/suggestions with a flying game. :D

The heart of the game lies in writing a method (ship.flyMethod) that is responsible for updating the ship’s position (based on acceleration from the mouse position and other factors).

Fundamentally the mouse position information will be turned into acceleration values which in turn are used to find the ship’s current speed. This needs to happen for both dimensions. Those speed values will be used to move the ship each time inside a loop (while loop). There are a set of attributes I have defined on the ship object to help with this:

• MAX_H_ACCEL – The maximum horizontal acceleration or deceleration the ship can achieve. MAX_H_ACCEL is achieved when the mouse is on the left edge of the screen and –MAX_H_ACCEL when it is on the right edge.
• MAX_V_ACCEL – The maximum vertical acceleration or deceleration the ship can achieve. MAX_V_ACCEL is achieved when the mouse is on the top edge of the screen and –MAX_V_ACCEL when it is on the bottom edge.
• MAX_H_SPEED - The maximum speed the ship can be going horizontally.
• MIN_H_SPEED – The minimum speed the ship can be going horizontally.
• MAX_V_SPEED – The maximum speed the ship can be going vertically. Note it can also achieve a “minimum” (i.e., going down fast) of –MAX_V_SPEED.
• CEILING – The maximum height “above the deck” that the ship can fly to.
• speedH – The speed the ship travelling horizontally.
Before the loop (i.e., right at the start of ship.flyMethod) I think this should be set to MAX_H_SPEED. I have thought about setting the value of this attribute (based on acceleration) each time inside the loop.
• speedV – The speed the ship moving vertically. Before the loop this should be set to zero. I think I will again set the value of this variable (based on acceleration) each time inside the while loop.

I think I will need two variables local to the ship.flyMethod method that record the vertical and horizontal acceleration (right?). These should be set each time inside the loop according to the above constants: when the mouse is in the centre of the display the acceleration in both directions is zero; the further the most is moved to the left the more positive the horizontal acceleration becomes until it reaches MAX_H_ACCEL.

Similarly moving to the right makes it reach a minimum of –MAX_H_ACCEL. The same applies for moving the mouse up and down the screen: vertical acceleration reaches MAX_V_ACCEL at the top of the screen and –MAX_V_ACCEL at the bottom.

Should I be able to determine the formula for calculating the acceleration values using the various getMouse*() methods of controlPad and the constants listed above? :confused: Then just simply add each of the acceleration values onto their corresponding speed attributes (speedH, speedV)???
Finally move the ship “forward” (as perceived by the viewer – for instance this is to the right as perceived by the world) and “up’ (up as perceived by the world) the speed values; taking 0.1 seconds to do so.

I would appreciate the feedback or some ideas about the code.

:)

jediaction
05-01-2011, 07:50 AM
OK, I am a bit confused but You can watch variables by right clicking them in the properties of the object with the variables, and then pressing watch variable. Hope that helps as a start. I will see what I can answer when I get home today

1101Student
05-02-2011, 07:03 AM
I'm sorry that the description is very long. :D It is difficult to get what I want out of alice without all the details.

The heart of the game lies in writing a method (ship.flyMethod) that is responsible for updating the ship’s position (based on acceleration from the mouse position and other factors).

Fundamentally the mouse position information from the calibrateMouse method (part of the controlpad object) will be turned into acceleration values which in turn are used to find the ship’s current speed. This needs to happen for both dimensions (X and Y). Those speed values will be used to move the ship each time inside a loop (possibly a while loop). There are a set of attributes I have defined on the ship object to help as above.

I have had a go at the monitor the variable but what is watching it? :confused: I thought about setting speedH and speedV before the loop (i.e., right at the start of ship.flyMethod) I think this should be set to MAX_H_SPEED, setting the value of this attribute (based on acceleration) each time inside a while loop.

Again I appreciate the input.

reuben2011
05-02-2011, 06:15 PM
Hi all,

I'm after some help/suggestions with a flying game. :D

The heart of the game lies in writing a method (ship.flyMethod) that is responsible for updating the ship’s position (based on acceleration from the mouse position and other factors).

Fundamentally the mouse position information will be turned into acceleration values which in turn are used to find the ship’s current speed. This needs to happen for both dimensions. Those speed values will be used to move the ship each time inside a loop (while loop). There are a set of attributes I have defined on the ship object to help with this:

• MAX_H_ACCEL – The maximum horizontal acceleration or deceleration the ship can achieve. MAX_H_ACCEL is achieved when the mouse is on the left edge of the screen and –MAX_H_ACCEL when it is on the right edge.
• MAX_V_ACCEL – The maximum vertical acceleration or deceleration the ship can achieve. MAX_V_ACCEL is achieved when the mouse is on the top edge of the screen and –MAX_V_ACCEL when it is on the bottom edge.
• MAX_H_SPEED - The maximum speed the ship can be going horizontally.
• MIN_H_SPEED – The minimum speed the ship can be going horizontally.
• MAX_V_SPEED – The maximum speed the ship can be going vertically. Note it can also achieve a “minimum” (i.e., going down fast) of –MAX_V_SPEED.
• CEILING – The maximum height “above the deck” that the ship can fly to.
• speedH – The speed the ship travelling horizontally.
Before the loop (i.e., right at the start of ship.flyMethod) I think this should be set to MAX_H_SPEED. I have thought about setting the value of this attribute (based on acceleration) each time inside the loop.
• speedV – The speed the ship moving vertically. Before the loop this should be set to zero. I think I will again set the value of this variable (based on acceleration) each time inside the while loop.

I think I will need two variables local to the ship.flyMethod method that record the vertical and horizontal acceleration (right?). These should be set each time inside the loop according to the above constants: when the mouse is in the centre of the display the acceleration in both directions is zero; the further the most is moved to the left the more positive the horizontal acceleration becomes until it reaches MAX_H_ACCEL.

Similarly moving to the right makes it reach a minimum of –MAX_H_ACCEL. The same applies for moving the mouse up and down the screen: vertical acceleration reaches MAX_V_ACCEL at the top of the screen and –MAX_V_ACCEL at the bottom.

Should I be able to determine the formula for calculating the acceleration values using the various getMouse*() methods of controlPad and the constants listed above? :confused: Then just simply add each of the acceleration values onto their corresponding speed attributes (speedH, speedV)???
Finally move the ship “forward” (as perceived by the viewer – for instance this is to the right as perceived by the world) and “up’ (up as perceived by the world) the speed values; taking 0.1 seconds to do so.

I would appreciate the feedback or some ideas about the code.

:)

It sounds like you have a good "game plan" for your project. I kind of understand what your trying to get at but I'm not sure exactly what your talking about. I'll take a look at the example you posted for clarification. I like how your implementing the mouse's position in your project. Most users usually flinch at the thought. :p

1101Student
05-02-2011, 08:16 PM
Thanks for the input. :)

The actual code is still kicking my ass. :mad:

1101Student
05-08-2011, 11:17 PM
The recommended way to solve this problem is to,

Loop forever
Turn mouse coordinates into acceleration values
Add acceleration values to ship's current speed
doTogether
move ship forward at its horizontal speed
move ship up at its vertical speed

But its still that first step (turn mouse cords into acceleration) that is causing me troubles.

OK. The 1st step is to turn the mouse coordinates into a normalized range. What I'm going to do is map the values into the range 0 to 1. So to do this for the horizontal part its going to look like controlPad.getMouseX()/controlPad.getMouseMaxX().

Now I have a value that lies between zero and 1 - it will be zero when the mouse is at the left edge of the screen and 1 when it is at the right. That’s sort of the reverse of what I want - I want max on the left and min on the right. I could go with