Alice Community  

Go Back   Alice Community > Alice 2 > Works-In-Progress

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Flying game
Old
1101Student
Guest
 
Status:
Posts: n/a
Exclamation Flying game - 05-01-2011, 07:42 AM

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.

Attached Files
File Type: a2w reflex.a2w (225.2 KB, 20 views)
   
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2020, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.