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

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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