Jump to content

How to create score modifier based on overlap?


MarrMooMoo
 Share

Recommended Posts

I'm currently making my first ever game and am fairly new to coding so I apologize if this code doesn't make much sense.

In my game the player sprite changes with the collection of various items.  When a certain item is collected I want it so that the score increases when the player is in a certain zone and decreases when the player is out of that zone all while the player sprite is that specific model, and then I want the score to decrease if the player is in that zone while the sprite model isn't correct. (Sorry if that doesn't make sense!)

Here is what I have so far:

//in the update function:
game.physics.arcade.overlap(player, laneC, laneCScoreModifier, null, this);

//outside update function:
function laneCScoreModifier (player, lane) {
    if (player.key == 'heroc') {
        timer = setInterval(plusScore, 1000);
        if (! game.physics.arcade.overlap(player, laneC)){
            clearInterval(timer);
        }
    } else {
        timer = setInterval(minusScore, 1000);
        if (player.key == 'heroc') {
            clearInterval(timer);
            timer = setInterval(plusScore, 1000);
            if (!game.physics.arcade.overlap(player, laneC)){
            clearInterval(timer);
            }
        }
    }
}
function plusScore(){
    score++;
}
function minusScore(){
    score--;
}

So my first guess is the '!' modifier isn't doing anything there.  When I run the game once the player enters the zone while not having the correct sprite the timer never stops, even if they leave.  Anyone have any idea how I should approach this?  Any help will be greatly appreciated!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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