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

2018/1/2

trump should collide with mexicaan and send him flying out of the map, the only problem is that trump goes straight through mexicaan and cant seem to "see" him

nick_crompton nick_crompton

2018/1/2

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

/**
 * Write a description of class Mexicaan here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Mexicaan extends Animal
{int vSpeed;
    int acceleration=1;
    
    /**
     * Act - do whatever the Mexicaan wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
       checkFall();
       onGround();
      fall();
      die();
      atWorldEdge();
      moveAround();
      
      
     
      
    }    
    public boolean onGround()
    {
        Object under = getOneObjectAtOffset(0, getImage().getHeight()/2 + 2, Steen.class);
        return under != null;
        
    }

    public void checkFall()
    {
        if (onGround()) {
            vSpeed = 0;
        }
        else {
            fall();
        }
      
        
    }

    public void fall()
    {
        setLocation (getX(), getY() + vSpeed);
        if(vSpeed<10)
        {
            vSpeed += acceleration;
            
        }
    }

       public void die()
    {
    Actor Trump = getOneIntersectingObject(Mexicaan.class);
    
    if(Trump!=null)
    {   
        vSpeed =-50;
        
        
    }
    
    
    
    }// bron: pws game lobster class
   
  public boolean atWorldEdge()
{

   
    if (getY() <= 5 || getY() >= getWorld() . getHeight() -5) 
        return true;
    else
        return false;
        
        
}// bron https://www.greenfoot.org/topics/2668
private void moveAround()  
    {  
        
        if (atWorldEdge())
            {  
                getWorld().removeObject(this);  
            }  
    }  
 

}
danpost danpost

2018/1/2

#
It would help if the Mexican looked for a Trrump type object instead of another Mexican.
nick_crompton nick_crompton

2018/1/4

#
i dont understand. in public void die, trump is looking for mexicaan right? and i f they touch he should fly.
xbLank xbLank

2018/1/4

#
It's not working like that. Please do this:
public void die()
{   
    if(getOneIntersectingObject(Trump.class)!= null)
    {   
        vSpeed =-50;
    }
}
Yehuda Yehuda

2018/1/4

#
On line 62 (of the Mexicaan class) you have Mexicaan.class as the parameter, there is no Trump involved (besides for the name of your instance of Actor). You also just change the vSpeed in that method no actual death.
xbLank xbLank

2018/1/4

#
Thats what he wanted to do. Well more or less. I dont know if you can call that flying.
nick_crompton nick_crompton

2018/1/4

#
일리아스 its not working
nick_crompton nick_crompton

2018/1/4

#
@yehuda i changed the vspeed to -50 which causes him to go up and in line 91 the mexican gets removed if it hits the top of the world
xbLank xbLank

2018/1/4

#
It has to work. Try removing the Mexicaan as soon as he hits Trump instead of changing the vSpeed value . If that works then it has something to do with your moving mechanic. Sorry im too tired to read into that.
nick_crompton nick_crompton

2018/1/4

#
well its not, maybe worth noticing: if the mexican is still in the air and not on the ground, the code works he goes flying in the air and disappears if trump touches but once he lands he doesnt move. AND OMG I FIGUERED IT OUT WHILE WRITING THIS. the problem is in line 41, the vspeed is 0 when it touches the ground so it stays 0 the whole time, i had to call die(); after it so it would work. thanks so much for all your advice and support i really appreciate it. :)
xbLank xbLank

2018/1/4

#
Yea I knew it was somewhere else in the code, sorry that im a lazy fuck when I'm tired c: Glad you found it yourself^^
Yehuda Yehuda

2018/1/5

#
But in your given code the 'die' method is called after 'checkFall', and 'moveAround' is called right after 'die' (calling 'atWorldEdge' on line 24 doesn't do anything), so line 41 should not have been executed.
Yehuda Yehuda

2018/1/5

#
It gets executed (answering my own question) because you have to go through an extra act cycle since changing the 'vSpeed' doesn't actually have an effect until the 'fall' method gets called. To fix the problem in the code shown above you can just add in "fall();" on line 67.
You need to login to post a reply.