Results 1 to 15 of 15

Thread: Moving Stars

  1. #1

    Thread Starter
    Member 110359's Avatar
    Join Date
    Jun 2002
    Location
    Melbourne, Australia
    Posts
    43

    Moving Stars

    I was wondering how to get scrolling stars in the background of a game that I'm making. I would appreciate any help.

    110359
    Why is it that when you kill one man people call you a murderer and when you kill one thousand you are a conqueror?

  2. #2
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    299
    scroll vertically, horizontally, ? Vertical is something like this. It assumes that you want 100 stars scrolling vertically in a 100*100 pixel area.



    VB Code:
    1. Type PointAPI
    2.      x as long
    3.      y as long
    4. End Type
    5. Sub Game_Loop()
    6. Dim StarPos(99) as POINTAPI,lCounter1 as Long
    7.      For lCounter1 = 0 To 99
    8.           StarPos(lCounter1).x=Rnd*100
    9.           StarPos(lCounter1).y=Rnd*100
    10.      Next lCounter1
    11.  
    12.      While Running
    13.  
    14.           For lCounter1 = 0 To 99
    15.                 StarPos(lCounter1).y=(StarPos(lCounter1).y+1) Mod 100
    16.                Form1.PSet (StarPos(lCounter1).x,StarPos(lCounter1.y)),vbWhite
    17.           Next lCounter1
    18.  
    19.  
    20.      Wend
    21. End Sub

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    That's a nice loop snake!

    But, he may mean like the screensaver... It's not all that hard to do, but it is a challenge nonetheless. To have it come from the middle, I suggest using sine and cosine with a different radius and angle for each star. Expand the radius by the star's speed (if they all have the same speed it looks flat and boring) and draw it. When it's offscreen, you can create it in the middle again and start the loop over.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Oh, snake, put a doevents in there or else your code will never be displayed
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    299
    [hides head in ass for shame]
    oops, I am sorry. Doevents is also needed.
    [/hides head in ass for shame]

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    It will look more 3D if a star's brightness is proportional to its speed. So a fast star is bright and a slow star is not
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  7. #7

    Thread Starter
    Member 110359's Avatar
    Join Date
    Jun 2002
    Location
    Melbourne, Australia
    Posts
    43

    Thanks

    Thanks for the help guys. Yes I did mean vertically. Again thank you.

    110359
    Why is it that when you kill one man people call you a murderer and when you kill one thousand you are a conqueror?

  8. #8

    Thread Starter
    Member 110359's Avatar
    Join Date
    Jun 2002
    Location
    Melbourne, Australia
    Posts
    43

    Question

    Where ever I put the section:
    Type PointAPI
    x As Long
    y As Long
    End Type
    It tells me it can't go there. Also where should the doevents go.
    Why is it that when you kill one man people call you a murderer and when you kill one thousand you are a conqueror?

  9. #9
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    You're declaring a Type, and declarations are always before the subs and functions

    The DoEvents should be right after the While.
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Originally posted by Jotaf98
    It will look more 3D if a star's brightness is proportional to its speed. So a fast star is bright and a slow star is not
    As that is true, far away stars could be really bright... add some randomness into that
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11

    Thread Starter
    Member 110359's Avatar
    Join Date
    Jun 2002
    Location
    Melbourne, Australia
    Posts
    43

    Unhappy

    It keeps coming up with an error saying:
    Cannot define as a Public user-defined type within a private object module.
    Why is it that when you kill one man people call you a murderer and when you kill one thousand you are a conqueror?

  12. #12
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    299
    Select Project->Add Module

    Not class module, not a form, but a module.

  13. #13

    Thread Starter
    Member 110359's Avatar
    Join Date
    Jun 2002
    Location
    Melbourne, Australia
    Posts
    43
    Sorry about all the questions. Thanks for all the help.
    Why is it that when you kill one man people call you a murderer and when you kill one thousand you are a conqueror?

  14. #14
    New Member
    Join Date
    Aug 2002
    Location
    Palmdale, Cali
    Posts
    4
    All you have to do is declare the type as a private type...

    Private Type PointAPI
    x As Long
    y As Long
    End Type

    no prob, right!

  15. #15
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    In my game craft, stars move opposite to the direction of travel.
    Check it out :

    http://www.coolground.com/plenderj/1.0.17.zip

    Older versions of the game also had stars moving at different speeds in the background to make them look farther away, but that effect only works if you're travelling in the one direction.
    It looks stupid if the player changes direction often
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width