Another question again, still Python, yea?
So while I'm figuring out Pathfinder and what to do with it (should I even bother with it) I still want to make progress, and this is my next question.
Making multiple levels.
I have tried searching on google, but so far have not found anything too promising. My question is how?
Suppose that we have 2 levels. One of them involves the player killing everything, and another involving the player getting to a certain coordinate. We can, of course, do something like this.
class player:
def __init__(self, x, y):
self.x = x
self.y = y
self.level = 1
In our main loop, we'd do something like this:
if player.level == 1 and len(enemies) == 0:
#Everything's dead, we can advance to level 2.
player.level += 1
elif player.level == 2 and player.x == 450:
#We reached the winning x, we can advance now
player.level += 1
That's not bad, right? Of course, our loop will get exponentially bigger the more levels we add to our game. Another way I thought of doing level loops is like so
class player:
def __init__(self, x, y):
self.x, self.y = x, y
self.level = 0
level_loops = [lev1, lev2] #In our main loop, we'd do something like this: level_loops[player.level]() #Calling our level loop def lev1(): if len(enemies) == 0: #We won! Next level player.level += 1 def lev2(): if player.x == 450: #We won! Next level player.level += 1
This makes my main loop cleaner and smaller, but does not kill my if statements, it just hides them.
What are some other ways of doing level loops? Am I overthinking it all again?
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector