Thread: Flying game
View Single Post
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 05-02-2011, 07:15 PM

Quote:
Originally Posted by 1101Student View Post
Hi all,

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

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? 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.


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote