The Daily Click ::. Forums ::. Klik Coding Help ::. Asteroids movement
 

Post Reply  Post Oekaki 
 

Posted By Message

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
7th March, 2007 at 20:17:24 -

So, I'd like to know how to code the classic asteroids movement in MMF2.
I've scavenged around the forum in search of it, but I can't seem to get it right.
The best example I found was this:

"At start of frame you set Alt. value a and Alt. value b of the spaceship to 0.0 so you can add floats to it.
When right is hold you add one to the direction of the spaceship, when left is hold you substract one.
Then you always set the x of the space ship to the x of the spaceship + alt. value a, and the y of the space ship to the y of the spaceship + alt. value b.

When up is hold you add the sin(direction of spaceship * 11.25) to alt. value a and add cos(direction of spaceship * 11.25) to alt. value b"

So I tried it out, but it didn't work. I've tweaked it and changed it but I can't get above code to work. So if someone feels smart, by all means.


 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
8th March, 2007 at 16:24:19 -

Always
---Ship: Set Xvelocity to Xvelocity("Ship")+Cos(Angle("Ship"))*Acceleration("Ship")
---Ship: Set Yvelocity to Yvelocity("Ship")+Sin(Angle("Ship"))*Acceleration("Ship")
---Ship: Set Xposition to Xposition("Ship")+ Xvelocity("Ship") / [arbitrary value]
---Ship: Set Yposition to Yposition("Ship")+ Yvelocity("Ship") / [arbitrary value]
---Ship: Set X("Ship") to Xposition("Ship")
---Ship: Set Y("Ship") to Yposition("Ship")

Where
Xposition/Yposition are alt values used to store decimal positions
Xvelocity/Yvelocity are alt values that contain the x/y velocity
Angle is the current angle of the ship in 360 degrees (you might need to change the Yvelocity line to [Yvelocity("Ship")+Sin(Angle("Ship")-180)*Acceleration("Ship")] if you're using either MMF2's built-in angle value, or basing it on 32-directions, because directions in MMF are backwards for some reason)
Acceleration is an alt value set to some number when the thrust key is held, and set to zero when not held, and maybe a negative value if you want reverse thrust

 
n/a

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
8th March, 2007 at 17:20:53 -

http://www.create-games.com/download.asp?id=6614

Pretty much what Radix said.

 
n/a

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
8th March, 2007 at 17:34:43 -

Thanks both of you!
Though sadly, I can't check out Axel's example since I cant get the AlphaChannel.mfx. To get it you need to install the extpack-something which requires that you have the full-version of MMF2, and I haven't saved up the money yet. So I'll try Radix instructions! Unless anyone could send the AlphaChannel.mfx...?

Anyways, thanks!

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
8th March, 2007 at 21:29:04 -

Axel's example is pretty much what I posted in an Always event, and then like a dozen other events that do nothing but support the alpha channel object, so don't worry about it. If you're using MMF2 you can just use the built-in angle value actives have now, which makes this really simple.

 
n/a

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
9th March, 2007 at 05:11:38 -

Yeah, do that. I used Alpha Channel object purely for MMF 1.5 compatibility, but it's actually much easier to do with the built in AO rotation support. Just copy the code Radix posted and you should be fine.

 
n/a

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
9th March, 2007 at 06:49:18 -

Well thanks to all of you! (Even Phizzy, though he didn't actually say anything of relevance... but I like the avatar )

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
9th March, 2007 at 07:55:42 -

Hmpf.
This is trickier than one would think. First I tried Radix code, as it was the ship just vanished in the blink of a loop. So I tweaked around a bit and almost got it to work, but it's something strange with it. Here's the code as it is now:

Always
---Ship: Set Xvelocity to Cos(Angle("Ship))*Acceleration("Ship")
---Ship: Set Yvelocity to Sin(Angle("Ship")-90)*Acceleration("Ship")
---Ship: Set Xposition("Ship")+Xvelocity("Ship")/10
---Ship: Set Yposition("Ship")+Yvelocity("Ship")/10
---Ship: Set X position to X("Ship")+Xposition("Ship")
---Ship: Set Y position to Y("Ship")+Yposition("Ship")

Repeat while "Up Arrow" is pressed
---Ship: Set Acceleration to 2

XRepeat while "Up Arrow" is pressed
---Ship: Set Acceleration to 0

Any ideas?

Image Edited by the Author.

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
9th March, 2007 at 07:59:06 -

Yeah try this:

Always
---Ship: Set Xvelocity to Xvelocity("Ship")+Cos(Angle("Ship"))*Acceleration("Ship")
---Ship: Set Yvelocity to Yvelocity("Ship")+Sin(Angle("Ship"))*Acceleration("Ship")
---Ship: Set Xposition to Xposition("Ship")+ Xvelocity("Ship") / [arbitrary value]
---Ship: Set Yposition to Yposition("Ship")+ Yvelocity("Ship") / [arbitrary value]
---Ship: Set X("Ship") to Xposition("Ship")
---Ship: Set Y("Ship") to Yposition("Ship")


I'd use an "arbitrary value" of like one or two hundred.

 
n/a

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
9th March, 2007 at 08:02:28 -

...
ok
...
*E_E feels kinda stupid*
...
*E_E get's an idea and does what every other non-english-as-first-language-ers does!*
But hey, english is not my first language.
Thanks for the pointer Radix!

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

DaVince

This fool just HAD to have a custom rating

Registered
  04/09/2004
Points
  7998

Game of the Week WinnerClickzine StaffHas Donated, Thank You!Cardboard BoxDos Rules!
9th March, 2007 at 08:47:57 -

Eternal_Entertainment.

 
Old member (~2004-2007).

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
9th March, 2007 at 09:00:56 -

Yeah, an accident in my childhood.
Anyways, I tried you're code again Radix but it still didn't work. So I switched the Cos and Sin so that you use Sin for Xvelocity and Cos for Yvelocity, voilá! It started to work, then by fiddling around with acceleration and the arbitrary value I got it to behave really nice. One thing you want though is to add an event that stops the X and Y position values at topspeed.
Thanks for all the help!

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
10th March, 2007 at 11:08:08 -

Once again!
A question!
Could you guys give me few pointers on how to convert the asteroids movement to a racecar movement? Like the built-in one. I'm doing an experiment... E_E

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
10th March, 2007 at 18:44:08 -

Always
---Ship: Set xpos to xpos("Ship") + Sin(Angle("Ship")) * Velocity("Ship")/100.0
---Ship: Set ypos to ypos("Ship") + Cos(Angle("Ship")) * Velocity("Ship")/100.0
---Ship: Set X position to xpos("Ship")
---Ship: Set Y position to ypos("Ship")

Where xpos/ypos are position holding alt values, and Velocity is the speed setting, which ranges from zero to whatever and is increased when up is held, and decreased when down is held.

Edit: Sorry, I just woke up and I misread your post. I thought you wanted a 360 degree racecar movement.
I'm not sure what you're asking now. If you want to be able to change the movement of your ship at runtime, just use the above code and convert the relevant values. If you just mean you want to use default racecar movement instead, there's not really any way to make the inertia work without using the same code anyway.

Image Edited by the Author.

 
n/a

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
10th March, 2007 at 20:10:54 -

No, you got me right! I mean't a 360 degree one! I can't tell you how grateful I am for all the help. I hope this works out, if it does, I'll be sure to cred you bigtime!
Thanks from E_E!

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image
   

Post Reply



 



Advertisement

Worth A Click