Hi, so I am making a game in which you throw a knife to kill enemies, and the code for that is here:
Basically, at the begining of the game, the knife appears and you must pick it up. Once you do, the above code executes. However, for the projectiles to work, the knife must be moving, so in the throwing knife class I have to do this:
However, once I do this the error, "cannot find symbol - variable hasKnife" appears. I thought I could call the actor with Actor mainplayer = new MainPlayer(), but that didn't work.
Is there a way to access boolean between classes? If so, how?
Thank you very much in advance!
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 | public boolean hasKnife = false ; public void pickUpKnife() { if (hasKnife = false ) { Actor tKnife; tKnife = getOneObjectAtOffset( 0 , 0 , ThrowingKnife. class ); if (tKnife != null ) { World world = getWorld(); getWorld().removeObject(tKnife); hasKnife = true ; } } } public void throwKnife() { if (hasKnife = true ) { if (Greenfoot.isKeyDown( "space" )) { getWorld().addObject( new ThrowingKnife(), getX(), getY()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 | public void act() { moving(); } public void moving() { if (hasKnife = true ) { move( 5 ); } } |