Jump to content
  • Advertisement

HughJanus

Member
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

102 Neutral

About HughJanus

  • Rank
    Newbie
  1. I've already declared   eneGen = new int[3];   I already tried that and yeah it still works. Actually, the game already runs. My problem is just that it spawns only one enemy. I declared an array of 3 enemies specificically because I want to spawn up to 3 of them at a rate of one enemy per second. if (eneCount < 3)//Enemy Activation: creates an enemy if there are less than 3 enemies { for (int a = 0; a <= 2; a++) { eneGen[a] = 1; if (a > 2) // What it this? Won't ever happen if a <= 2 as above { a = 0; } // eneCount++; } } That particular code means that I permanently set eneGen[a] to be 1. In the below code: private void eneMove_Tick(object sender, EventArgs e) { for (int a = 0; a < 2; a++) { if (eneGen[a] == 1)//creates BLUE ENEMY // does this create enemies? if so it creates only one { eneInA++; EnAIaY[a] += 6; eneCount++; if (a >= 2) // And again... { a = 0; } // if (eneInA > 2) { eneInA = 0; } } } pbArea.Refresh(); } It says that if eneGen[a] ==1 (which I have already set to always have a value of 1), it will start the process of generating and making the enemy move downwards.     What I don't understand is that if I have a for loop to determine the existence of an enemy per eneGen[a] (which is up to 3), why is there only one enemy spawning? There should be 3 enemies spawning since I specifically randomized their spawn points.
  2. That is to restart the loop. Once the for loop reaches that condition, it will start again from zero. Am I doing it wrong? The timer automatically starts as soon as the game starts so I have to keep the loop running indefinitely for it to generate an enemy every 2 seconds.   The code   "if(eneGen[a] == 1)"   along with   "eneGen[a] = 1;"     was supposed to generate enemies randomly based on a random number. For debugging purposes, I have set it to one, which is the required number for the enemy to actually spawn. Once I can spawn multiple enemies, I'll make it random again.
  3. I need help generating multiple versions of the same enemy. Here's all the necessary code I used to try and do just that, but it only ever generates one enemy on screen. The below code already has a Timer (enemyGen having an Interval = 2000, and eneMove having an Interval = 40) I'll put my thoughts on each line of code I think has a problem: public FormDesign() { eneGen = new int[3]; EnAIaX = new int[3]; EnAIaY = new int[3]; for (int a = 0; a < 3; a++) //Will the random numbers all be different per array object? { EnAIaX[a] = new Random().Next(20, 500); EnAIaY[a] = new Random().Next(0, 0); } } private void enemyGen_Tick(object sender, EventArgs e) { if (eneCount < 3)//Enemy Activation: creates an enemy if there are less than 3 enemies { for (int a = 0; a <= 2; a++) { eneGen[a] = 1; if (a > 2) { a = 0; } eneCount++; } } for (int a = 0; a < 2; a++) { if (EnAIaY [a] > 600) { EnAIaX[a] = new Random().Next(20, 500);//Will the random number generated be different per array object? EnAIaY[a] = new Random().Next(0, 0); eneCount--; } if (a > 1) { a = 0; } } } private void eneMove_Tick(object sender, EventArgs e) { for (int a = 0; a < 2; a++) { if (eneGen[a] == 1)//creates BLUE ENEMY { eneInA++; EnAIaY[a] += 6; eneCount++; if (a >= 2) { a = 0; } if (eneInA > 2) { eneInA = 0; } } } pbArea.Refresh(); } The singular enemy that comes out really does generate in random locations along the X-axis, but my end goal is to generate at least 3 of them at the same time. Please help a beginner out. :(    
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!