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

2022/1/2

how add text from different world?

mariq_rasyid29 mariq_rasyid29

2022/1/2

#
mmmm i want add this text
public String dialog2[] =
    {"Pup 1 & Pup 2 : ''Hello, Alpha. ^^''",
            "Blizzard : ''Hi, Kiddo. :)",
            "Pup 1 : ''Alpha, Where are you going?",
            "Blizzard : ''I'm go to Ancient Dugeons :)",
            "Pup 2 : ''Woah, Are you sure Alpha? \n That place is very Dangerous,\n My Parent said only Alpha can to there.",
            "Blizzard : ''Im sure about that :)",
            "Pup 1 & Pup 2: ''Ok Then Alpha, Good luck.''",
            "Blizzard : ''Thank you, Kindos. See ya ;)''",
            "Pup 1 & Pup 2 : ''Your Welcome, Alpha, see yaa!!!''"
    };
but blizzard.class position from ParentsHouse world to BridgeStoneForest world I also want to add pup1.class & pup2.class, if blizzard.class in BridgeStoneForest World and if blizzard.class is 8 pixels away from pup1.class & pup2.class text appears in the world BridgeStone Forest. after the text is finished pup1.class & pup2.class disappear from the world I use mat2.class to trigger the switch to the world from ParentsHouse world to BridgeStoneForest world here the code of mat2.class :
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Mat2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Mat2 extends Mats
{
    /**
     * Act - do whatever the Mat2 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        Touching();
    }
    public void Touching()
    {if (isTouching(Blizzard.class)) 
        { if (getWorld() instanceof ParentsHome) 
            { 
                World bsf = new BridgeStoneForest();
                getWorld().repaint();
                bsf.removeObjects(bsf.getObjects(Dialogue.class));
                bsf.removeObjects(bsf.getObjects(Blizzard.class));
                bsf.addObject(new Blizzard(), 723,111);
                ((ParentsHome)getWorld()).Back.stop();
                Greenfoot.setWorld(bsf);  
            }
        }
        
    }

    
}

mariq_rasyid29 mariq_rasyid29

2022/1/2

#
If you want to know the code of the ParentsHouse world, here it is :
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class Home2 here.
 * 
 * Muhamad Ariq Rasyid
 * 1.0 /21 Feb 2021
 */
public class ParentsHome extends World
{
    public GreenfootSound Back= new GreenfootSound("Alpha and Omega Soundtrack 2 Pre Teen Woves.mp3");
    public String[] dialog2 =
        { "Blizzard : ''Hi, Mom and Dad.''",
            "Mom : ''Ohh Hello, Son''",
            "Dad : ''Hi, son''",
            "Blizzard : '' Mom, Dad. I hope i can defeated \n All monsters in the Ancient Dugeons.''",
            "Mom & Dad : ''Good luck Son''",
            "Blizzard : ''I'll try my best, See ya.''",
            "Mom : ''See ya, Son",
            "Dad : ''Bye, Son.''"

        };
    private int[][] wallstopLoc=
        { {53,19},{106,19},{159,19},{212,19},{265,19}, 
            {318,19},{371,19},{424,19}, {477,19}, {530, 19},
            {583,19}  
        };
    private int[][] wallssideLoc=
        {{11,388} , {11,363}, {11,338}, {11,313}, {11,288}, {11,263},
            {11,238}, {11,213}, {11,188 }, 
            {11,163},{11,138},
            {  11, 113 },  {  11, 88 }, {  11, 63 },
            {  11, 38 },  {  11,  13 }, { 587, 387 },
            { 587, 362 }, { 587, 337 }, { 587, 312 },
            { 587, 287 }, { 587, 262 }, { 587, 237 },
            { 587, 212 }, { 587, 187 }, { 587, 162 }, 
            { 587, 137 }, { 587, 112 }, { 587,  87 },
            { 587,  62 }, { 587,  37 }, { 587,  12 },
            { 563, 387 }, { 538, 387 }, { 513, 387 },
            { 488, 387 }, { 463, 387 }, { 438, 387 },
            { 413, 387 }, { 388, 387 }, { 363, 387 },
            { 338, 387 }, { 313, 387 }, { 288, 387 },
            { 263, 387 }, { 238, 387 }, { 238, 387 },
            { 213, 387 }, { 188, 387 }, { 163, 387 },
            { 138, 387 }, { 113, 387 }, {  88, 387 },
        };

    private int[][] boxsLoc=
        { { 555, 57 }, { 529, 70 }, { 537, 37 }  

        };

    /**
     * Constructor for objects of class Home2.
     * 
     */
    public ParentsHome()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        //Background
        setBackground("bathroom-tile.jpg"); 
        //Music
        Back.playLoop();
        //Mom
        Mom mom = new Mom();
        addObject(mom,226,150);
        //Dad
        Dad dad = new Dad();
        addObject(dad,363,222);
        //Blizzard
        addObject(new Blizzard(),177,249);

        //Walls
        addtopWalls();
        addsideWalls();

        //Funiture
        //mat
        Mat2 mat2 = new Mat2();
        addObject(mat2,53,378);

        //heaters
        Heater heater = new Heater();
        addObject(heater,72,44);

        //Windows
        Windows windows = new Windows();
        addObject(windows,400,21);

        //Curtain
        Curtains curtains = new Curtains();
        addObject(curtains,399,36);

        //Clock
        Clock clock = new Clock();
        addObject(clock,304,65);

        //RoundTable
        RoundTable roundTable = new RoundTable();
        addObject(roundTable,260,226);

        //box
        addboxs();

        //info
        addObject(new TempText("Parents Home's", 120), 93, 16);

        //dialogue
        addObject(new Dialogue(dialog2), 310,370);
    }

    public void act()
    {if (!getObjects(Dialogue.class).isEmpty() && "z".equals(Greenfoot.getKey()))
        {
            ((Dialogue)getObjects(Dialogue.class).get(0)).next();
        }
    }

    public void addboxs()
    {for(int i=0; i<boxsLoc.length;i++)
        {WoodenBox wb=new WoodenBox();
            addObject(wb, boxsLoc[i][0], boxsLoc[i][1]);
        }
    }

    public void addsideWalls()
    {for(int i=0; i<wallssideLoc.length;i++)
        {HomeWallsSides hws = new HomeWallsSides();
            addObject(hws, wallssideLoc[i][0], wallssideLoc[i][1]);
        }
    }

    public void addtopWalls()
    {for(int i=0; i<wallstopLoc.length;i++)
        {HomeWallsTop hwt = new HomeWallsTop();
            addObject(hwt, wallstopLoc[i][0], wallstopLoc[i][1]);
        }
    }

}
mariq_rasyid29 mariq_rasyid29

2022/1/2

#
also If you want to know the code of the BridgeStoneForest world, here it is:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class  BridgeStoneForest here.
 * 
 * @author (Muhamad Ariq Rasyid) 
 * @version (1.0 19 Feb 2021)
 */

public class BridgeStoneForest extends World
{   Dialogue dg;
    Stones st;
    Pup1 pp1;
    Pup2 pp2;
    Tree t1;
    Tree2 t2;
    public GreenfootSound Back= new GreenfootSound("The Wolf Online Simulator Soundtrack Easter Event Castelvenia Netflix.mp3");
    public String[] dialog1 =
        {
            "Hello, My Name is Blizzard Wolf Smiths, The Timber Wolf",
            "Welcome in Western Pack Territory.",
            "In the Night many Monster in Ancient Dugeons.",
            "But before that Please to My parents home",
            "to North East from here"
        };

    public String dialog2[] =
    {"Pup 1 & Pup 2 : ''Hello, Alpha. ^^''",
            "Blizzard : ''Hi, Kiddo. :)",
            "Pup 1 : ''Alpha, Where are you going?",
            "Blizzard : ''I'm go to Ancient Dugeons :)",
            "Pup 2 : ''Woah, Are you sure Alpha? \n That place is very Dangerous,\n My Parent said only Alpha can to there.",
            "Blizzard : ''Im sure about that :)",
            "Pup 1 & Pup 2: ''Ok Then Alpha, Good luck.''",
            "Blizzard : ''Thank you, Kindos. See ya ;)''",
            "Pup 1 & Pup 2 : ''Your Welcome, Alpha, see yaa!!!''"
    };
    private int [][] StonesLoc=
        {{ 88 , 578 }, { 90 , 538 }, { 117 , 518 },
            { 160 , 518 }, { 204 , 518 }, { 204 , 518 }, 
            { 234 , 518 }, { 259 , 518 }, { 289 , 520 },
            { 327 , 520 }, { 357 , 521 }, { 387 , 521 },
            { 388 , 543 }, { 390 , 580 }
        };
    private int [][] Pine3Loc=
        {{ 552 , 565 } , { 588 , 564 } , { 108 , 468 } , { 124 , 468 } ,
            { 143 , 469 } , { 160 , 470 } , { 178 , 468 } , { 192 , 469 } ,
            { 207 , 469 } , { 226 , 471 } , { 322 , 470 } , { 268 , 471 } ,
            { 288 , 469 } , { 310 , 471 } , { 351 , 471 } , { 372 , 472 } ,
            { 104 , 21  } , { 67  , 24  } , { 41  , 27  } , { 161 , 21  } ,
            { 133 , 21  } , { 213 , 22  } , { 235 , 22  } , { 259 , 22  },
            { 287 , 21  } , { 310 , 21  } , { 515 , 24  } , { 543 , 24  },        
            { 573 , 24  } , { 604 , 24  } , { 634 , 23  } , { 668 , 26  },
            { 744 , 24  }
        };
    private int[][] Pine2Loc=
        { { 416 , 446 } , { 351 , 8 } , { 479 , 11 } ,
            { 703 ,   7 } , { 781 , 22 }
        };

    private int [][]PineLoc=
        {  { 523 , 549 } , { 634 , 547 } , { 770 , 547 } , { 796 , 130 } ,
            { 797 , 153 } , { 795 , 171 } , { 797 , 201 } , { 797 , 229 } ,
            { 799 , 256 } , { 797 , 283 } , { 795 , 311 } , { 793 , 344 } ,
            { 793 , 375 } , { 790 , 421 } , { 791 , 466 } , { 790 , 506 } ,
            { 790 , 545 } , { 129 ,   6 } , {   6 ,  72 } , {  11 ,  36 } ,
            {   4 ,  49 } , {   5 ,  63 } , {   7 ,  91 } , {   7 , 113 } ,
            {  11 , 147 } , {   8 , 181 } , {   7 , 214 } , {   8 , 245 } ,
            {   8 , 283 } , {  89 , 453 }
        };
    public void AddStones()
    {for(int i=0; i<StonesLoc.length;i++)
        {st = new Stones();
            addObject(st, StonesLoc[i][0], StonesLoc[i][1]);
        }
    }

    public void AddTreePines()
    {for(int i=0;i<PineLoc.length;i++)
        {t1 = new Tree();
            addObject(t1, PineLoc[i][0], PineLoc[i][1]);
        }
    }

    public void AddTreePines2()
    {for(int i=0;i<Pine2Loc.length;i++)
        {t2 = new Tree2();
            addObject(t2, Pine2Loc[i][0], Pine2Loc[i][1]);
        }
    }

    public void AddTreePines3()
    {for(int i=0;i<Pine3Loc.length;i++)
        {Tree3 t3 = new Tree3();
            addObject(t3, Pine3Loc[i][0], Pine3Loc[i][1]);
        }
    }
public void adddialog()
    { Dialogue dialogue = new Dialogue(dialog1);
        addObject(dialogue, 368,559);
    }
    public void adddialog2()
    {Dialogue dialogue2 = new Dialogue(dialog2);
        addObject(dialogue2, 368,559);
    }
    /**
     * Constructor for objects of class BridgeStoneForest.
     * 
     */
    public BridgeStoneForest()
    {// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1);
        /**
         * Blackground
         */
        setBackground("Background/Bridge Forest/corkboard.jpg");
        /**
         * BackSound
         */
        Back.playLoop();
        /**
         * NPC
         */
        //WolfLink
        WolfLink wolfLink = new WolfLink();
        addObject(wolfLink,419,68);
        //Cerberus
        Cerberus cerberus = new Cerberus();
        addObject(cerberus,704,525);
        //Werwwolf
        Werewolf werewolf = new Werewolf();
        addObject(werewolf,33,533);
        //Rayquaza
        Rayquaza rayquaza = new Rayquaza();
        addObject(rayquaza,451,535);

        /**
         * Blizzard
         */
        //Blizzard
        Blizzard blizzard =  new Blizzard();
        addObject(blizzard,291,163);
        /**
         * MapsAttribute
         */
        //River
        River river = new River();
        addObject(river,238,564);

        //Flatfrom
        Flatfrom1 flatfrom1 = new Flatfrom1();
        addObject(flatfrom1,24,582);
        Flatfrom2 flatfrom2 = new Flatfrom2();
        addObject(flatfrom2,452,582);
        Flatfrom3 flatfrom3 = new Flatfrom3();
        addObject(flatfrom3,701,578);
        Flatfrom4 flatfrom4 = new Flatfrom4();
        addObject(flatfrom4,416,21);
        
        //Trees
        AddTreePines();
        AddTreePines2();
        AddTreePines3();
        //Stones
        AddStones();
        /**
         * Dens
         */
        //Blizzard home
        BlizzardHomes bh = new BlizzardHomes();
        addObject(bh,65,67);
        //Parents Den Den
        ParerentsHomes ph = new ParerentsHomes();
        addObject(ph,764,38);

        //info
        addObject(new TempText("Bridge Stone Forest", 60), 214, 48);
        //WolfSatue
        WolfStatue wolfStatue = new WolfStatue();
        addObject(wolfStatue,426,254);

        //Dialogue
adddialog();

    }

  public void act()
    {if (dg.getWorld() == this && "z".equals(Greenfoot.getKey()))
        {((Dialogue)getObjects(Dialogue.class).get(0)).next();
    }
}
}
danpost danpost

2022/1/2

#
In BridgeStoneForest class, replace the first 2 words of lines 99 and 103 with dg. Also, change line 189 to:
dg.next();
danpost danpost

2022/1/2

#
If you want to have the dialog2 dialog accessible to the BridgeStoneForest class, make the dialog2 array a static object. Actually, best would be to make it a "public static final" field. Then you can assign it to dg in BridgeStoneForest class with (presuming that the array is in the Blizzard class):
dg = new Dialogue(Blizzard.dialog2);
mariq_rasyid29 mariq_rasyid29

2022/1/2

#
roger that sir
You need to login to post a reply.