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

2019/2/3

I struggle with giving my actor reversed controls

Tommes Tommes

2019/2/3

#
public class Player2 extends Actor
{
private int x = 0;
private int p = 0;  
private int q = 0;
private boolean event1 = false;
    /**
     * Act - do whatever the Player2 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */ 
public void act() {
    bewegen();
    Events();
    Umgekehrte_steuerung2();
}
public void bewegen(){
    if (event1==false)  {
        if(getX()<350){
            if (Greenfoot.isKeyDown("d")){
                setRotation(0);
                move(1);
            }
        }
        if (Greenfoot.isKeyDown("w")){
            setRotation(270);
            move(1);
        }
        if (Greenfoot.isKeyDown("a")){
            setRotation(180);
            move(1);
        }
        if (Greenfoot.isKeyDown("s")){
            setRotation(90);
            move(1);
        }
    }
    if (isTouching(Schraube.class)) {
        x = x+1;
        removeTouching(Schraube.class);
    }
    if (event1=true)  {
        if(getX()<350){
            if (Greenfoot.isKeyDown("a")){
                setRotation(0);
                move(1);
            }
        }
        if (Greenfoot.isKeyDown("s")){
            setRotation(270);
            move(1);
        }
        if (Greenfoot.isKeyDown("d")){
            setRotation(180);
            move(1);
        }
        if (Greenfoot.isKeyDown("w")){
            setRotation(90);
            move(1);
        }
    }
}
public void Events()  {
    if ( x > 5)  {
        x = x-6;
        if (p==0) {
            p = p + Greenfoot.getRandomNumber(2)+1;
            if (p==2)  {
                p=1;
            }
            if (p==3)  {
              p=1;
            }
            if (p==1)  {
                q = q + 80;
                event1=true;
            }
        }
    }
}
public void Umgekehrte_steuerung2()  {
    if (q==0)  {
        event1=false;
        p=0;
    }
    if (q>0)  {
        q = q-1;
    }
}
}
That's my player2 and to test things for the first event,p should be every time 1. Now I've got the problem that if I start the program with this code I have to shut the game down... My goal is, that the controls of player2 are reversed/changed if he collects 6 of these things. I just need help please!
danpost danpost

2019/2/3

#
Change line 41 to:
if (event1 == true) {
(with a double equal sign).
Tommes Tommes

2019/2/3

#
Thank you! You helped me a lot!
You need to login to post a reply.