Alice Community  

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

Reply
 
Thread Tools Display Modes
Flying game
Old
1101Student
Guest
 
Status:
Posts: n/a
Exclamation Flying game - 05-01-2011, 08: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, 18 views)
   
Reply With Quote
Old
jediaction
Senior Member
 
jediaction's Avatar
 
Status: Offline
Posts: 5,064
Join Date: Jul 2009
Location: Bel Air, Maryland
Default 05-01-2011, 08: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


Website: www.salokingames.com
FaceBook: www.facebook.com/SalokinGames
   
Reply With Quote
Flying game
Old
1101Student
Guest
 
Status:
Posts: n/a
Exclamation Flying game - 05-02-2011, 08:03 AM

I'm sorry that the description is very long. 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? 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.
   
Reply With Quote
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
Flying game
Old
1101Student
Guest
 
Status:
Posts: n/a
Exclamation Flying game - 05-02-2011, 09:16 PM

Thanks for the input.

The actual code is still kicking my ass.
   
Reply With Quote
Flying game progress...any ideas on the Alice code?
Old
1101Student
Guest
 
Status:
Posts: n/a
Arrow Flying game progress...any ideas on the Alice code? - 05-09-2011, 12:17 AM

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
1 - controlPad.getMouseX()/controlPad.getMouseMaxX().

That gives me a range 1 (left) down to 0. Its getting close to what I want (if we multiply by MAX_H_ACCEL we get values from MAX_H_ACCEL on the left edge - which is correct down to zero on the right edge - which is wrong, should be -MAX_H_ACCEL). The final step (before the multiplication by MAX_H_ACCEL) is to do another simply step to shift that 1 to 0 range to the 1 to -1 range (you can do this by multiplying then adding an offset).

Can I get some help on the Alice code?
   
Reply With Quote
Reply

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 ©2017, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.