This site requires JavaScript, please enable it in your browser!
Greenfoot back
GamesGrinder1998
GamesGrinder1998 wrote ...

2014/4/4

Enemies code

1
2
Mutton Mutton

2014/4/5

#
public void act() { getWorld().addObject(new DarkPower(90), getX(), getY()); shoot(); } get rid of the bold bit, because that is what the shoot method does, as the same line of code is already there. And feel free to bug me, I had to do the same thing in my CompSci class, so I know how it can be.
GamesGrinder1998 GamesGrinder1998

2014/4/5

#
thanks...i it delaying though but they are all still shooting at the same time, do you know how to fix that problem
GamesGrinder1998 GamesGrinder1998

2014/4/5

#
Mutton wrote...
public void act() { getWorld().addObject(new DarkPower(90), getX(), getY()); shoot(); } get rid of the bold bit, because that is what the shoot method does, as the same line of code is already there. And feel free to bug me, I had to do the same thing in my CompSci class, so I know how it can be.
thanks...it is delaying but they are all still shooting at the same time, do you know how to fix that problem, i only want a limited amount of enemies shoot at the same time (3-4)
Mutton Mutton

2014/4/5

#
public int shotDelay = 0; public int deSync = Greenfoot.getRandomNumber(50); /** * Act - do whatever the BugEnemy wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { shoot(); } public void shoot() { if(shotDelay >= 25 && shotDelay > deSync) { getWorld().addObject(new DarkPower(90), getX(), getY()); shotDelay = 5; } shotDelay++; } try that out, the deSync int will have every enemy start shooting at different times, by having the first delay be longer than the rest by a random amount.
GamesGrinder1998 GamesGrinder1998

2014/4/5

#
what is the 50 in the deSync mean
GamesGrinder1998 GamesGrinder1998

2014/4/5

#
Mutton wrote...
public int shotDelay = 0; public int deSync = Greenfoot.getRandomNumber(50); /** * Act - do whatever the BugEnemy wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { shoot(); } public void shoot() { if(shotDelay >= 25 && shotDelay > deSync) { getWorld().addObject(new DarkPower(90), getX(), getY()); shotDelay = 5; } shotDelay++; } try that out, the deSync int will have every enemy start shooting at different times, by having the first delay be longer than the rest by a random amount.
what is the 50 in the deSync mean and it does work but it just showering with bullets....is it possible just for only 3-4 enemies shoot at a time before the next start shooting
Mutton Mutton

2014/4/5

#
It's the range between 0 and the maximum the random number generator will hit. So deSync will be a number between 0-49, different for every enemy
GamesGrinder1998 GamesGrinder1998

2014/4/5

#
How do you get the enemies to have a longer delay than others, will you just change the number in the shot delay to a higher value
GamesGrinder1998 GamesGrinder1998

2014/4/5

#
Mutton wrote...
It's the range between 0 and the maximum the random number generator will hit. So deSync will be a number between 0-49, different for every enemy
How do you get the enemies to have a longer delay than others, will you just change the number in the shot delay to a higher value
Mutton Mutton

2014/4/5

#
public void shoot() { if(shotDelay >= 25 + deSync) { getWorld().addObject(new DarkPower(90), getX(), getY()); shotDelay = 5; } shotDelay++; } that should do the trick. If you just changed the number in shotDelay, then it would change it for all the enemies. You need some random element there, in this case the int deSync
GamesGrinder1998 GamesGrinder1998

2014/4/5

#
Mutton wrote...
public void shoot() { if(shotDelay >= 25 + deSync) { getWorld().addObject(new DarkPower(90), getX(), getY()); shotDelay = 5; } shotDelay++; } that should do the trick. If you just changed the number in shotDelay, then it would change it for all the enemies. You need some random element there, in this case the int deSync
It worked better, but because my game is like galaga or space invaders, i have 31 enemies and it's showering with bullets still, do you have any sort of advice to fix this, should i limit the amount of enemies then just have the enemies spawn when is shoot one, i'm sort of stuck in this situation???
Mutton Mutton

2014/4/5

#
Increase the 25 and deSync values until you get to a point you think is comfortable. That will slow down the rate at which they fire, and make it a managable situation.
GamesGrinder1998 GamesGrinder1998

2014/4/5

#
Mutton wrote...
Increase the 25 and deSync values until you get to a point you think is comfortable. That will slow down the rate at which they fire, and make it a managable situation.
1. when the enemy and my player's bullets collide, i want it to disappear, what's the code
GamesGrinder1998 GamesGrinder1998

2014/4/5

#
GamesGrinder1998 wrote...
Mutton wrote...
Increase the 25 and deSync values until you get to a point you think is comfortable. That will slow down the rate at which they fire, and make it a managable situation.
1. when the enemy and my player's bullets collide, i want it to disappear, what's the code
how do you make the enemies go down a bit together whilst in formation like the game space invaders
You need to login to post a reply.
1
2