Jump to content

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:


I'm using C here.

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


Link to comment
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.

Link to comment
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 ?

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...