How to handle Enemy Creation?

Imagine a side-shooter game where enemies come,shoot and die or leave the screen. This is what i want to do.

My problem is my Enemy class and my basic Game logic is ready but to create a level I have to hard code everything like;

Enemy enemy1=new Enemy();
enemy.position=new Vector2(…
enemy.texture=Load …
enemy.speed=1;
enemy.logic(1);

Enemy enemy2=bla bla…

spawn.Enemy(enemy1);
if (enemy1.isDead OR enemy1.LeaveScreen){
spawn.Enemy(enemy2);
}

Below post is a solution. But i do not know how to implement this solution or if there is a better way?

http://www.solarus-games.org/2011/01/18/enemy-scripts…-finished/

So far, each type of enemy was implemented as a C++ class (hardcoded into the engine). Creating a new type of enemy required to write a new C++ class that inherit the Enemy class. Even if the API was easy to use, implementing new enemy types was a quite heavy task. And the editor’s source code also had to be updated to support the new type of enemy… So this is was annoying. The other reason to make scripted enemies is that it will allow you to make your own enemies for your own quest. What you want when creating new types of enemy is to specify them as data files (a Lua script and some sprites), not to change the C++ engine.

I am not entirely sure what you are trying to do here, but have you considered e.g. keeping a list of all the enemies?

You could create a list of enemies like so:

List enemies;
enemies = new List();

and add a new enemy once the previous enemy leaves the screen or dies:

enemies.Add(new Enemy());

Also, instead of coding the position, texture, speed and logic for the enemy each time, you should probably consider moving these to a constructor within the Enemy class. If different enemies are to have different textures, logic and speeds, simply implement subclasses of the enemy class, which will represent different types of enemies.

Keeping a list of enemies will also be useful if later on in the code you want to perform some operations on all the enemies in the game (like make all enemies disappear when a boss shows up, or something like that).

I’m very new to coding, but it seems to me like this a rather simple solution.

Consider using a file such as XML to store the properties of each enemy. Parse the file into a data structure when loading the level. As the player progresses through the level, you create new enemy instances from this data structure.

This is basic .NET coding, and there are many resources on the Internet to teach these techniques.