General Development

Realistic Gravity (2D) – kurtp2003

kurtp2003
Member

Posts: 48
From: minnesota, US
Registered: 01-20-2006
A while back, I posted a program in which particles orbited aroung a source of gravity. The effect was cool, but not realistic at all, but just recently, I've figured out how to make much more real gravity effects.

In this new program, (which is for Blitz) I have added one new feature, which is, that when you press "B" on the keyboard, it will turn the Cls command on or off, which is good to get a beeter idea of what the orbit an object is in actually looks like.

Anyway, here's the code:


C=True

Type particle
Field x#,y#
Field h#
Field xd#,yd#
Field s#,c#
Field xs#,ys#
Field angle#
Field create
End Type

Type gravity
Field x#,y#
End Type

g.gravity=New gravity
g\x=400
g\y=300

While Not KeyDown(1)

If c>0
Cls
EndIf

If KeyHit(bkey)
c=-c
EndIf

If KeyHit(f10) Then SaveBuffer(FrontBuffer(),"orbit screen.bmp")

Color 255,255,255
For p.particle=Each particle
Oval p\x-1,p\y-1,2,2,0
Next

If MouseHit(1)
p.particle=New particle
p\x#=MouseX()
p\y#=MouseY()
p\create=True
EndIf

For p.particle=Each particle
If p\create=True
If MouseDown(1)
p\xd=p\x-MouseX()
p\yd=p\y-MouseY()
p\xs=p\xd/10
p\ys=p\yd/10
Line p\x,p\y,MouseX(),MouseY()
Else
p\create=False
EndIf
EndIf

If p\create=False
p\x#=p\x#+p\xs#
p\y#=p\y#+p\ys#
For g.gravity=Each gravity
p\xd#=g\x-p\x#
p\yd#=g\y-p\y#
Oval g\x-1,g\y-1,3,3,1
Next

p\h#=Sqr(Abs(p\xd#)^2+Abs(p\yd#)^2)

p\s#=p\xd#/p\h#
p\c#=p\yd#/p\h#

p\xs#=p\xs#+(p\s#*200)/(p\h^2/4)
p\ys#=p\ys#+(p\c#*200)/(p\h^2/4)
EndIf
Next

If KeyHit(space)
For p.particle=Each particle
Delete p
Next
EndIf


Text 10,10,"this works"
Color Rand(50,255),Rand(50,255),Rand(50,255)

Oval MouseX()-1,MouseY()-1,3,3,1
Oval MouseX()-4,MouseY()-4,9,9,0

Flip

Wend

End

Mack: it's easy to edit the message after posting.

[This message has been edited by Mack (edited April 08, 2006).]

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
oops... lol... it's supposed to be [ code ] (without the space) [ /code ]... lol... i didn't realize it wouldn't show up...


but that's cool lol!! i don't do much BB... but i know enough about it to say good job! lol...

------------------
In the stock market, you must buy high and sell low...Wait! That's not right!
--------------
Yes, I can be intelligent at times!!

[This message has been edited by buddboy (edited April 06, 2006).]

kurtp2003
Member

Posts: 48
From: minnesota, US
Registered: 01-20-2006
cool, I didn't know that.

if you don't do much bb, what do you use?

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
i use C++ (still learning, i'm on Windoze programming and soon DirectX, also learning some OO) and Python (just started learning )... i used to use BB... but i didn't much cuz it was just the demo lol... plus i wasn't really ready to learn a language back then i don't think... so i really just learned the basics... LOL....

------------------
In the stock market, you must buy high and sell low...Wait! That's not right!
--------------
Yes, I can be intelligent at times!!

kurtp2003
Member

Posts: 48
From: minnesota, US
Registered: 01-20-2006
hey, I've been on the demo for a year now, and I'm doing fine (though I do plan to get the full version)

BTW, is C++ very hard to learn?

dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
C++ is kinda hard to get used to but easier once you start coding often in it. Plus you can get started with it for free.

I have a tutorial series (under development) if you want to learn it. Currently via email list, so if you want to get on that list just send me an email. Also I'm on msn, and if you are too then you can chat about stuff if you want.

My tutorials look into Christian Game Programming in C++ from scratch. Mainly using Dev-C++ but I'm doing both example code in Dev-C++ and Visual Studio 8 (still working on the VS example code). Atm I've completed 3, working on the 4th (text based maze game project tutorial).

God Bless

------------------
"But it is God who judges: He brings one down, he exalts another." - Psalm 75:7

Startup Christian Games Company Producing Mobile/PC Games/Tools