IGNORED

# Math help

## Recommended Posts

The Game Boy is a lot like the Intellivision in regards to 8x8 tiles making up a screen, so I'm asking this here.

The Game Boy screen is 360 tiles, 20 x 18 tiles. Each tile is 8x8 pixels. What I am trying to do is make the program tell which tile my 8x8 sprite is on and then react accordingly depending on which tile is being touched by the sprite.

Right now I have this:

whichtile=((franky/8)*20)+(frankx/8);

I'm using C here.

But this does not work. What am I doing wrong?

##### Share on other sites

Is there a version of C for the Intellivision now?

This should work, assuming that "whichtile" is a 16 bit number.

whichtile=((franky/8)*20)+(frankx/8);

tilevalue = *(BACKTAB + whichtile) ;

Catsfolly

##### Share on other sites

I got it working. There is no C for Intellivision, I was doing it for Game Boy.

The problem was I was using 8 bit variables where I should have been using 16 bit ones.

##### Share on other sites

Also sometimes you may have to offset a few pixels, depending on if the first screen column starts where the upper left pixel of the sprite is 0,0. In cases where it is possible to position the sprite partly outside of the screen area, e.g. if the system has a border outside of the screen, you might have to subtract e.g. 50 from both sprite X and Y before calculating screen position. Even more so, you are calculating the position for the upper left pixel of your sprite, while the other 63 pixels may lie one position to the right and one row down. I would offset my sprite coordinates so you are calculating the screen position of the midpoint on the sprite, but still you might get the wrong position, in particular if it is allowed to travel smooth less in diagonal directions.

##### Share on other sites

What is the best way to test the condition that the score has passed a multple of a given number ?

Assume you need to give a bonus each time the player passes a multiple of 500pts

Let #MyScore be the current score and #DeltaScore the number of points gained in the last game iteration

Under the assumption that #DeltaScore is always less than 500, I did in this way

```#x = #Myscore % 500
#y = (#Myscore +#DeltaScore ) % 500

If (#x<#y) then gosub GiveBonus

#Myscore  = #Myscore +#DeltaScore
#DeltaScore = 0 ' accumulate points of thenext iteration
```

Is there a way that takes less CPU cycles, e.g. with only one (or even without) modulus operation ?

##### Share on other sites

Nevermind, I've found a better way

##### Share on other sites

Just now, artrag said:

Nevermind, I've found a better way

Would you mind sharing it?

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.