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

2018/6/12

how can i get my score from another actor

1
2
3
4
roonie01 roonie01

2018/6/21

#
basically my scoreboard form MyWorld is transferred to stage2 with the score from MyWorld
roonie01 roonie01

2018/6/21

#
would it help if I updated my code on the project I posted
danpost danpost

2018/6/21

#
roonie01 wrote...
why does it need to be static
Because it is cleaner and easier to deal with. Your stage2 constructor can simply be this:
 public stage2()
{    
    super(800, 600, 1); 
    addObject(MyWorld.getScoreboard(), 66, 550);
    addObject(new Survivor(),400,300);
}
roonie01 roonie01

2018/6/21

#
okay that worked but wont show up unless paused and the scenario only runs for one act cycle I reposted the newest version of the code
roonie01 roonie01

2018/6/21

#
I also got this exception Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Not on FX application thread; currentThread = AWT-EventQueue-0
danpost danpost

2018/6/22

#
roonie01 wrote...
okay that worked but wont show up unless paused and the scenario only runs for one act cycle I reposted the newest version of the code
I told you what to do to fix that also:
danpost wrote...
Your if statements need additional conditions. For example, line 6 should be:
if (getWorld() instanceof MyWorld && MyWorld.getScoreboard().getScore() >= 10100)
and something similar for line 19.
roonie01 roonie01

2018/6/22

#
thanks danpost it works now but I have one small problem my zombie actors animation is supposed to change when he heads left to the left images in my 2d array
danpost danpost

2018/6/22

#
roonie01 wrote...
I have one small problem my zombie actors animation is supposed to change when he heads left to the left images in my 2d array
The relevant code in your Zombie class act method follows:
actCount++;
// some unrelated code, then
if (actCount <= 0 || actCount >= 10)
{
    dn = 1;
    switchImage();
    actCount = 0;
}
else if (actCount >= 5)
{
    dn = 0;
    switchImage();
    actCount = 0; 
}
Now, see what happens to the value of actCount. First, it starts at zero and throughout is only ever reset to zero (it is never set to a negative value). After the first line increments its value, it must at that point be greater than zero. This makes the first condition in line 3 here pointless. It will never be equal to or less than zero at that point. The value is incremented by one each act step until the if condition on line 9 is satisfied, when the value is reset to zero. This makes the second condition on line 3 pointless. Its value will never be more than 5, so it will never make it to a value of 10. Now, because the first if block is never executed, the value of dn will never be set to 1. Look, you have 2 directions with 3 images each. I cannot know why you are checking for values of zero, 5 and 10 -- I can only know that you want to change its image on a regular basis of which I will assume to be every 5 act steps. Five act steps of three images means a cycle of images will take 15 act steps. Therefore, I suggest replacing the above code with the following and removing the switchImage method:
if (dn == 1 && getX() <= 2 || dn == 0 && getX() >= 797) dn = (dn+1)%2; // changing direction
actCount = (actCount+1)%(5*3); // repeating a 15-count
if (actCount%5 == 0) setImage(images[dn][actCount/5]); // animating actor
Your move command can now be the following:
move(speed*(1-dn*2));
without having to change the sign of speed.
You need to login to post a reply.
1
2
3
4