Changing lives/scores on 'Player' objects without if statements in multiplayer extension

Below I have a simple multiplayer project with two player sprites at the top that will move to dodge snakes. I’m trying to see if it’s possible to have a single overlap event between players and enemies and if I can utilise ‘getPlayerBySprite’ in some way to get the player and use that player object to directly change that player’s lives.

so it could look something along the lines of

sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function(playerSprite, enemySprite) {
// let thisPlayer be the player attached to playerSprite
// change the lives thisPlayer by -1
})

I’m aware I could do a few things like attach sprite data to the sprite representing the current player and use an if statement inside the overlap event and I could use different spriteKinds with different overlap events, I’m just scoping out other methods of approaching this.

Thanks for your time!

1 Like

Oh ok. I think I know what you are trying to do. In my opinion, I would be much simpler to just make two separate overlap events and make a new player type to do that. Just make player 2 sprite kind food or something. Or make a new type for it.

I agree that would be simpler for now, but imo logically it would be neater and less repetitive to have a single ‘player’ overlap event that can interact with the different numbered players’ set/change life and score functions.