Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make explicit dedicated reference to player #7

Open
Bravo555 opened this issue Jun 2, 2018 · 0 comments
Open

Make explicit dedicated reference to player #7

Bravo555 opened this issue Jun 2, 2018 · 0 comments

Comments

@Bravo555
Copy link
Member

Bravo555 commented Jun 2, 2018

GAME.entities[0].add_velocity(-1)

Here, entities[0] is just a player, but for you to know that, you need to check how the entities list is populated. Addressing a specific member of the collection based strictly on index is not considered a good practice.

The order of the array members should not be trusted!

I suggested you to use entities list as a means to print them all to screen in one loop. You should not address to specific members of array to do different stuff with them.

Better method

The state of your game is just something like that:

state = {
    player,
    enemyField = {
        enemy,
        enemy,
        ...
    }
}

So, make references to player and enemyField seperate (pro-tip: make entities a dictionary!). You just need to draw() two things, which is not that much! But if that's too much, here how you can iterate over a dictionary:

entities = {
    player: PlayerShip(),
    enemyField: EnemyField()
}

for entity in entities.values():
    entity.draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant