Creation of object in game

This is a discussion on Creation of object in game within the Game Programming forums, part of the General Programming Boards category; Hi everoyne I understand about how classes work but i have an issue with creating new objects. In my game ...

  1. #1
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29

    Exclamation Creation of object in game

    Hi everoyne

    I understand about how classes work but i have an issue with creating new objects. In my game i want to read a file which has level data. No problem.

    What i want to do is make a number of enemies that the file determins and then sets their attributes. So if my file said 10 goblins the program would make 10 seperate goblins. Would their names be enemy.goblin1, enemy.goblin2..... enemy.goblin10

    How do i tell the difference between two goblins????

    The only way i could think was to hard code the levels, that i dont want to do!. I want to beable to choose how many goblins there are and their attributes from an external file. Is it done with a loop like:

    Code:
    do 
    {
    
    "create new goblin"
    "set attributes"
    i ++
    
    }(while i <= number of goblins)
    thanks
    Last edited by bobbinator; 04-05-2011 at 06:38 AM.

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by bobbinator View Post
    Hi everoyne

    I understand about how classes work but i have an issue with creating new objects. In my game i want to read a file which has level data. No problem.

    What i want to do is make a number of enemies that the file determins and then sets their attributes. So if my file said 10 goblins the program would make 10 seperate goblins. Would their names be enemy.goblin1, enemy.goblin2..... enemy.goblin10

    How do i tell the difference between two goblins????

    The only way i could think was to hard code the levels, that i dont want to do!. I want to beable to choose how many goblins there are and their attributes from an external file. Is it done with a loop like:

    Code:
    do 
    {
    
    "create new goblin"
    "set attributes"
    i ++
    
    }(while i <= number of goblins)
    thanks
    You have to create the goblin classes dynamically, since you don't know how many goblins each level holds at compile time, you can't do it statically.

    One way to do it is with a list or a vector of pointers to said goblin class, then you can just add the number of pointers that you need to your container, and then iterate through it and allocate them using "new". If each goblin has the same attributes, then you can use the constructor of the goblin class to set them to desired values, another way to do it is to statically create an instance of the goblin class, manually set all attributes, and then assign them to the goblins in your entitylist using an overloaded =operator.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    Monster vector. Get the number of mobs you want and iterate through a loop while allocating space for the mob with new and pushing it in the vector. Basically what the user above said.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [freefps]Tactical Assault coders needed
    By Sickmind in forum Projects and Job Recruitment
    Replies: 4
    Last Post: 05-07-2010, 06:06 PM
  2. Replies: 15
    Last Post: 10-20-2009, 10:39 AM
  3. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 02:22 AM
  4. game creation questions
    By ajrillik in forum Game Programming
    Replies: 4
    Last Post: 08-10-2005, 07:29 PM
  5. Replies: 7
    Last Post: 03-10-2004, 04:10 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21