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

2016/11/28

Locking controls and Asking questions.

MJBelmer MJBelmer

2016/11/28

#
In my DragonArena scenario I have two dragons that can shoot Fireballs at each other, each controlled by two different players. When a hit is landed the Dragons are reset to their starting positions and a point is awarded to the player who landed the hit. I would like to let the user tell the program how many points must be scored by a single player to win the game at the start of the program. Rather than have a bland input box show, I'ed like it to look better I could create an image for a box that would ask how many rounds but wouldn't be limited to just that maybe I could add other options to the game like dragon color choices or how many walls will be randomly placed. I would need to have the players controls locked though while this is being selected. Furthermore I would like when a hit is landed for the players to be reset but a short delay to lock the controls and display something like "Point Red" or "Point Blue" across the screen for a short moment to give the players time to collect themselves. Are these things outside the scope of what I should be trying to do here for a basic game?
danpost danpost

2016/11/28

#
You can use different worlds for PointMessage and for Controls. While a different world is active, no act cycles will be executed in DragonArena world.
MJBelmer MJBelmer

2016/11/28

#
Okay that would make sense and is kind of what I figured would be needed. I don't however know how to change active worlds and referencing values from different worlds to do PointMessage world as well as how do you make input fields for my Controls world. Is there a chapter I should reference?
danpost danpost

2016/11/28

#
In your alternate worlds, such as PointMessage, you can put add a reference field to hold the DragonArena world; then pass that world to it when created. The following class code shows at least how to receive the necessary information (who pointed and a reference to the game world), retain it and utilize it (as an example -- not to necessarily be used as shown):
import greenfoot.*;

public class PointMessage extends World
{
    private DragonWorld dragonWorld;

    public PointMessage(DragonWorld dw, int point)
    {
        dragonWorld = dw;
        if (point > 0) setBackground("bluePoint.jpg"); else setBackground("redPoint.jpg");
    }

    public void act()
    {
        Greenfoot.delay(40);
        Greenfoot.setWorld(dragonWorld);
    }
}
When a point is scored, you would use this line for the given class shown here:
// for point for blue
Greenfoot.setWorld(new PointMessage(getWorld(), 1);

// for point for red
Greenfoot.setWorld(new PointMessaage(getWorld(), -1);
MJBelmer MJBelmer

2016/11/28

#
Wonderful! Just this little bit of code explains so much to me, I really love learning this... Thank you!
You need to login to post a reply.