Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Determine when points gets to a certain number?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #16307

    Isak

    Hello,

    I need some help with how i shall test when my points reach 100,200,300,400,500 and so on without having to test every number, i want my gamespeed to increase every time the player has collected 100 points but dont wanna have to check by number, is there a way to check this?

     

    My psudocode goes like this:

    Every hundred points

    increase gamespeed

    increase avoided enemyvalue

     

    /Isak

    #16308

    Isak

    okey i have been thinking (cant test because i am at work) but shouldnt this work?:

     

    if(score > 100 && score%100 == 0)

    newLevel = true

     

    if(newLevel == true)

    speed up game

    newLevel = false

     

    My thinking went like this:

     

    that if i wont get an remainder when its reaching 100,200,300 when i now its reached a new level

     

    However i dont think it will work after thinking about it because if the player has say 90 points and gets 15 points when the scoredata is 105 points and when my if cant recognize that is has passed a 100:e so i need som way to check every time it pass a certain number like every 100:e or 1000:e

     

    /Isak

     

     

    #16309

    Günther
    Felgo Team

    Hi Isak!

    you can add a check like this whenever you increase the score:

    Scene {
      id: gameScene
    
      property var totalScore: 1234 // holds total score, 1234 = dummy data
    
      // increase score with relativeScore parameter and check 100 pts boundary for speed up
      function increaseScore(relativeScore) {
        var modulo = totalScore % 100
        var missing = 100 - modulo // points required to reach new 100pt step 
    
        gameScene.totalScore += relativeScore // increase score
    
        // check if adding relativeScore will complete another 100 pts step
        if(relativeScore >= missing) {
          // increase difficulty
        }
      }
    }

    Best,
    Günther

    #16310

    Isak

    GT said:

    Hi Isak!

    you can add a check like this whenever you increase the score:

    Scene {
      id: gameScene
    
      property var totalScore: 1234 // holds total score, 1234 = dummy data
    
      // increase score with relativeScore parameter and check 100 pts boundary for speed up
      function increaseScore(relativeScore) {
        var modulo = totalScore % 100
        var missing = 100 - modulo // points required to reach new 100pt step 
    
        gameScene.totalScore += relativeScore // increase score
    
        // check if adding relativeScore will complete another 100 pts step
        if(relativeScore >= missing) {
          // increase difficulty
        }
      }
    }

    Best,
    Günther

    Hello Günther,

     

    Where does relativeScore come from?

     

    Kind regards

    /Isak

    #16311

    Günther
    Felgo Team

    In the above code example, the increaseScore function expects the value for relativeScore to be passed when it is used.

    For example, instead of increasing the score with a line like gameScene.totalScore += 15, you call gameScene.increaseScore(15), which uses the value 15 for then.

    The line gameScene.increaseScore(15) then

    • Increases gameScene.totalScore by 15
    • Checks if adding 15 to totalScore exceeds a 100 pt mark

    Best,
    Günther

    #16312

    Isak

    GT said:

    In the above code example, the increaseScore function expects the value for relativeScore to be passed when it is used.

    For example, instead of increasing the score with a line like gameScene.totalScore += 15, you call gameScene.increaseScore(15), which uses the value 15 for then.

    The line gameScene.increaseScore(15) then

    • Increases gameScene.totalScore by 15
    • Checks if adding 15 to totalScore exceeds a 100 pt mark

    Best,
    Günther

    Hello Günther,

    I have tested it now and it works like a charm:D It has really been a difficult nut to crack for me. Thanks for the help.

     

    /Isak

Viewing 6 posts - 1 through 6 (of 6 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded