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

2018/7/25

Broken code

Ticker175 Ticker175

2018/7/25

#
hey guys im having trouble with my code for my pacman game can anyone see whats causeing the problem of the check methods.
import greenfoot.*;

public class Blinky extends Ghosts
{
    // public int pacx;
    // public int pacy;
    public int Tracking = 0;
    private int rotation = 0;
    private int left,up,right,down;
    public int moveb=0, movebb=-2;
    
    // aims directly for pacman and speeds up when half of the dots are collected
    public void act()
    {
        if (Tracking == 0){
            setLocation(getX()+moveb, getY()+movebb);
            
            Actor Wall = getOneIntersectingObject(Wall.class);
            if (Wall != null) {
                setLocation(getX()-moveb, getY()-movebb);
            }
        }
        up=0;
        down=0;
        left=0;
        right=0;
        
        Pathfinding();
        
        
        if (isTouching(Entry_Intercection.class)){
            //nope\\
            Tracking = 0;
        }
        else if (isTouching(Intercection.class)){
            checkRight();
            checkLeft();
            checkDown();
            checkUp();
            
            Tracking = 1;
        }
    }
    
    
    public void Pathfinding()
    {
        if (isTouching(Entry_Intercection.class)){
            //no
        }
        else if (isTouching(Intercection.class))
        {
            if (getRotation()==90) //right
            {
                if (isTouching(Intercection.class)){
                    right=2;
                    Execute();
                }
            }
            else if (getRotation()==0) //down
            {
                if (isTouching(Intercection.class)){
                    down=2;
                    Execute();
                }
            }
            else if (getRotation()==270) //left
            {
                if (isTouching(Intercection.class)){
                    left=2;
                    Execute();
                }
            }
            else if (getRotation()==180) //up
            {
                if (isTouching(Intercection.class)){
                    up=2;
                    Execute();
                }
            }
        }
    }
    public void checkRight()
    {
        if (getOneObjectAtOffset(7, 0, Wall.class) == null){
            if (right == 2)
            {
                right=0;
            }
            else{
                right=1;
            }
        }
        else if (getOneObjectAtOffset(7, 0, Wall.class) != null){
            right=0;
        }
    }
    public void checkUp()
    {
        if (getOneObjectAtOffset(0, 7, Wall.class) == null){
            if (up == 2)
            {
                up=0;
            }
            else{
                up=1;
            }
        }
        else if (getOneObjectAtOffset(0, 7, Wall.class) != null){
            up=0;
        }
    }
    public void checkLeft()
    {
        if (getOneObjectAtOffset(-7, 0, Wall.class) == null){
            if (left == 2)
            {
                left=0;
            }
            else{
                left=1;
            }
        }
        else if (getOneObjectAtOffset(-7, 0, Wall.class) != null){
            left=0;
        }
    }
    public void checkDown()
    {
        if (getOneObjectAtOffset(0, -7, Wall.class) == null){
            if (down == 2)
            {
                down=0;
            }
            else{
                down=1;
            }
        }
        else if (getOneObjectAtOffset(0, -7, Wall.class) != null){
            down=0;
        }
    }
    
    
    public void Execute()
    {
        if (isTouching(Entry_Intercection.class))
        {
            //NOPE\\
        }
        else if (isTouching(Intercection.class))
        {
            if (left == 1)//check left
            {
                if (isTouching(Intercection.class)){
                    setRotation(270);
                    left = 0;
                    moveb=-2;
                    movebb=0;
                }
            }
            if (right == 1)//check right
            {
                if (isTouching(Intercection.class)){
                    setRotation(90);
                    right = 0;
                    moveb=2;
                    movebb=0;
                }
            }
            if (up == 1)//check up
            {
                if (isTouching(Intercection.class)){
                    setRotation(0);
                    up = 0;
                    moveb=0;
                    movebb=-2;
                }
            }
            if (down == 1)//check down
            {
                if (isTouching(Intercection.class)){
                    setRotation(180);
                    down = 0;
                    moveb=0;
                    movebb=2;
                }
            }
        }
    }
    
    
    
    
}
You need to login to post a reply.