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

2021/2/10

World Selector

BogdanMicu BogdanMicu

2021/2/10

#
I'm trying to save in a variable "world" the world my actor is in so I can use it later in commands such as
((world)getWorld()).a++;
This is my code:
public void worldSelector()
{
    if(getWorld() instanceof level1)world = level1;
    if(getWorld() instanceof level2)world = level2;
    if(getWorld() instanceof level3)world = level3;
    if(getWorld() instanceof level4)world = level4;
    if(getWorld() instanceof level5)world = level5;
}
It is obviously wrong, but I personally don't know how to make it work. Could you help?
BogdanMicu BogdanMicu

2021/2/10

#
Also, can you recommend a pixel-like font supported by Greenfoot to use for the HUD? I tried using Stencil but it just displays the default font. Calibri and Consolas work though.
danpost danpost

2021/2/10

#
Maybe it might be best to have an intermediate class between World and your current level classes:
public class level extends greenfoot.World
{
    int a;
    
    public level(int w, int h, int c)
    {
        super(w, h, c);
    }
}
with your current levels as:
public class level# extends level
Then you can use:
((level)getWorld()).a++;
regardless of specific level number. In fact, any code common to all levels can be placed in this intermediate class (instead of in all the level# classes.
BogdanMicu BogdanMicu

2021/2/13

#
How can I use the act for the level# as well as the superior class level? When I create an act function for the actual levels the act() from level is ignored.
danpost danpost

2021/2/13

#
BogdanMicu wrote...
How can I use the act for the level# as well as the superior class level? When I create an act function for the actual levels the act() from level is ignored.
Use:
super.act();
in level# act.
You need to login to post a reply.