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

2019/8/25

appearing objects

1
2
avery avery

2019/8/25

#
hi, how can i make my actors continually appearing randomly at the same y axis?
avery avery

2019/8/25

#
send helpp
danpost danpost

2019/8/25

#
avery wrote...
hi, how can i make my actors continually appearing randomly at the same y axis?
Regulated spawning at constant x and random y. What have you tried?
avery avery

2019/8/25

#
this is my program,
import greenfoot.*;
public class ahihihi extends World
{
    egpuding egpuding = new egpuding();
    jelatin jelatin = new jelatin();
    prag prag = new prag();
    /**
     * Constructor for objects of class anuto.
     * 
     */
    public ahihihi()
    {    
        super(1100, 600, 1); 

        prepare();
    }
    public void act()
    {
        int randomNumber = Greenfoot.getRandomNumber(30);
        if(randomNumber == 15)
        {
            int randomX = Greenfoot.getRandomNumber(1100);
            int randomY = Greenfoot.getRandomNumber(600);
            addObject(egpuding, randomX, randomY);
        }
        
        if(randomNumber == 15)
        {
            int randomX = Greenfoot.getRandomNumber(1100);
            int randomY = Greenfoot.getRandomNumber(600);
            addObject(jelatin, randomX, randomY);
        }
       
        if(randomNumber == 15)
        {
            int randomX = Greenfoot.getRandomNumber(1100);
            int randomY = Greenfoot.getRandomNumber(600);
            addObject(prag, randomX, randomY);
        }
    }
i dont know what to change in the codes to make the actors continuously appear randomly in the same x axis --dont mind the names of the actors, forgive me for i am a person with too much humor
avery wrote...
hi, how can i make my actors continually appearing randomly at the same y axis?
--its "at the same x axis" sorry
danpost danpost

2019/8/25

#
avery wrote...
this is my program, << Code Omitted >> i dont know what to change in the codes to make the actors continuously appear randomly in the same x axis ... << Quote Omitted .> --its "at the same x axis" sorry
If along the same horizontal, the you would use a random x and a constant y. It is unclear, however, exactly what you are trying to do. You appear to be spawning 3 things on each random hit on 15. Is there a specific x value you want to spawn them at or do you want all 3 to spawn along the same random horizontal on each hit?
avery avery

2019/8/25

#
there is a specific x value
avery avery

2019/8/25

#
but i dont know what x value is it if i want it to be at the top most part of the scenario
danpost danpost

2019/8/25

#
avery wrote...
there is a specific x value...but i dont know what x value is it if i want it to be at the top most part of the scenario
You mean y value. A random x value with a y value of 0 will place the actors along the top of the window.
avery avery

2019/8/25

#
oh yes sorry, thank you for your help! :>
avery avery

2019/8/26

#
when the actor touches the ground, i want it to disappear and get back to the top and fall again, how can i do that?
avery avery

2019/8/26

#
another thing, i have this code,
public void eat ()
    {
        Actor egpuding;
        egpuding = getOneObjectAtOffset(0, 0, egpuding.class);
        if (egpuding != null)
        {
            World world;
            world = getWorld();
            ahihihi ahihihi = (ahihihi)world;
            counter counter = ahihihi.getcounter(); 
            counter.addScore();
            world.removeObject(egpuding);
        }
         Actor jelatin;
        jelatin = getOneObjectAtOffset(0, 0, jelatin.class);
        if (jelatin != null)
        {
            World world;
            world = getWorld();
            ahihihi ahihihi = (ahihihi)world;
            counter counter = ahihihi.getcounter(); 
            counter.addScore();
            world.removeObject(jelatin);
        }
         Actor milkeu;
        milkeu = getOneObjectAtOffset(0, 0, milkeu.class);
        if (milkeu != null)
        {
            World world;
            world = getWorld();
            ahihihi ahihihi = (ahihihi)world;
            counter counter = ahihihi.getcounter(); 
            counter.addScore();
            world.removeObject(milkeu);
        }
    }
that's supposed to be adding scores whenever the actors above touch the milk tea, but it doesn't do so. Is there something wrong?
avery avery

2019/8/26

#
avery wrote...
another thing, i have this code,
public void eat ()
    {
        Actor egpuding;
        egpuding = getOneObjectAtOffset(0, 0, egpuding.class);
        if (egpuding != null)
        {
            World world;
            world = getWorld();
            ahihihi ahihihi = (ahihihi)world;
            counter counter = ahihihi.getcounter(); 
            counter.addScore();
            world.removeObject(egpuding);
        }
         Actor jelatin;
        jelatin = getOneObjectAtOffset(0, 0, jelatin.class);
        if (jelatin != null)
        {
            World world;
            world = getWorld();
            ahihihi ahihihi = (ahihihi)world;
            counter counter = ahihihi.getcounter(); 
            counter.addScore();
            world.removeObject(jelatin);
        }
         Actor milkeu;
        milkeu = getOneObjectAtOffset(0, 0, milkeu.class);
        if (milkeu != null)
        {
            World world;
            world = getWorld();
            ahihihi ahihihi = (ahihihi)world;
            counter counter = ahihihi.getcounter(); 
            counter.addScore();
            world.removeObject(milkeu);
        }
    }
that's supposed to be adding scores whenever the actors above touch the milk tea, but it doesn't do so. Is there something wrong?
nevermind hehe
avery avery

2019/8/26

#
avery wrote...
when the actor touches the ground, i want it to disappear and get back to the top and fall again, how can i do that?
just this.. please?
danpost danpost

2019/8/26

#
avery wrote...
when the actor touches the ground, i want it to disappear and get back to the top and fall again, how can i do that?
if (getY() >= getWorld().getHeight()-1) setLocation(getX(), 0);
avery avery

2019/8/26

#
thank yoouuuu!!
There are more replies on the next page.
1
2