Generators
Hi,
I'm new to the forums at new to game development too.
The case:
I'm actually, creating my server for the game. Which is a mmorpg.
Using python with twisted for network.
The problem:
I need to find a dynamic way to create monsters/items.
I need it to be dynamic and independent, because I won't be like:
item = Potion() #where Potion would be the item class
or
monster1 = Zombie() #where Zombie would be a class too
I need to fill maps with them, so I need a dynamic way, a function like:
spawn(mapname, monstertype, quantity)
Any ideas? I'm not a master python programmer yet, so it can take a while
until I grasp the explanations ^^.
Thanks for your time,
DarkSorrow.
You might want to start looking at controlling how and where you spawn monsters using a series of probability distributations.
Monster type, location and treasure could all be controlled by a chance of occurance.
gen = LevelGenerator()
gen.AddMonster(type = Zombie, probability = 0.5)
gen.AddMonster(type = Skeleton, probability = 0.4)
gen.AddMonster(type = Dragon, probability = 0.1)
level = gen.SpawnLevel(meanMonsters = 15, varianceMonsters = 4)
Monster type, location and treasure could all be controlled by a chance of occurance.
gen = LevelGenerator()
gen.AddMonster(type = Zombie, probability = 0.5)
gen.AddMonster(type = Skeleton, probability = 0.4)
gen.AddMonster(type = Dragon, probability = 0.1)
level = gen.SpawnLevel(meanMonsters = 15, varianceMonsters = 4)
Quote:Original post by XXX_Andrew_XXX
You might want to start looking at controlling how and where you spawn monsters using a series of probability distributations.
Monster type, location and treasure could all be controlled by a chance of occurance.
gen = LevelGenerator()
gen.AddMonster(type = Zombie, probability = 0.5)
gen.AddMonster(type = Skeleton, probability = 0.4)
gen.AddMonster(type = Dragon, probability = 0.1)
level = gen.SpawnLevel(meanMonsters = 15, varianceMonsters = 4)
The problem is the (using your example) gen.AddMonster function, I mean, each monster will be a different entity, so when the player attacks a monster it will only damage this monster, instead of all others. I mean, I don't know how I will create instances of them.
Thanks
When you type "monster1 = Zombie()", that does create a separate instance. So essentially, that is all you need. The rest is just deciding how to store them all. Inside the spawn() function, you decide which class you want, create an instance as above, and then return it, to be stored in a list or something.
Quote:Original post by Kylotan
When you type "monster1 = Zombie()", that does create a separate instance. So essentially, that is all you need. The rest is just deciding how to store them all. Inside the spawn() function, you decide which class you want, create an instance as above, and then return it, to be stored in a list or something.
Ahh, so basically what I need is something like this?
#CODE START
class Monster:
def __init__(self, name=None):
self.name = name
monsterlist = []
for x in range(10):
monster = Monster('Zombie')
monsterlist.append(monster)
#CODE END
Thanks for the info :) just one more question, when the monster is killed the instance need to be deleted, how would I do it?
Thanks once more,
Bye.
You remove it from whatever contains it. '5.1 More on Lists'.
PS. Use the code tag for short code snippets and the source tag for longer ones, to make your code easier to read. This is especially important for Python where the indentation matters.
PS. Use the code tag for short code snippets and the source tag for longer ones, to make your code easier to read. This is especially important for Python where the indentation matters.
Quote:Original post by Kylotan
You remove it from whatever contains it. '5.1 More on Lists'.
PS. Use the code tag for short code snippets and the source tag for longer ones, to make your code easier to read. This is especially important for Python where the indentation matters.
Hmm, thanks for the advice, but I still see a problem.
If I create 10 instances of the monster in a list(all will be called monster), and the third monster in the list dies(still, I'll have not control of which one dies), I need to delete the third list object, BUT, since all the monsters have the same name, using
mylist.index(monster)
since all the instances are called monster, I will get the first one. Sorry If I'm looking so dumb, that's my first attempt into a game, and I'm really confused ^^Thanks for all,
DarkSorrow.
Maybe your spawn function could have some sort of static ID generator/counter with a sister ID variable in your 'monster' class. This way all 'monsters' can be tracked and controlled by an ID instead of their general class name.
Quote:Original post by Xyphyx
Maybe your spawn function could have some sort of static ID generator/counter with a sister ID variable in your 'monster' class. This way all 'monsters' can be tracked and controlled by an ID instead of their general class name.
Hmm, I'll look into this, thanks :)
DarkSorrow.
Quote:Original post by darksorrowQuote:Original post by Kylotan
You remove it from whatever contains it. '5.1 More on Lists'.
PS. Use the code tag for short code snippets and the source tag for longer ones, to make your code easier to read. This is especially important for Python where the indentation matters.
Hmm, thanks for the advice, but I still see a problem.
If I create 10 instances of the monster in a list(all will be called monster), and the third monster in the list dies(still, I'll have not control of which one dies), I need to delete the third list object, BUT, since all the monsters have the same name, usingsince all the instances are called monster, I will get the first one. Sorry If I'm looking so dumb, that's my first attempt into a game, and I'm really confused ^^mylist.index(monster)
Look at the method above index() in the link I sent you.
Incidentally, your instances are not called 'monster'. They have no name, as such. In your last code example, 'monster' is just a variable name that refers to an instance temporarily.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement