Ercan
Ercan

Reputation: 2773

Design: an array of "enemy" objects for game AI

I made shoot em up like game.But I have only one ememy which fallows me on screen.But I want to make lots of enemys like each 10 second they will across on screen together 5 or 10 enemys.

 ArrayList<Enemies> enemy = new ArrayList<Enemies>();

 for (Enemies e : enemy) {

        e.draw(g);
    }

is it good creating array list and then showing on screen? And Do I have to make some planing movements thoose enemies in my code ? I want that they vill appear not on same pozition.Like First 5 enemies will come top of screen then the other 5 or 10 enemies will come from left side.. so on.What is best solution for this?

And I have problem where to fullfiel this array like

enemy.add(new Enemies(750,60)) 

But this doesnt work ((

Upvotes: 0

Views: 1027

Answers (3)

user297205
user297205

Reputation: 196

Use for example a random property and onScreen property. And set them when you show them on the screen.

Upvotes: 1

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103135

You can randomize the starting position ofthe enemies using the Random class. At the point where you create the enemy select Random coordinates for each.

You may want to have each enemy run in its own thread so that they move independent of each other too.

Upvotes: 0

lbedogni
lbedogni

Reputation: 7997

Yes you can create an ArrayList for enemies, it's a common solution.

Upvotes: 0

Related Questions