Enemy Bullets

Started by
29 comments, last by BeerNutts 9 years, 2 months ago

Okay well before I said that when I included a timer all my enemies would not shoot. Now I got them to shoot on a timer but only one shoots at a time. So one enemy comes out and it shoots, when that enemy gets destroyed the next one in the vector shoots.

Well, we don't have any code to help, but I bet you can work it out.

Where is your timer variable stored? It should be an EnemyShip class member variable since each ship should have it's own refire timer. You don't have it as a global variable do you?

Go though your code, ask yourself what happens. Try debugging and see why this is happening. Good luck.

The code is pretty much what I posted earlier in the thread. If you look at one of the functions theres a part of it thats commented out. That one has a timer and when I use that ships fire one at a time like i explained.

I'm going to really go through the code like you said though. Its just that it seems like its something that should be done so easily.

No, that's only the function that acts on the "timer" My question was, where is the timer variable stored? Is it a global? That's the code I want to see.

It should be a member variable for in each instance of class you have.

The Timer variables are just stored in the EnemyShip class. I initialize it as currentTime = SDL_GetTicks() and lastTime is initialized to zero.


void Enemy1Bullet::EnemyBulletHandler(int posX, int posY)
{ 
	currentTime = SDL_GetTicks();
	if(currentTime > lastTime + 1000)
	{
		Enemy1Bullet* bullet = new Enemy1Bullet(); 
		bullet->box.x = posX + 50;
		bullet->box.y = posY + 35; 
		enemyBullets.push_back(bullet);
		lastTime = currentTime; 
	}
}

You already showed me that code, it looks fine, so the problem is somewhere else in your code, that's why I asked to see the rest of it.

Well, GL to you anyway.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement