Advertisement

How to save the enemy formation in a STG game.

Started by February 06, 2015 01:45 PM
2 comments, last by cookiezby 9 years, 11 months ago

I am using Unity to develop my game, and I want to know how to save the formation of the enemy in a STG game, You know that in a STG game, there can be many kinds of formation of enemy. I decide to use enum to create the enum formationkind of the enemy and use the formationkind to decide the moving of the enemy, but first of all, I need to save each of the position of the enemy in the formation, can I use the Vector3[][] to save them?

For example Vector3[][] temp; temp[0][1] means the second enemy's position in the first kind of formation.

This can be accomplished by creating an Object array. Each object has an instance of an enemy, and the location it in in the world.

Example:


// Example of a class that can be saved and iterated from an array
// Written in Java

public class EnemyListExample{

Enemy e;
Group g;
int x;
int y;

     public EnemyListExample(Enemy enemy, Group, group, int X_Loc, int Y_Loc){
          e = enemy;
          g = group;
          x = X_Loc;
          y = Y_Loc
     }
     public Enemy getEnemy(){ return e; }
     public Group getGroup(){ return g; }
     public int getX_Loc(){ return x; }
     public int getY_Loc(){ return y; }
     
}

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

Advertisement

Code Fox has the right idea. If you only want to save the positions of the enemies, a list of vector3's will do. However, that could get a little bit nasty when you need to work on a per-enemy basis. Ideally, you want to create a list of gameobject's. On save, you can then add the enemy game objects to the list. This way, you will have the reference to the enemies, as well as the transform (position) for each.

EDIT: Just realized that you may or may not be using C# with Unity. In my above post I assume you are using C#. Regardless, the idea is the same for any of Unity's languages.

"The code you write when you learn a new language is shit.
You either already know that and you are wise, or you don’t realize it for many years and you are an idiot. Either way, your learning code is objectively shit." - L. Spiro

"This is called programming. The art of typing shit into an editor/IDE is not programming, it's basically data entry. The part that makes a programmer a programmer is their problem solving skills." - Serapth

"The 'friend' relationship in c++ is the tightest coupling you can give two objects. Friends can reach out and touch your privates." - frob

Is it good that I create all the enemies in one stage, and set the positions of them in the scene, when the player has arrived some place, I let the enemy in the view begin to move in a special formation? Is most of the STG game designed in this way? I think that the enemy in each stage is not random.

This topic is closed to new replies.

Advertisement