0
\$\begingroup\$

I am new to the scripting world and I am currently trying to add a score multiplier to the game code I am working on.

Right now the score is set to increase as the player runs across the level however I want to set it up so that the players gains X amount of score for every Y amount of distance traveled. I also want to add a multiplier for when they come into contact with certain objects X amount of time. Any help would be greatly appreciated.

\$\endgroup\$
1
  • \$\begingroup\$ For every metre you travel in distance, add that metre to the score. If you come into contact with any objects, add a score. There's no need for a multiplier. \$\endgroup\$ – Poriferous Mar 7 '15 at 18:44
3
\$\begingroup\$

I'll use pseudocode examples here.

Rather than setting score based on current position

score = distance;

increment their score based on a change in position over time. Depending on your code this should be fairly easy. If the character is moving then you're changing it's distance over time already. Somewhere in your game loop you've got something that looks like this:

position_x = position_x + speed;

or maybe

position_x += 5;

(I recommend the first case, by the way. Using a variable means it should be easy to make a pick up item that increases or decreases speed)

Once you've found this, you can add a line right there to increment your score

position_x = position_x + speed;
score = score + 1;

Now for a multiplier. Normally you don't want to multiply the score by anything, and sometimes you want to double or triple the gains made. So, add a new variable called "multiplier", set it to one, and use that everywhere you add to the score:

integer variable "multiplier" = 1;

(in main game loop){
    position_x = position_x + speed;
    score = score + 1*multiplier;
}

and

(on item pickup){
     score = score + itemScoreValue*multiplier;
}
\$\endgroup\$
1
  • \$\begingroup\$ +1 This is a good example on how to turn an unclear question into a good question, just by answering it clearly! Nice! \$\endgroup\$ – Gustavo Maciel Nov 25 '17 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.