I'm not understanding how to dynamically add object instances in my games.
I'm really having trouble understanding the general concept. If I want to quickly generate unknown numbers of objects, going through and declaring them one by one does not seem to be plausible. This problem is exemplified by bullets. If the player can fire 100 bullets, how do I declare and define these objects in a simple manner. Obviously I need formulas to tell the bullets where to appear and where to go, but I can do that. How do I get to the point where I can begin to define those formulas?
Here is the code up to the point I have tried, the current problem being that B cannot be assigned because it is the essence of the foreach loop:
if (ms.LeftButton == ButtonState.Pressed)
{
shotFired = 0;
foreach (Bullet B in bulList)
{
if(B != null)
{
B = new Bullet(main.Location, enball, spriteBatch);
shotFired = 1;
}
}
//if all bullets are not "null," essentially delete one and replace it.
}