Skip to main content
GameDev.net gamedev.net
🔒 Locked

Enemies in Java

Started by Duekiller Nov 16, 2003 at 7:37 PM 5 replies 600+ views
Original Post
Duekiller
Duekiller
Hi im building a game as an after school project and i would like to know how to make enemies apear without end. i have a class that handles how ONE soldier moves and acts, but i wanna do is have 10 enemies on the screen at once. Whenever a soldier gets killed another one is created. I have no clue how to do that. ps: the method that handles the soldiers movment ArmyofOne.drawSoldier(); [edited by - Duekiller on November 16, 2003 8:38:24 PM]
Duekiller
Duekiller
thank you for the constructive advice, it always helps ! |:-<
nonnus29
nonnus29
Use an array;


Soldier [] soldiers = new Soldier[10];

for (int i=0; i < soldiers.length; i++)
soldiers[i] = new Soldier();

// then to spawn a new one do something like


for (int i=0; i < soldiers.length; i++)
if (soldiers[i].dead) soldiers[i].reset();



[edited by - nonnus29 on November 16, 2003 10:11:06 PM]
Duekiller
Duekiller
thanks man that helps, i didnt know you could do that, that helps alot!
Hungry Joe
Hungry Joe
quote:
Original post by AndreTheGiant
Java doesn''t need anymore enemies


9/10
0110011001110101011000110110101100100000011011110110011001100110

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.