Windows tracking pickups for mutliple players for a level win condition?

W

Wintermute()

Guest
Hi again you helpful folks out there in game dev land!

So, my next little head scratcher in my multiplayer game. I have a game condition happening like this at present:

Player destroys AI. AI drops a moving pickup object. Moving pickup object is able to be picked up by any player. Pickup adds points to the player that picked it up. The pickup can also be destroyed by AI or other players. Pickups come from spawning AI enemies.

All well and good so far. what I want to add to this is:

-When (any) player gains the pickup, it adds a graphic (same sprite) of the pickup under their name on screen to represent the number of pickups they have gained so far.

-Code to track how many pickups each player has gained. So when the first player gains (x) pickups, I can have a level win state.

I am thinking I need to kick off both the drawing of the pickup image + the counting of pickups when the collision of player+pickup occurs ? But exactly how to achieve that I am struggling with, beyond detecting the collision and adding points, destroying the pickup instance.

Any help much appreciated... thank you!
 

TheouAegis

Member
Are the pickups unique or basically the same thing?

If they are the same thing, just have a global 1D array keeping track of how many pickups each player has.
If they are unique, have a global 2D array where the first index is the player and the second index is each powerup the player has collected.

1D array would look like:
global.pickups[ player# ] += 1

2D array would look like:
global.pickups[ player#, array_length_2D(global.pickups, player#) ] = pickup_id
 
W

Wintermute()

Guest
Are the pickups unique or basically the same thing?

If they are the same thing, just have a global 1D array keeping track of how many pickups each player has.
If they are unique, have a global 2D array where the first index is the player and the second index is each powerup the player has collected.

1D array would look like:
global.pickups[ player# ] += 1

2D array would look like:
global.pickups[ player#, array_length_2D(global.pickups, player#) ] = pickup_id
Thanks the the reply !

Yes indeed, the pickups are all the same object. I started thinking about global variables today as I need to modify the single player scoring/lives system to track score and lives for up to 4 players. A global variable for the pickups makes perfect sense.

so the line of code: assuming i am talking about obj_player1 picking it up.

global.pickups[obj_player1 ] += 1

So I can put this simply as a single line of code to be executed when the collision detection occurs, ie the player runs over the pickup, without anything else wrapped around this single line ?

And then I guess have a new object containing a step event to track the number of pickups for every player, then kickoff the level win condition when (x) pickups are reached ? or would I count instances within the collision event ?

Sorry for too many questions..... :)
 

TheouAegis

Member
Just use 0 for player1, 1 for player2, 2 for player3, and 3 for player4. Don't use the object_index as an index in an array.

Only check the score when a player gets a pickup. Don't do it every step, as that is just a needless waste of the CPU's time.
 
W

Wintermute()

Guest
Just use 0 for player1, 1 for player2, 2 for player3, and 3 for player4. Don't use the object_index as an index in an array.

Only check the score when a player gets a pickup. Don't do it every step, as that is just a needless waste of the CPU's time.
Thank you once again for the advice :)
 
Top