Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Creating batch objects

Author
Message
Kerl
User Banned
Posted: 3rd Jul 2012 03:42
I am currently working on a very simple Diablo like game. I've come across a situation where I don't know how to manage this amout of enemy characteristics at one time.
I want to create a batch of ogres, but instead of simply using a for loop to create the sprites, I need them to be their own object so that they can hold their own individual variables such as int ogreHealth and booleans.
Am I correct that I cannot create several of these guys with a for loop because the name cannot be an integer value?

For instance:
Class ogre ogre1: will work
But
Class ogre 1: will NOT work.

I may have up to 20 of these guys at a single time so I'd rather not have a ton of different variables so that each sprite has its own variable....
Does anyone know of a way to handle this situation?
prasoc
11
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 3rd Jul 2012 04:20 Edited at: 3rd Jul 2012 04:22
Have a class of Ogre objects with their own individual healths and booleans, and make a vector of these Ogre objects that you loop through with each draw loop to move, etc.

like:



In each game loop, go through each Ogre entity and do the relevant AI checks



There are many ways to loop through each Ogre entity inside the vector, the for loop is my personal preference, but using iterators will work


Kerl
User Banned
Posted: 3rd Jul 2012 06:59
Great this seems to be the missing piece to this puzzle.
I must do some research because I've yet to use vectors.
Thanks prasoc for the detailed response
prasoc
11
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 3rd Jul 2012 15:17
Yeah, vectors come under an umbrella called "STL containers" - there are loads of them that each perform certain tasks better than others; lists, vectors, deques, etc.


Kerl
User Banned
Posted: 4th Jul 2012 05:15
I'm having trouble getting the vectors set up. I keep getting LINK errors.
Where do I initialize and define the vector?
Do I need to include it in the Ogre.h file?
Does it need to be static like the rest of my variables?

Also, that Ogre(){} that you put within the class, is that the constructor?
Kerl
User Banned
Posted: 4th Jul 2012 05:34
Here is some code so you can check it out.



Error codes
prasoc
11
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 4th Jul 2012 14:54
Right click your project, go to Properties -> C/C++ -> Code Generation, and set Runtime Library to "Multi-Threaded" from "Multi-Threaded Debug".

Furthermore, go to Properties -> Linker -> Input, and set "Ignore Specific Library" to exactly "libcmtd, msvcrt, atls" without the quotes.

Pretty sure that will fix it


Kerl
User Banned
Posted: 5th Jul 2012 03:10
hmmm those were already my settings in the properties tab.
Rudolpho
14
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 10th Jul 2012 01:36
Ignoring the error message, are you sure you can declare an empty array like this
?
Also, why are you declaring it outside the class, that is only needed if it's static. If it is I'm pretty sure you must give it a size (ogres[n]) for it to compile properly, or alternatively if you want a dynamic array you will have to declare a pointer to an array like so:



"Why do programmers get Halloween and Christmas mixed up?"

Login to post a reply

Server time is: 2020-02-16 22:55:08
Your offset time is: 2020-02-16 22:55:08