I'm adding to my Asteroid game to make them move faster the more you destroy.
Okay, once again I am at a stage where I think I need to use a public variable but am having no luck. Right now what I'm using to keep track of my score is I have a persistent actor with the following methods in it:
However, based on the results from running the program, this doesn't seem to be working. Within the asteroid class:
The getDestroyedCount() seems to be having no effect, the speed is just staying at 1. Is this because castle is new Castle()? If it's new, doesn't that mean the value would be 0? How can I reference the castle that already exists. If I'm over-complicating this, please inform me of a more straightforward way to do public variables.
public void addDestroyed() { destroyedCount = (destroyedCount + 1); } public double getDestroyedCount() { return destroyedCount; }
Castle castle = new Castle(); private int moveSpeed = (int)(Math.sqrt(castle.getDestroyedCount())); public void act() { if(moveSpeed == 0) { moveSpeed = 1; } move(moveSpeed);