Hello, I ran into another problem I cannot solve for my Asteroid Game, making a working ForceField. Just some basic, when the key, "a," is pressed down, the ForceField is made and follows the Rocket. I can create the ForceField wtih this code:
I do have a checkKey method, which I wonder if I should put the "if(Greenfoot.isKeyDown("a")) there.
Anyways, the problem with this code is that if "a" is pressed, it creates ForceField; however, it does not follow the Rocket. I know for sure I have to use getX() and getY(), but I'm not sure where to put it. Another problem is then how long the Rocket can use the ForceField, which I think I would just need to create a counter, right?
Examples of the code will help me out. Thank you!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | private static final int ffReloadTime = 100 ; private int ffReloadDelayCount; public void act() { ffReloadDelayCount++; if (Greenfoot.isKeyDown( "a" )) { useForce(); } } private void useForce() { if (ffReloadDelayCount >= ffReloadTime) { ForceField ff = new ForceField(); getWorld().addObject(ff, getX(), getY()); ffReloadDelayCount = 0 ; } } |