开发者

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 ((


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜