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

2017/4/25

Help with my Shark game please?

Optimistic_Celery Optimistic_Celery

2017/4/25

#
(URGENT!!!) Hi! So I am making what is basically supposed to be a super basic hungry shark game (I call it Shark Attack... hehe). It's for my programming class and it's due tomorrow, but I'm having a tad bit of trouble spawning the fishes and rocket (yes, a rocket, i couldn't be bothered to find and resize a bird image because I'm lazy) in a timely manner. What I basically did is create a counter, and every time the shark moves 1, the counter has one added to it, and once the counter reaches certain numbers, certain actors are released. The program has no syntax errors, and it should theoretically work, but none of the actors will spawn except the shark, which spawns right at the beginning anyway. Here is the code for the counter: public void addToCounter() { int move = 0; int counter = 0; if(move == move + 1) { counter = counter + 1; } } And this is what I have for the spawn program for the other actors: if(counter == 15) { spawn_theFish1(); } if(counter == 20) { spawn_theFish2(); } if(counter == 50) { spawn_theRocket(); } Any help/advice you guys could give me before tomorrow would really, really help! It's probably something obvious, I'm no good at programming haha.
ET78759 ET78759

2017/4/26

#
Where are you increasing the move variable? And you can also add code by clicking on the button "code" on the bottom left corner of the text box.
Optimistic_Celery Optimistic_Celery

2017/4/26

#
Sorry, should have mentioned this, the public void addToCounter() program is in my Shark class, which moves whenever I press the arrow keys. The rest of the spawn program is in my "MyWorld." And thank you, that's helpful to know.
danpost danpost

2017/4/26

#
The thing that catches my eye is that in the 'addToCounter' method, you set 'move' to zero, set 'counter' to zero, then ask if zero equals one, which is never true. So, the value of 'counter' is never incremented (at least not by that method).
Optimistic_Celery Optimistic_Celery

2017/4/26

#
Thank you Danpost, that's a good point, I'll change that now and see what happens.
Optimistic_Celery Optimistic_Celery

2017/4/26

#
 if(counter == 15)
        {
            spawn_theFish1();
            counter = 0;
        }
        else
        {
          counter++;  
        }
I ended up deleting the addToCounter() method and did this instead. There's no syntax error, but again, they aren't spawning.
danpost danpost

2017/4/26

#
Optimistic_Celery wrote...
again, they aren't spawning.
Not even the one spawned by 'spawn_theFish1'? What method is that code in and what class? If not the act method, is the method being called from the act method?
Optimistic_Celery Optimistic_Celery

2017/4/26

#
Nope, theFish1 wont spawn either, and the other spawn programs are identical. That spawn_theFish1, along with the others, are all in public MyWorld.
danpost danpost

2017/4/26

#
Optimistic_Celery wrote...
Nope, theFish1 wont spawn either, and the other spawn programs are identical. That spawn_theFish1, along with the others, are all in public MyWorld.
You did not answer my other question:
danpost wrote...
What method is that code in and what class? If not the act method, is the method being called from the act method?
The 'class' part was answered; but, not the 'method' part. Please post your entire MyWorld class code.
You need to login to post a reply.