Jump to content

  • Log In with Google      Sign In   
  • Create Account


TheResolute

Member Since 08 Feb 2012
Offline Last Active Mar 08 2013 12:24 PM
-----

#4979939 Why is it faster to develop in certain languages over others?

Posted by TheResolute on 13 September 2012 - 10:34 PM

Thank you for these clarifications so far, and I would like to note that I asked this exact question on Stack Overflow and watched it be mocked and closed within minutes. Kudos to the GameDev.net community!


#4974913 Enemy shooting

Posted by TheResolute on 30 August 2012 - 02:49 PM

Won't work.

So you have 30 enemies. Let us say I have killed the 2nd, 4th, 6th one. So 27 enemies left.

the rand() seeder will only give me a number from 0-27.
Meaning, if I get the number 0, 4, 6 those enemies will try to shoot but they are dead..
Also means the last 3 enemies will never be able to shoot a bullet.

You must have misread the code or I made a mistake, but it is not accessing the array using the random number as an index, it is iterating through the array and every time an enemy is alive, it decrements its counter and if the counter is zero, meaning that this enemy is the nth living one, it will then have it shoot


#4974905 Enemy shooting

Posted by TheResolute on 30 August 2012 - 02:18 PM

EngineProgrammer provided a nice solution

Something far more simple would be to:
keep track of how many enemies are alive (variable initialized with number of enemies and decremented each time one dies);
using the same process he described to do this at certain intervals: generate a random number using the number of living enemies as your cap, and iterate through your enemies array, skipping dead ones, while decrementing the random number, and have the enemy shoot when your random number is 0
Hope that makes sense Posted Image

Some pseudo code could help:
int totalEnemies = 30;
int livingEnemies = totalEnemies;
Enemy[30] enemies;

// in code region dealing with enemy death
livingEnemies--;
//

// on iterval for enemy to shoot
if(livingEnemies > 0)
{
	 int randNum = Math.Rand(0, livingEnemies);  // generates a random integer between bounds, lower exclusive, upper inclusive
	 for(int i = 0; i < totalEnemies; i++)
	 {
		  if(enemies[i].isAlive)
		  {
			   randNum--;
			   if(randNum == 0)
			   {
					// Enemy shoots
			   }
		  }
	 }
}
//



PARTNERS