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

2020/2/25

Bullet doesn't fire. It just stays where it is and then causes and error.

1
2
3
danpost danpost

2020/2/27

#
footpickle wrote...
the bomb rapid fires... It is now WAY too overpowered. How do I add a reload like function?
Decision time: fire once per space press or repeat firing when space is held down?
danpost danpost

2020/2/27

#
footpickle wrote...
Is there a "do nothing" method? if so, that would be quite useful
Any method absent of code will "do nothing". Usually, however, you place conditions on what can be done and when a false resulting conditional expression is given, "nothing" will happen, anyway.
footpickle footpickle

2020/2/27

#
I would say fire once every space press? It could be held down if the boss had more health, though... It would be useful to know both, if possible, but I would go with... I actually don't know... if it is repeat, then pressing it repeatedly would still work, right? So it would be more useful to know the "hold down space" Either works though. Thanks for all your help so far!
footpickle footpickle

2020/2/27

#
my previous post was messily written, so this is basically what I said: Being able to hold down the space bar and have it fire every, let's say, 1 second, would be probably more useful than having to press, press, press, press, again and again. I just have no idea how to make a line of code have a delay to it.
footpickle footpickle

2020/2/27

#
I just realized where you are it is 10:00pm... I'm Aussie, so here it is 1:00pm. Sorry if this has been bothering you!
danpost danpost

2020/2/27

#
I guess it really depend on how quick you will allow the repeat. A long delay with one press per fire would require both ways together (early pressing would be unresponsive). So, actually 3 ways -- not two. Firing once per press requires that you keep track of the up/down state of the key. In general, any time you can check a state and you need to do something once when that state changes, keeping track of the state would be required (without the tracking field, you can only get the current state, which alone does not tell you when the state changes). Basically:
/** with tracking field */
private boolean trueState = false;

/** in code */
if (trueState != getState()) // if state changed
{
    trueState = ! trueState; // track change
    if (trueState) // is new state when something should be done
    {
        // do something
    }
}
Firing repeatedly (with a delay) requires an int timer field:
/** with field */
private int timer = 0;

/** in code */
if (timer > 0) timer--; // run timer down
if (timer == 0 && getState()) // if can do something
{
    // do something
}
Firing once per press with a delay will require both fields:
/** with fields */
private int timer = 0;
private boolean trueState = false;

/** in code */
if (timer > 0) timer--; // run timer down
if (trueState != getState()) // if state changed
{
    trueState = ! trueState; // track state
    if (timer == 0 && trueState) // if can do something
    {
        // do something
    }
}
footpickle footpickle

2020/2/27

#
But which actor would this code go in? I assume the Bomb class? I will try use this now. Thanks for this!
footpickle footpickle

2020/2/27

#
It says "cannot find method getState" Would the code go in the bomb class, or the class that actually has the code to fire the bomb?
footpickle footpickle

2020/2/27

#
it says "cannot find symbol - method getState()" What does this mean? I assume it means I haven't defined the method, but if that's the case, how do I define it?
danpost danpost

2020/2/27

#
footpickle wrote...
It says "cannot find method getState" Would the code go in the bomb class, or the class that actually has the code to fire the bomb?
The codes were given for general case purposes. I did not write them specific to your needs. Bomb class? No. The Knight object is what does the firing of bombs and the state to be gotten is if the "space" key is pressed. You do not need a getState method. Just replace the call with the condition required to shoot.
footpickle footpickle

2020/2/27

#
what is Knight?
footpickle footpickle

2020/2/27

#
IT WORKS PERFECT! Thank you so much!
danpost danpost

2020/2/27

#
footpickle wrote...
what is Knight?
Sorry, that's a different discussion. My bad. It goes with whatever object creates the bombs.
footpickle footpickle

2020/2/27

#
I have another issue. Should I start a new discussion, or keep using this one?
danpost danpost

2020/2/27

#
footpickle wrote...
I have another issue. Should I start a new discussion, or keep using this one?
If it not related to this issue, start a new one.
There are more replies on the next page.
1
2
3