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

Monster refactoring #27

Open
IanWitham opened this issue Apr 28, 2012 · 1 comment
Open

Monster refactoring #27

IanWitham opened this issue Apr 28, 2012 · 1 comment

Comments

@IanWitham
Copy link
Contributor

move_monsters doesn't really belong in the map object. Move should really be a method of the Monster class. That way, thanks to duck typing each monster could potentially have different behaviour.
The movement could then be called within the game loop:

for monster in monsters_on_this_level:
    monster.move()

Also monsters could possibly take care of drawing themselves as well:

for monster in monsters_on_this_level:
    monster.draw(surface_to_draw_on)

Also... monsters, treasures etc probably shouldn't have their own map objects to keep track of them, and you shouldn't have to loop through every square on the map just to find your monsters. It would be preferable if each monster keeps track of it's own coordinates on the map. That way you could keep track of whether there is a monster on a given map square just like this:

# check if a square (x, y) is occupied by a monster
monsters_on_square = [m for m in monsters_on_level if m.coords == (x, y)]
# or if we know that only one monster is allowed per square:
monster_on_square = [m for m in monsters_on_level if m.coords == (x, y)][0]

Regarding that last comment, I know it is probably desirable to have one monster per square, but it is probably OK to have multiple treasures occupy the same square.

@kcunning
Copy link
Owner

I have to agree on this. I'm doing some basic AI, so I'm coming to the same conclusion. Let me see if I can get this working today.

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

2 participants