SFML community forums

Help => General => Topic started by: Jim70 on May 28, 2015, 10:03:42 am

Title: Multiple objects from same class?
Post by: Jim70 on May 28, 2015, 10:03:42 am
I have a basic ai system, how do i do it so that i dont have to re-write the code for every ai i add with the same functionality?
Title: AW: Multiple objects from same class?
Post by: eXpl0it3r on May 28, 2015, 10:08:24 am
It's a very broad question (and not really related to SFML), can you be a bit more specifc?
Title: Re: Multiple objects from same class?
Post by: Jim70 on May 28, 2015, 10:11:21 am
so that i can have one class (with sf::texture, sprite, private & public variables etc) and reference it more than once and display the on screen.
Title: Re: Multiple objects from same class?
Post by: eXpl0it3r on May 28, 2015, 10:14:17 am
Use a container such as std::vector?
Title: Re: Multiple objects from same class?
Post by: Jim70 on May 28, 2015, 10:29:52 am
isnt there something like  LOL lol = new LOL ?
Title: Re: Multiple objects from same class?
Post by: eXpl0it3r on May 28, 2015, 10:32:10 am
I think you should get a good C++ book (https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and learn about classes and STL containers.
Title: Re: Multiple objects from same class?
Post by: MakaiKing0 on May 28, 2015, 06:22:25 pm
For once I agree with eXpl0it3r....

You should probably learn c++ before you try using it.  And your question is extremely broad, to the extent that it even extends to the programming model your using...  OOP, ECS, etc...  Your just going to have to figure out a model and run with it, then you can easily find a way to single out specific segments of your program such that it reduces or even erradicates redundancy....

GL
Title: Re: Multiple objects from same class?
Post by: DarkRoku12 on May 28, 2015, 06:33:34 pm
You can use virtual functions , or overloaded functions too, inclusive you can embed a script language such lua , python , ruby for the AI.. etc..

If the part of class/templates of c++ you don't know so well , buy a book (more recommendable) or google for tutorials.

http://www.cplusplus.com/files/tutorial.pdf
http://www.cprogramming.com/tutorial/c++-tutorial.html
http://www.cprogramming.com/tutorial/c++-tutorial.html