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

2018/5/3

HELP - Frogger game remake

Ticker175 Ticker175

2018/5/3

#
Hey guys I'm trying to remake the classic frogger game and I'm almost done but I'm not the best coder and i need some help =/ Any help would be great I'm only having a problem with my Log class I'm trying to create the logs using an array in my world class (this works great) Then i am setting the speed and respawn/wrap mechanics in my Log class (works =D) I'm setting the speed of the logs with a integer called speed1, speed 2 etc. The only thing left that the log needs to do is move the frog when it is on the log. but this is proving to be very difficult because the logs have 4 different speeds and I've been trying to make this work but everything I've tried doesn't work =/ the code i have in my frog class i don't mind changing (it was just the last thing that i had tried)

Log.Class

public class Log extends Actor
{
    int speed1 = 3;
    int speed2 = 1;
    int speed3 = 2;
    int speed4 = 4;
    
    public void act() 
    {
        Core();
    }
    
    public void Core()
    {
        if (getY() == 205) {
            move(speed1);
            Actor Bounds = getOneIntersectingObject(Bounds.class);
            if (Bounds != null)
            {
                setLocation(0, 205);
            }
        }
        if (getY() == 265) {
            move(speed2);
            Actor Bounds = getOneIntersectingObject(Bounds.class);
            if (Bounds != null)
            {
                setLocation(0, 265);
            }
        }
        if (getY() == 325) {
            move(speed3);
            Actor Bounds = getOneIntersectingObject(Bounds.class);
            if (Bounds != null)
            {
                setLocation(0, 325);
            }
        }
        if (getY() == 385) {
            move(speed4);
            Actor Bounds = getOneIntersectingObject(Bounds.class);
            if (Bounds != null)
            {
                setLocation(0, 385);
            }
        }
    }
}

Frog.Class

Highlighted lines are the only ones necessary to this problem
public class Frog extends Actor
{
    private int timer;
    int speed1 = 3;
    int speed2 = 1;
    int speed3 = 2;
    int speed4 = 4;
    
    public void act() 
    {
        FrogLog();
        Jumping();
    }
    
    public void Jumping()
    {
        String key = Greenfoot.getKey();
        if (key != null && key.equals("up")) jump();
        if (key != null && key.equals("down")) jumpdown();
        if (key != null && key.equals("right")) jumpright();
        if (key != null && key.equals("left")) jumpleft();
    }
    
    public void jump()
    {
        setLocation(getX(), getY()-60);
        setImage("Frog.png");
    }
    public void jumpdown()
    {
        setLocation(getX(), getY()+60);
        setImage("FrogDown.png");
    }
    public void jumpright()
    {
        setLocation(getX()+60, getY());
        setImage("FrogRight.png");
    }
    public void jumpleft()
    {
        setLocation(getX()-60, getY());
        setImage("FrogLeft.png");
    }
    
    public void FrogLog()
    {
        if (isTouching(Log.class))
        {            
            if (getX() == 205)
            {
                setLocation(getX() + speed1 , getY());
                if (timer > 0) timer--;
                if (timer == 0)
                {
                    timer = 50;
                }
            }
            if (getX() == 265)
            {
                setLocation(getX() + speed2 , getY());
                if (timer > 0) timer--;
                if (timer == 0)
                {
                    timer = 50;
                }
            }
            if (getX() == 325)
            {
                setLocation(getX() + speed3 , getY());
                if (timer > 0) timer--;
                if (timer == 0)
                {
                    timer = 50;
                }
            }
            if (getX() == 385)
            {
                setLocation(getX() + speed4 , getY());
                if (timer > 0) timer--;
                if (timer == 0)
                {
                    timer = 50;
                }
            }
        }
        else if (isTouching(River.class))
        {
            getWorld().removeObject(this);
        }
    }
}
Thanks Thomas
Ticker175 Ticker175

2018/5/3

#
if u need anymore code just lemi know and ill upload it
Ticker175 Ticker175

2018/5/3

#
I figured out what was wrong after looking over the code closely a few times i had getX (in my frog class) where i needed getY. so i replaced it and it now works flawlessly =)
You need to login to post a reply.