Thread: Alligning to grid?

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    Alligning to grid?

    I am making this little demo that has a grid (directx application) of lines 32x32. There is this box, 32x32, which has to move randomly in the grid, alligned to it. What I do is performing a rand()%viewport.Width and Height for the x,y of the box (x,y is the position of the top-left corner of the box). The problem is, that I cant make rand() work only for randomizing values multipliers of 2, which is 32 i want. ANy ideas?
    I hope you understand the question well,
    Thanks!
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Hmm, I didn't really understand, but this is the way to create a random number that is a multiplier of 2:

    Code:
    int num = 2*(rand()%16);
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Thats is exactly what i wanted, thanks a lot!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tips for drawing a grid
    By countchocula in forum C Programming
    Replies: 12
    Last Post: 04-19-2008, 07:47 AM
  2. More Windows Trouble
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 04-12-2005, 10:02 AM
  3. Cleaning up a Grid of Memory
    By Epo in forum C++ Programming
    Replies: 9
    Last Post: 02-25-2005, 10:23 AM
  4. Find a word in a 2d grid
    By The_Kingpin in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2005, 05:38 PM
  5. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM