Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2020-05-10 14:05:52

Sin
Member
Registered: 2019-08-11
Posts: 16

Help with Score Display

Hello again,

I have received a great bit of assistance both here and in a GBDev Discord, however there is an issue I cannot seem to find a fix for. I am trying to get my score to display, and it works fine up until 99 points, after which it begins to act unpredictably. I have looked at the code for a few days and still cannot see where my issue lies. Below is where I calculate and display the sprites for my score. It appears that after it hits three digits, the third digit remains as a 0 for some time while the first and second update, though incorrectly. Problem persists both in the 2.95 and 2020 version of GBDK.

Code:

// Sets score tiles based on numerical values
void scoredisplay()
{
    // Set sprite tiles for score
    set_sprite_tile(15, (score1 << 1) + 58);
    set_sprite_tile(16, (score2 << 1) + 58);
    set_sprite_tile(17, (score3 << 1) + 58);
    set_sprite_tile(18, (score4 << 1) + 58);    

} //End Score display

// Math function that separates the score into individual digits
void scoremath()
{     scoretemp = gamescore;
    scorenum = gamescore;
    scorefactor = 1;
    scoreflag = 1;
    while(scoretemp)
    {
        scoretemp=scoretemp/10;
        scorefactor = scorefactor*10;
    }

    while(scorefactor>1)
    {
        scorefactor = scorefactor/10;
                        
        if (scoreflag == 1)     // If first digit
        {
            score1 = scorenum/scorefactor;      // Set to left most digit
        }
                        
        else if (scoreflag == 2)     // If second digit
        {
            score2 = scorenum/scorefactor;  // Set to second from left digit
        }      

        else if (scoreflag == 3)        // If third digit       
        {
            score3 = scorenum/scorefactor;
        }   

        else             
        {
            score4 = scorenum/scorefactor;
        } 

        scoreflag +=1;  // Counter increase

                        
        scorenum = scorenum % scorefactor;
    }     


} // End Score Math     
     
// Update score    
void setscore()
{
    //Reset all variables to default before doing any math
    scoretemp = gamescore;
    scorenum = gamescore;
    scorefactor = 1;
    scoreflag = 1;

    // If score only has one digit
    if (scoretemp < 10)
    {
        // Do math and set display for single digit
        scoremath();
        scoredisplay();

        // Hide the rest of the unused number places
        set_sprite_tile(16,78);  
        set_sprite_tile(17,78);
        set_sprite_tile(18,78);             
    }

    // If score has only two digits
    else if (scoretemp < 100)
    {               
        scoremath();
        scoredisplay();

        // Hide the rest of the unused number places
        set_sprite_tile(17,78);
        set_sprite_tile(18,78);
    } 
 
    // If score has only three digits
    else if (scoretemp < 1000)
    {               
        scoremath();
        scoredisplay();

        // Hide the rest of the unused number places
        set_sprite_tile(18,78);    

    } 

    // If score has only three digits
    else 
    {
        scoremath();
        scoredisplay();
    } 

} // end setscore

Last edited by Sin (2020-11-24 23:33:49)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson