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

2019/4/19

Delay

1
2
Philipplol Philipplol

2019/4/19

#
Hi everyone i have a little problem i build a little Game with random moving enemys. Everyone time one of them ist moving i cant move the main charecter. Ist this fixabel?(PS:i am German so sorry dir Bad english :P)
N0way N0way

2019/4/20

#
post your code pls :D
Philipplol Philipplol

2019/4/20

#
public void laufen()
    {
        
        if (Greenfoot.isKeyDown("right") && !wandVorne())
        {
            this.setLocation(getX()+1 ,getY());
            this.setImage(right);
            Greenfoot.delay(8000);
            this.setImage(right2); 
            Greenfoot.delay(8000);
           
        }
        if (Greenfoot.isKeyDown("left") && !wandHinten())
        {
            this.setLocation(getX()-1 ,getY());
            this.setImage(left);
            Greenfoot.delay(8000);
            this.setImage(left2);
            Greenfoot.delay(8000);

        }
        if (Greenfoot.isKeyDown("up") && !wandLinks())
        {
            this.setLocation(getX() ,getY()-1);
            this.setImage(up);
            Greenfoot.delay(8000);
            this.setImage(up2);
            Greenfoot.delay(8000);
            
        }
        if(Greenfoot.isKeyDown("down") && !wandRechts())
        {
            this.setLocation(getX() ,getY()+1);  
            this.setImage(down2); 
            Greenfoot.delay(8000);
            this.setImage(down);
            Greenfoot.delay(8000);
            
        }
    }
    
  public void act()
    {
        laufen();
        
    }
this is the main character( only moving)
public GreenfootImage down = new GreenfootImage ("oktoroc.png");
        public GreenfootImage up= new GreenfootImage ("oktoroc1.png");
        public GreenfootImage right = new GreenfootImage ("oktoroc3.png");
        public GreenfootImage left = new GreenfootImage ("oktoroc2.png");
        public void  laufen()
        {
            if (Greenfoot.getRandomNumber(100) < 10 && !wandRechts())
            {
                this.setImage(down);
                this.setLocation(getX(), getY()+1);
                Greenfoot.delay(25000);
            }
            if (Greenfoot.getRandomNumber(100) < 10 && !wandLinks())
            {
                this.setImage(up);
                this.setLocation(getX(), getY()-1);
                Greenfoot.delay(25000);
                
            }
            if (Greenfoot.getRandomNumber(100) < 10 && !wandVorne())
            {
                this.setImage(right);
                this.setLocation(getX()+1, getY());
                Greenfoot.delay(25000);
            }
            if(Greenfoot.getRandomNumber(100) < 10 && !wandHinten())
            {
                this.setImage(left);
                this.setLocation(getX()-1, getY());
                Greenfoot.delay(25000);
            }
        }
public void act() 
    {
       
       laufen();
       
        
    }  
this is the enemy (only moving)
N0way N0way

2019/4/20

#
under public class you can just set speed
private final int SPEED=5;
you can use this movement code i think will work better
if(Greenfoot.isKeyDown("right"))   
        {
            move(SPEED);
            this.setImage(right);
            Greenfoot.delay(8000);
            this.setImage(right2); 
            Greenfoot.delay(8000);
        }
        if(Greenfoot.isKeyDown("left"))
        {
            move(-SPEED);
            this.setImage(left);
            Greenfoot.delay(8000);
            this.setImage(left2);
            Greenfoot.delay(8000);
        }
        if(Greenfoot.isKeyDown("up"))
        {
            setLocation(getX(),getY()-SPEED);
            this.setImage(up);
            Greenfoot.delay(8000);
            this.setImage(up2);
            Greenfoot.delay(8000);
        }
        if(Greenfoot.isKeyDown("down"))
        {
            setLocation(getX(),getY()+SPEED);
            this.setImage(down2); 
            Greenfoot.delay(8000);
            this.setImage(down);
            Greenfoot.delay(8000);
        }
and put the same code of moving in monster as in main char it should work
Philipplol Philipplol

2019/4/20

#
hi first thanks for the help but this doesn`t fix my problem if i use your code the charakter is moving 5 spaces insted of one (i am trying to build the first the legend of zelde) and even with this code i cant move the charaker at the same time the enemy is moving
N0way N0way

2019/4/20

#
set private final int SPEED=5; to 1 and put the same thing in monster class private final int SPEED=1;
public GreenfootImage down = new GreenfootImage ("oktoroc.png");
        public GreenfootImage up= new GreenfootImage ("oktoroc1.png");
        public GreenfootImage right = new GreenfootImage ("oktoroc3.png");
        public GreenfootImage left = new GreenfootImage ("oktoroc2.png");
        public void  laufen()
        {
            if (Greenfoot.getRandomNumber(100) < 10 && !wandRechts())
            {
                this.setImage(down);
                setLocation(getX(),getY()+SPEED);
                Greenfoot.delay(25000);
            }
            if (Greenfoot.getRandomNumber(100) < 10 && !wandLinks())
            {
                this.setImage(up);
                setLocation(getX(),getY()-SPEED);
                Greenfoot.delay(25000);
                 
            }
            if (Greenfoot.getRandomNumber(100) < 10 && !wandVorne())
            {
                this.setImage(right);
                move(SPEED);
                Greenfoot.delay(25000);
            }
            if(Greenfoot.getRandomNumber(100) < 10 && !wandHinten())
            {
                this.setImage(left);
                move(-SPEED);
                Greenfoot.delay(25000);
            }
        }
public void act() 
    {
        
       laufen();
        
         
    }
i have edited your monster movement as well and i dont know why are you generating random number from 100 just make it 4 and in if statements do
            if (Greenfoot.getRandomNumber(4) == 1 && !wandVorne())
and so one 4 == 2 4 == 3
Philipplol Philipplol

2019/4/20

#
 private static int zellenGroesse = 50
    ;

    
    public test()
    {
        super(13, 10, zellenGroesse);
        setBackground("images/Bodenplatte.png");
        setPaintOrder(  Roboter.class, Schraube.class, Akku.class,Wand.class);
        Greenfoot.setSpeed(99);   

        prepare();
    }
(this is the world if it helps) nope still locks the Charakter if the monster is moving
N0way N0way

2019/4/20

#
yeah because of the delay change delay to 20 instead of 8000 or even lower like 10/5 just change delay everywhere in classes from that high numbers to low like 10
Philipplol Philipplol

2019/4/20

#
and the speed of the world?
N0way N0way

2019/4/20

#
im not sure what is happening in your world but i dont think you actually need speed in world but set it to 1 for now and see if it will work normally after changing delay to low like 10
Philipplol Philipplol

2019/4/20

#
the problem is just that greenfoot doesn´t do 2 command at the same time if i press start
Philipplol Philipplol

2019/4/20

#
https://www.greenfoot.org/scenarios/23705 hear i uploaded it so you can see on your own (dont press space)
N0way N0way

2019/4/20

#
its wired because when im running this game the dummy and Hero is moving normally are you using arrows to move character? :D or you want that character to dont move through dummy like wand does?
Philipplol Philipplol

2019/4/20

#
Jes i am Usingen arrows. If you walk from left to right the Charakter is sometimes stoping for a littel bit If the Monster ist moving. Or you can see it If you Press space the charakter isattacking but the Monster ist also Stop moving and i want that it does both at the same time.
Super_Hippo Super_Hippo

2019/4/20

#
Do not use Greenfoot.delay at all for moving. It pauses your whole scenario.
There are more replies on the next page.
1
2