I am currently working on a Warfare 1917 like game. Right now I am trying to get the combat system working. I have made animations for a running and shooting soldier. It takes exactly 0.5 seconds till the animation lets the soldier shoot.
I have taken out the animations, hud etc. because I put much effort in them and I don't want someone to steal them just now. :) It currently looks like this:
Obviously they are killing each other too fast. How can I let them wait till the animation is at the point where they can calculate if they die or not?
This is my code. First it checks if two "soldiers" are in each others vicinity and then I calculate who of those two will die. german.stop(true); britain.stop(true);In the class where I handle the spawning and the animations of my soldiers I have a simple if else statement. Whenever stop = true then the soldier will stay at his current position and does his shooting animation. That this soldier continues to run after killing the other soldier is also a problem, but that's something for a later time.
ArrayList<britain> britainToRemove = new ArrayList<britain>();
ArrayList<germans> germansToRemove = new ArrayList<germans>();
for (int i = german_array.size() - 1; i >= 0; i--) {
germans german = german_array.get(i);
for (int j = britain_array.size() - 1; j >= 0; j--) {
britain britain = britain_array.get(j);
if (german.getBounds().overlaps(britain.getBounds())) {
//handle collision
german.stop(true);
britain.stop(true);
int german_hit = random.nextInt(100) + 0;
int britain_hit = random.nextInt(100) + 0;
message = "Red: " + german_hit + "Blue: " + britain_hit;
if (german_hit > britain_hit) {
britainToRemove.add(britain);
} else {
germansToRemove.add(german);
}
}
}
}
britain_array.removeAll(britainToRemove);
german_array.removeAll(germansToRemove);