Results 1 to 3 of 3

Thread: [RESOLVED] Confusing Center code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    129

    Resolved [RESOLVED] Confusing Center code

    Hello,
    I'm having problems with a mathematical equation to get center position.

    I'm making a game in VB6 which involves cards to be generated in center of some offset I pick..

    I put a few cards in microsoft paint program to see how the X coordinate changes as the spread out more and more seems to exactly 30 pixels apart.. but the thing is the cards have to also overlap other cards meaning at first I thought it was possible without re-drawing everything just keep adding cards and they would sort out and center. But it seems the only way is to provide the size of how much cards you want to display then it's possible to center those.. and still I cannot do that.

    Here is the stats I gathered
    X:35 = 1 CARD CENTERED.
    X:20 X:50 = 2 CARDS CENTED
    X:5 X:35 X: 65 = 3 CARDS CENTERED
    X:-10 X:20 X:50 X:80 = 4 CARDS CENTERED.

    figured they are 30 SUBTRACTED from previous card.

    Now i'm trying to write a function that returns X for next card Position.

    Code:
    function getCenterOffset(cardPos as integer, numCards as integer)
    //all I got at the moment.
    getCenterOffset = 0
    end function
    honestly I'm just looking for the equation..

    I been fooling around with the math and came up with this..

    curPosition, maxCards
    0 and maxCards = 4

    20+15x0=20 [-30] = -10
    20+15x2=50 [-30] = 20
    20+15x4=80 [-30] = 50
    20+15x6=110 [-30] = 80

    curPosition, maxCards
    0 and maxCards = 3

    20+15x1=35 [-30] = 5
    20+15x3=65 [-30] = 35
    20+15x5=95 [-30] = 65

    curPosition, maxCards
    0 and maxCards = 2

    20+15x2=50 [-30] = 20
    20+15x4=80 [-30] = 50

    curPosition, maxCards
    0 and maxCards = 1

    20+15x3=65 [-30] = 35


    As you can see from my math above I got to something.. when maxCards is odd the multipiler is odd and even is even..
    Also the last card position is maxCards+2 from my equations but i dont know what else to do to make it a algorithm


    note maxCards 4 is not the limit it could go very high maybe up to 30.. and i don't want them in a huge array or loops i know its possible with good old math equation.


    So yah i'm stumped can someone help me out thanks

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Confusing Center code

    This is the function you need:
    Code:
    Function GetCardX(ByVal CardNum As Integer, ByVal NumOfCards As Integer) As Integer
        If (CardNum > 0) And (NumOfCards >= CardNum) Then
            GetCardX = 20 - 15 * NumOfCards + 30 * CardNum
        Else
            Err.Raise 9 '-- treat it as subscript out of range
        End If
    End Function
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    129

    Re: Confusing Center code

    20-15? isn't that just like

    5 * NumOfCards + 30 * CardNum?

    PEMDAS is.. Parenthesis | Exponents | Multiplication | Division | Addition | Subtraction

    i guess it's like

    GetCardX = 20 - (15 * NumOfCards) + (30 * CardNum)

    I don't know I'm not a math wiz lol thanks for everything man.. don't know how it works but glad it works i'll debug further to figure out how it works.

Tags for this Thread

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