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

2017/2/19

While problem

joshuadswa joshuadswa

2017/2/19

#
Hello again :) I have another problem here, so here what i want: - i want after the projectile hit the target , tower will stop shooting the projectile, but in my case, the tower keep shooting the projectile, but after that it dissapear since it dont have any target. -so i try with while, but its say incompatible type .-. thx before ^^ (Tower class) public void shootProjectile() { int miniion = getWorld().getObjects(Minion1.class); while(miniion > 0){ if (shotDelay > 0 && --shotDelay != 0) return; getWorld().addObject(new Projectile1(), getX(), getY()); shotDelay = 100; } }
Super_Hippo Super_Hippo

2017/2/19

#
The 'getObjects' method returns a list. What you may want to have is the number of objects of that type. You have to call the 'size' method on this list to get it. Change the 'while' back to 'if' or you will have an infinite loop. You will also find that you need to set a rotation to the projectile so it is moving to the target (depending on which target you want to shoot - nearest, first, last...).
Nosson1459 Nosson1459

2017/2/20

#
just a tip about the greenfoot website, if you look under the text box where you write your replies and q's, there are a few blue words, try them out. For example the word "code" if you press on it a box pops up on the screen, and if you type your code into there, on your post it'll highlight keywords and make it more obvious to read as code.
joshuadswa joshuadswa

2017/2/20

#
Ok :D thank you very much ^^
You need to login to post a reply.