Advertisement

Dynamic Object Creation

Started by May 10, 2001 07:11 PM
0 comments, last by JSCFaith 23 years, 9 months ago
Hey, Me and my friend are working on a asteroids clone, its going rather good by the way, and we want to make it so that when you kill an asteroid. Littler asteroids will come out. Right now I have a class called GameObject, and Asteroid is a subclass. My questions is this, how would I dynamically add more asteroids when a big one is destroyed. My class has a linked list and as you know that is dynamic. Its just that I don''t want to have to create an Array of like 20 and limit the number of small asteroids to 20. Thanks... P.S. This might be a stupid question. I don''t know, but I am sure known for stupid questions.
Well if you can make linked lists this will be cake.

Make a class for each item and have GameObject *object; for each list item and do list./->object = new GameObject; after you add the new class...or even better use std::list

example:

#include #include class test{public:	test(int x) : x(x) {}	int x;};int main(int argc, char* argv[]){	std::list testlist;	testlist.push_back(10); // Add new item to end	std::cout << testlist.back().x << std::endl; // Get end item and print out member x	return 0;} 

This topic is closed to new replies.

Advertisement