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

2017/3/1

How exactly does this work?

1
2
Nosson1459 Nosson1459

2017/3/1

#
The problem with using the isGround method in Egg is because there is a problem in WorldLoader. The problem is that you're doing "Color ez = bgmask.getColorAt(x,y);" but the variable bgmask wasn't defined so it's equal to null.
DuckGod DuckGod

2017/3/1

#
but it becomes defined here though.
public void testLvl()
    {
        background= new GreenfootImage("MaskTest.png");
        setBackground(background);
        bgmask = new GreenfootImage("MaskTest.png");
        startx= 100;
        starty=500;
        addObject(new Egg(), startx,starty);
    }
Nosson1459 Nosson1459

2017/3/1

#
But you have to call that method for it to be defined. Try moving lines 3 - 5 (or copying them) to the constructor method of this class (as line 37 - 39).
DuckGod DuckGod

2017/3/1

#
Ok so it doesen't error anymore... buttt the player dosen't fall at all.
Nosson1459 Nosson1459

2017/3/1

#
I don't see any code that's supposed to make that happen. I can't stick around all night so I gotta go.
DuckGod DuckGod

2017/3/1

#
in the player code if you look at physics
public void physics()
    {
        x+=xspeed;// when moving left or right
        y+=yspeed;// fall speed

        xspeed *=0.91;//used to slow down but will never reach 0 cuz science!
    }
the int y means the player's y coords and same for x and on the ground code
private void Grounds()
    {
        if (world.isGround(getX(), getY()+16))
        { yspeed = 0; 
            canjump = true; }// to check if standing on the color black

        if (world.isGround(getX(), getY()+14) )
        { y -= 1;}//

        if (world.isGround(getX(), getY()-14) )
        { y += 1; 
            if (yspeed < 0){yspeed = 0;}
        }//to check if under color black

        if (world.isGround(getX()+14, getY()) )
        { x -= 1;
            if (xspeed > 0) {xspeed = 0;}
        }// to check if trying to run into color black from the right side

        if (world.isGround(getX()-14, getY()) )
        { x += 1;
            if (xspeed < 0) {xspeed = 0;}
        }// to check if trying to run into color black from left side
    }
it changes yspeed and adds to or subtracts from the y coords like when he runs into a wall it kinda pushes him back or lands on a platform he stops moving down.
DuckGod DuckGod

2017/3/1

#
ok :(
Nosson1459 Nosson1459

2017/3/1

#
Did you uncomment line 141 - the call to the Grounds method? (now "//Grounds();", should be "Grounds();".)
DuckGod DuckGod

2017/3/2

#
Thanks but my teacher helped me figure it out.
Nosson1459 Nosson1459

2017/3/3

#
What was the problem in the end?
You need to login to post a reply.
1
2