Results 1 to 3 of 3

Thread: Random positions

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2003
    Location
    QLD, AUSTRALIA
    Posts
    17

    Random positions

    I am making a snake game. I need to know how to make little fruit pop up in different area on the form. also I would like to know how to make a barrier for the snake so if it hits the wall it will die. Thanx in advance for any replies.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    For the fruits use a random number generator.

    For the barrier, simply do an out-of-bounds check for the head each step.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Your code for the random fruit position should look like this:

    VB Code:
    1. Private Function MoveFruit()
    2.     Randomize
    3.    
    4.     X = Int(Rnd * MapWidth) * FruitWidth
    5.     Y = Int(Rnd * MapHeight) * FruitHeight
    6.     Fruit.Move X, Y
    7. End Function

    MapWidth and MapHeight would be the number of tiles wide the map is, not pixels.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

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