Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Multiple asteroids.
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Cervantes




PostPosted: 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
Sponsor
sponsor
jamonathin




PostPosted: Fri Jun 24, 2005 10:10 am   Post subject: (No subject)

code:
Ek=1/2*mv^2 Therefore, v = sqrt (2*Ek/m).
Eh

Yeah, i wish I knew formula's. The only smart class I took this year was calculus.
MysticVegeta




PostPosted: 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




PostPosted: Fri Jun 24, 2005 7:22 pm   Post subject: (No subject)

Simplicity?

Turing:

View.Set ("graphics:600;600;nobuttonbar;offscreenonly")
colourback (black)

module Asteroid
    export add, update, draw, total
    const asteroidDensity := 5
    var asteroid : flexible array 1 .. 0 of
        record
            x, y : real
            velocity, angle : real
            kineticEnergy : real
            radius : int
        end record

    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)
        end for
    end update

    fcn total : int
        result upper (asteroid)
    end total

    proc draw
        for i : 1 .. upper (asteroid)
            Draw.FillOval (round (asteroid (i).x), round (asteroid (i).y), asteroid (i).radius, asteroid (i).radius, 30)
        end for
    end draw

end Asteroid


loop
    if Asteroid.total < 30 then
        Asteroid.add
    end if

    Asteroid.update

    cls
    Asteroid.draw
    View.Update
    delay (5)

    exit when hasch()
end loop


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




PostPosted: Sat Jun 25, 2005 8:11 am   Post subject: (No subject)

Shocked 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




PostPosted: 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. Smile
jamonathin




PostPosted: 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)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 22 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: