I know there are a ton of map generators out there already, but I was considering trying my hand at it as well. More as a learning experience though, and not as an attempt to improve on them in any way. Lord knows I'm not that good.
But I was thinking about it and I think I may be able to pull it off. I threw together some pseudo code to help me out with the logistics, and I wanted to see if anyone had any improvements or maybe some comments.
Here's what I've got so far:
class RoomObj:
init(type): #types can be hallways or rooms
attributes, size, type, image etc.
randomize image based on type given
update:
pass
class Room(RoomObj):
create room type=Room
class Hall(RoomObj):
create hall type=Hall
def genMap():
numofrooms = random number of rooms from range
listofrooms = []
listofmapobj = []
for i in range(numofrooms):
listofrooms.append(Room())
for i in range(len(listofrooms)):
create room objects with a "hallway" type
if i is not the last iterate:
listofmapobj.append(Hall(listofrooms[i], listofrooms[i+1]))
listofmapobj.append(listofrooms[i])
return listofmapobj
I still need to figure out exactly what parameters the room and hallway classes need to be given, but the rooms will initially just create random sized rectangular rooms, then choose a random image from a pre-loaded set. The room placement would have to check to ensure there are no collisions with other room rectangles. And finally the hallway objects would base their size and shape on the locations of the two rooms given as a parameter.
There are a lot of other particulars I still need to figure out, but I think it is doable. and it should be an interesting project to work on.
I'll have to post whatever I end up with at the end of this little adventure.
-newt
No comments:
Post a Comment