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

2013/4/22

Some uncomprehensible problems..

Solringolt Solringolt

2013/4/22

#
Hello everybody! I have 2 little problems that I can't solve.. I made a buton for sound but I can only activate the sound it doesn't respond to any further click. THe second problem is in class actions the randomMove function seems to not work like you can see in the game but I don't understand why. Here is the link for the game. If you find any other problem in the code tell me! ^^ http://www.greenfoot.org/scenarios/7845
danpost danpost

2013/4/22

#
You need to check the 'Include source code' checkbox during the 'Share'ing process for anyone to look at the code.
Solringolt Solringolt

2013/4/22

#
Ok fixed now you should be able to see it, if you need any explanation tell me
Solringolt Solringolt

2013/4/22

#
Even if I am searching for a solution XD
danpost danpost

2013/4/22

#
Well, I did find the problem with the sound. In the Bouton class, needed to change the last 'if' statement in the act method to an 'else'. Well, I thought that would fix the sound problem. Must be something else, as well.
danpost danpost

2013/4/22

#
Alright, I got rid of the 'soundPlaying' field and changed the last 'if' block in the act method of the 'Bouton' class to:
if(ThatWorld .equals("Option") && Greenfoot.mouseClicked(this))
{
    if (!WorldOption.MainSound.isPlaying())
    {
        WorldOption.MainSound.playLoop();
        setImage("son.png");
    }
    else
    {
        WorldOption.MainSound.pause();
        setImage("son2.png");
    }
}
That fixed the sound problem.
danpost danpost

2013/4/22

#
Your enemies are moving left and up because of the 'Greenfoot.getRandomNumber(8)-4' part of your offsets in movement. The random range is 0 to 7; subtracting 4 the range is -4 to 3. This gives more chance of moving up and left than not. Also, you should randomize the shot timer for the enemies (instead of having all of them shoot at the same time).
Solringolt Solringolt

2013/4/23

#
Ho nice a was looking for my problem too far! For the movement of the enemies the random effect is now ok but i still don't understand why they change between two position like that.. Each act they teleport to a "symetric" location...
danpost danpost

2013/4/23

#
Maybe you should use an instance field to track the 'rotation' of the enemies. Then:
rotation += Greenfoot.getRandomNumber(9)+356; // random change in rotation
setRotation(rotation); 
move(3); // more in direction of rotation
setRotation(0);
shoot(); // shoot toward left
NOTE: the above is just a guide to what you could do and not actually the code you should put in your scenario (I was not looking at your Enemy class to create this code).
Solringolt Solringolt

2013/4/23

#
Then I can't use my method? Because with this one my object will rotate, I wan't them to have the same direction.
danpost danpost

2013/4/23

#
Sure, you can! If you notice, I reset the rotation back to zero after the move. The rotation will never be visibly displayed.
Solringolt Solringolt

2013/4/23

#
Ok thx I finally got something playable! ^^
You need to login to post a reply.