Respawning enemies at the same location and replacing player with dead player.

Hi all,

I wish to spawn my enemies again and again when they die or hit the target.
Also when the player is hit all spears should stop and not spawn anymore, and the player should be taken out and replaced with the player dead sprite.
Thank you
-shadowMoses

// My spears array, initiated also.


	private Array<Spears> spears = new Array<Spears>();

// Drawn on the canvas, the location of the spears.


        spears.add(new Spears(550, 270, 32, 11));
	spears.add(new Spears(585, 282, 32, 11));
  	spears.add(new Spears(617, 294, 32, 11));

// update for the array, also delays the array for set time needed.


        for (int i = 0; i < spears.size; i++) {
		if (TimeUtils.nanoTime() - lastShot > shotFreq) {
 			spear1 = ths.get(i);
 			spear1.update(delta);
		 }
	 }

// Drawing/rendering on the screen.


         for (int i = 0; i < spears.size; i++) {
		 spear1 = spears.get(i);
		batcher.draw(AssetLoader.spearAnimation.getKeyFrame(runTime), spear1.getX(), spear1.getY(),  spear1.getWidth(), spear1.getHeight());
	}

// This is for the collision detection so the spear gets taken out when it hits the player.


        for (int i = 0; i < spears.size; i++) {
	        spear1 = spears.get(i);
 		if (spear1.collides(monkey)) {
		System.out.println("Spear Contact made");
		batcher.draw(AssetLoader.hitAnimation.getKeyFrame(runTime, true), monkey.getX(), monkey.getY());
		batcher.draw(AssetLoader.hitAnimation.getKeyFrame(runTime, true), monkey.getX() - 5, monkey.getY());
		batcher.draw(AssetLoader.hitAnimation.getKeyFrame(runTime, true), monkey.getX() + 5, monkey.getY());
		backgroundAnimation.stop();
		spears.removeIndex(i);
		i--;
		batcher.draw(AssetLoader.monkeyDead, 185, 273);
		break;
	        }
         }

If anymore code is needed then I will provide.

Ask more specific questions, it seems like you are asking us to write code for you.

You don’t need to provide more code, I will provide you something:

part 1/3 of a series
another part 1/3 of a series

ArrayList doc

When you are done with these feel free to ask anything you need.

@OpenGLShaders
I am not asking for anyone to write code for me.
I am asking if anyone knows or can help with the issue I am having.

If you cannot help me or wish not to then that is your prerogative.

I am asking who wish to help and I am grateful for their help.

Thank you
-shadowMoses

That’s good. It came off like that to me :wink:

If you wanted to spawn them again, could you just teleport the enemy back to his spawn location? Maybe I misunderstood the question.

To spawn enemies at the place they die, just add a new enemy to the place where the enemy died.

For the 2nd problem, just render the dead player image when player’s health is less than 0.

I hope this helps you.

problem partly solved as I got the spawning system to kind of work. I improved how to spawn better. Now need to figure out the respawning and the player dead part :stuck_out_tongue:

Maybe make a boolean and call it alive and in the render method, if alive == false change the sprite to the dead sprite?
I think you should watch some videos about grame programming because thats very basic.
search for Cherno in youtube he made great tutorials.