Results 1 to 5 of 5

Math Help - Problem

  1. #1
    Newbie
    Joined
    May 2008
    Posts
    3

    Problem

    Hi, this problem is a little hard to explain. I'm working on a programming problem for a game. These numbers are the position on the screen, and each position on the screen exists in a tile. Note: I'm using hexidecimal numbers

    $00 to $07 is tile1
    $08 to $0F is tile2
    $10 to $17 is tile3...

    I want to be able to put any number into a formula that will come out with the tile number that number is in.
    If I put in $06 the formula will come out with the number $01.
    If I put in the number $14 the formula will come out with the number $03.

    Can you explain what kind of formula/equation would do this?
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Ash11 View Post
    Hi, this problem is a little hard to explain. I'm working on a programming problem for a game. These numbers are the position on the screen, and each position on the screen exists in a tile. Note: I'm using hexidecimal numbers

    $00 to $07 is tile1
    $08 to $0F is tile2
    $10 to $17 is tile3...

    I want to be able to put any number into a formula that will come out with the tile number that number is in.
    If I put in $06 the formula will come out with the number $01.
    If I put in the number $14 the formula will come out with the number $03.

    Can you explain what kind of formula/equation would do this?
    tile_number=(x/$008)+$001

    here I am assuming that (hex) integer division is rounded down to the largest integer less than actual result.

    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    May 2008
    Posts
    3
    Thanks, that works great!
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    May 2008
    Posts
    3
    Ok, I've just realised I have to specify the x and y position for the sprite, so that makes it more complicated than I realised, sorry.

    if x = $00 to $07 AND y = $00 to $07 it's tile1
    if x = $08 to $0F AND y = $00 to $07 it's tile2
    if x = $10 to $17 AND y = $00 to $07 it's tile3...

    one row down:
    if x = $00 to $07 AND y = $08 to $0F it's tile33
    if x = $08 to $0F AND y = $08 to $0F it's tile34
    if x = $10 to $17 AND y = $08 to $0F it's tile35...

    There's 32 tiles on every row. The tiles are numbered from the top row going left to right then one row down going left to right etc... like this

    1 2 3...
    -> -> -> -> -> -> -> -> -> -> -> ->

    33 34 35...
    -> -> -> -> -> -> -> -> -> -> -> ->

    65 66 67...
    -> -> -> -> -> -> -> -> -> -> -> -> ...

    I need to have a function that I put x and y into and it tells me the tile number. Can you help?
    Last edited by Ash11; May 7th 2008 at 12:51 AM.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Ash11 View Post
    Ok, I've just realised I have to specify the x and y position for the sprite, so that makes it more complicated than I realised, sorry.

    if x = $00 to $07 AND y = $00 to $07 it's tile1
    if x = $08 to $0F AND y = $00 to $07 it's tile2
    if x = $10 to $17 AND y = $00 to $07 it's tile3...

    one row down:
    if x = $00 to $07 AND y = $08 to $0F it's tile33
    if x = $08 to $0F AND y = $08 to $0F it's tile34
    if x = $10 to $17 AND y = $08 to $0F it's tile35...

    There's 32 tiles on every row. The tiles are numbered from the top row going left to right then one row down going left to right etc... like this

    1 2 3...
    -> -> -> -> -> -> -> -> -> -> -> ->

    33 34 35...
    -> -> -> -> -> -> -> -> -> -> -> ->

    65 66 67...
    -> -> -> -> -> -> -> -> -> -> -> -> ...

    I need to have a function that I put x and y into and it tells me the tile number. Can you help?
    row=y/$08+1
    col=x/$08+1

    ncol=$020

    tile=ncol*(row-1)+col

    (needs some checking)

    RonL
    Follow Math Help Forum on Facebook and Google+

Search Tags


/mathhelpforum @mathhelpforum