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

2017/4/19

What must I write that an actor can not go through an other actor?

1
2
3
danpost danpost

2017/4/21

#
Timon wrote...
No. Now when I press no bottom and a box came he is going underthe box and after the box he Comes up.
So, what do you want to happen when a box moves into the player from the side? Be detailed about everything until the player resumes normal playing position.
Timon Timon

2017/4/21

#
I want that he box push him to the edge andwhe he toucht the edge he die.
Timon Timon

2017/4/21

#
*I want that the box.....
danpost danpost

2017/4/21

#
Timon wrote...
I want that he box push him to the edge andwhe he toucht the edge he die.
Then have the Boxes object move the touching player -- pushing him.
Timon Timon

2017/4/21

#
Yes, but how I wite the code.
Timon Timon

2017/4/22

#
Please help me.
danpost danpost

2017/4/22

#
Timon wrote...
Please help me.
Have not seen your Boxes class yet.
Timon Timon

2017/4/22

#
ou sorry
Timon Timon

2017/4/22

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Boxes here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Boxes extends Objects
{
    /**
     * Act - do whatever the Boxes wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        this.move();
        this.despawning();
    }    
}
that is my Boxes code but the Boxes are a subclass from the Objects.
Timon Timon

2017/4/22

#
And that is my Object code.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Objects here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Objects extends Actor
{
    /**
     * Act - do whatever the Objects wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
    }  
    public void move()
    {
     move(-6);   
        
    }
    public int score=0;
   public void despawning()
    {
        if(this.isAtEdge())
        {
            getWorld().removeObject(this);
        }
    }
    public void countScore()
    {
        score++;
        setImage(new GreenfootImage("Score: " + score, 48, Color.WHITE, Color.BLACK));
    }
}
Timon Timon

2017/4/22

#
I have the Object class, because I have not only the "Boxes" I have also the "Walls" class
danpost danpost

2017/4/22

#
Timon wrote...
I have the Object class, because I have not only the "Boxes" I have also the "Walls" class
Do you want the walls to be able to move (push) the player also?
Timon Timon

2017/4/22

#
Yes.Please.
danpost danpost

2017/4/22

#
Timon wrote...
Yes.Please.
Then insert the following at line 22 in the Objects class code above:
Actor player = getOneIntersectingObject(Player.class); // adjust class name as needed
if (player != null) player.move(-6);
Timon Timon

2017/4/22

#
Thank you very much. It works.
You need to login to post a reply.
1
2
3