Posted: Fri Jun 24, 2005 9:01 am Post subject: (No subject)
Instead of doing something like
code:
speed = 20 - size
you could use the formula for kinetic energy. Ek=1/2*mv^2 Therefore, v = sqrt (2*Ek/m).
So, simply decide what you want the kinetic energy of the asteroids to be (this could be somewhat random for each asteroid) and then determine the mass (based on radius and density) and then plug those into the formula and find the appropriate velocity.
If you want to make things harder, just increase the kinetic energy.
Sponsor Sponsor
jamonathin
Posted: Fri Jun 24, 2005 10:10 am Post subject: (No subject)
code:
Ek=1/2*mv^2 Therefore, v = sqrt (2*Ek/m).
Yeah, i wish I knew formula's. The only smart class I took this year was calculus.
MysticVegeta
Posted: Fri Jun 24, 2005 12:22 pm Post subject: (No subject)
uh... I think i will go with simplycity...
talk about calculus formulas, let me first spend my first day in Grade 10 math in September lol. Those functions and relations just do nothing but confuse me....
Cervantes
Posted: Fri Jun 24, 2005 7:22 pm Post subject: (No subject)
module Asteroid
export add, update, draw, total
const asteroidDensity :=5 var asteroid :flexiblearray1.. 0of record
x, y :real
velocity, angle :real
kineticEnergy :real
radius :int endrecord
proc add
new asteroid, upper(asteroid) + 1
asteroid (upper(asteroid)).radius := Rand.Int (10, 20)
asteroid (upper(asteroid)).x := Rand.Int (maxx + 10, maxx + 50)
asteroid (upper(asteroid)).y := Rand.Int (asteroid (upper(asteroid)).radius, maxy - asteroid (upper(asteroid)).radius)
asteroid (upper(asteroid)).kineticEnergy := Rand.Int (30000, 100000)
asteroid (upper(asteroid)).angle := Rand.Int (170, 190)
asteroid (upper(asteroid)).velocity :=sqrt(2* asteroid (upper(asteroid)).kineticEnergy / %sqrt (2 * Kinetic Energy / mass) (4 / 3*3.14159265358979323846* asteroid (upper(asteroid)).radius ** 3* asteroidDensity)) end add
proc update
for i :1.. upper(asteroid)
asteroid (i).x += asteroid (i).velocity *cosd(asteroid (i).angle)
asteroid (i).y += asteroid (i).velocity *sind(asteroid (i).angle) endfor end update
proc draw
for i :1.. upper(asteroid) Draw.FillOval(round(asteroid (i).x),round(asteroid (i).y), asteroid (i).radius, asteroid (i).radius, 30) endfor end draw
end Asteroid
loop if Asteroid.total < 30then
Asteroid.add
endif
Here's a question to ponder. Is it better to make a module that contains an array of asteroids, or to create an asteroid class and create an array of pointers to the class?
MysticVegeta
Posted: Sat Jun 25, 2005 8:11 am Post subject: (No subject)
I dont think you know what i meant from my previous post, I dont know modules, i dont know classes, i dont know pointers (except maybe sometimes i came across pointers in game-hacking) but that was a long time ago. Anyways, all my asteroids will be the same shape, because they really are not asteroids, they are spaceships. I will replace the drawfilloval with Pic.Draw and make necessary changes. So i dont think i will need Kinetic Energy formula. Speed will be random. size/mass will be constant. If i change my mind i might use the module.
Cervantes: You love to use flexible array everywhere dont you? Every code i see in your post has array : 1..0 of int/string. lol.
Cervantes
Posted: Sat Jun 25, 2005 9:39 am Post subject: (No subject)
MysticVegeta wrote:
Cervantes: You love to use flexible array everywhere dont you? Every code i see in your post has array : 1..0 of int/string. lol.
Whell, this program should, most definately use flexible arrays. Even if you were to use a class, you'd make a flexible array of pointers to the class.
jamonathin
Posted: Sat Jun 25, 2005 7:53 pm Post subject: (No subject)
Yeah because flexible arrays help keep everything organized, and with them you dont need a variable to represent how many asteroids you have. You can simple use upper (fart)