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

2015/5/9

Timer that goes up in seconds!!

1
2
danpost danpost

2015/5/10

#
How similar are the codes of your different levels? is it only the 'prepare' and 'act' methods (minus the timer code) that are different? What code do you have in your player class for calling the game over method in the world class?
danpost danpost

2015/5/10

#
Adam2323 wrote...
Okay... What code do I put into the "public void showSurvivalTime(int time)"?
Something like the following should suffice:
1
2
3
Actor actor = new SimpleActor();
actor.setImage(new GreenfootImage("You survived for "+time+" seconds\n\nPlay again?", 72, null, null));
addObject(actor, 300, 200);
Adam2323 Adam2323

2015/5/10

#
Here is the code for calling the game over world class.
1
2
3
4
5
6
7
8
9
10
public void hitDetection()
    {
        Actor enemy;
        enemy = getOneIntersectingObject(Enemy.class);
        if(enemy != null)
        {
            AvoiderWorldEasy world1 = (AvoiderWorldEasy)getWorld();
            world1.endGame1();
        }
    }  
The codes for my worlds are slightly different, in the sense that they have different enemies, but they all go to the same game over world when the player is hit by an asteroid.
Adam2323 Adam2323

2015/5/10

#
Thank you, it all works now. Thank you for your help :)
danpost danpost

2015/5/10

#
Adam2323 wrote...
Here is the code for calling the game over world class.
1
2
3
4
5
6
7
8
9
10
public void hitDetection()
    {
        Actor enemy;
        enemy = getOneIntersectingObject(Enemy.class);
        if(enemy != null)
        {
            AvoiderWorldEasy world1 = (AvoiderWorldEasy)getWorld();
            world1.endGame1();
        }
    }  
The codes for my worlds are slightly different, in the sense that they have different enemies, but they all go to the same game over world when the player is hit by an asteroid.
I do not see how line 7 would work here. That is, it will work from the easy level, but it will fail from the other levels, unless they each use a different player from a different class.
Adam2323 Adam2323

2015/5/10

#
I have a different player actor for each world. For easy, I have AvatarE, for medium, AvatarM, and for hard, Avatar. I also have 4 different enemy classes, each move at different speeds. (Enemy, Enemy2, Enemy3 and Enemy4 )
danpost danpost

2015/5/10

#
Adam2323 wrote...
I have a different player actor for each world. For easy, I have AvatarE, for medium, AvatarM, and for hard, Avatar. I also have 4 different enemy classes, each move at different speeds. (Enemy, Enemy2, Enemy3 and Enemy4 )
That will work.
You need to login to post a reply.
1
2