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

2013/7/11

my "Enemy" wont move like its supposed to when it is 250 leftTurn, it moves half way across the map. I want it to run the full way. how do i fix this problem??

qsapp.3 qsapp.3

2013/7/11

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

/**
 * Write a description of class Enemy3 here.
 * 
 * @author (Quinn Sapp) 
 * @version (5 July 2013)
 */
public class Enemy3 extends Animal
{
    private int speed = 4;
    private int leftTurn = 450;
    private int rightTurn = 450;

    /**
     * 
     */
    public void act() 
    {
        setLocation ( getX() + speed, getY() );
        Actor actor = getOneIntersectingObject(null);
        if(actor != null) {
            actor.setLocation ( actor.getX() + speed, actor.getY() );
        }
        
        if (atTurningPoint()) {
            speed = -speed;
        }
    }
    
    /**
     * 
     */
    public boolean atTurningPoint()
    {
        return (getX() <= leftTurn || getX() >= rightTurn);
    }
    
    
}
danpost danpost

2013/7/11

#
Forgive me if I am wrong, but it appears that the 'atTurningPoint' method will always return true. The x-coordinate of the enemie will always be either less than or equal to leftTurn (450) or greater than or equal to rightTurn (also 450). This means that the speed will always be changing directions and your actor will jiggle in place. Your conditions for turning in your 'atTurningPoint' method needs some work.
You need to login to post a reply.