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

2019/4/22

Need help, whenever frog eats fly, score goes up 1

joeyjin_ joeyjin_

2019/4/22

#
All i have is public void checkKeyPress() { if(Greenfoot.isKeyDown("up")) { setLocation(getX(), getY()-3); } if(Greenfoot.isKeyDown("down")) { setLocation(getX(), getY()+3); } if(Greenfoot.isKeyDown("right")) { setLocation(getX()+3, getY()); } if(Greenfoot.isKeyDown("left")) { setLocation(getX()-3, getY()); } } for he frog to move around with arrow keys I need help whenever the frog moves on top of the fly, the fly dissapears, and the score goes up
Nosson1459 Nosson1459

2019/4/22

#
i'd like to help buy you're gonna have to post all the relevant code such as the entire frog class the entire fly class and the entire world class for starters if I need other code i'll ask for it
Nosson1459 Nosson1459

2019/4/22

#
also when posting code it makes it easier if you use the code tags. like this:
public void act()
{
    random();
}
to use them look on the bottom of the text box there's a few blue words, one of them is code, press on that and a white text box appears, type or copy your code into there and press the green check when you're done and it appears in code form in your post and it makes it much easier to read
Proprogrammer04 Proprogrammer04

2019/4/23

#
You could implement this:
if(isTouching(Fly.class))
{
    getWorld().removeObject(getOneIntersectingObject(Fly.class));
    score++;
}
my fly class is called Fly and the frog class Frog the variable where the Points are saved is called score Hope it helps
joeyjin_ joeyjin_

2019/4/24

#
Proprogrammer04 wrote...
You could implement this:
if(isTouching(Fly.class))
{
    getWorld().removeObject(getOneIntersectingObject(Fly.class));
    score++;
}
my fly class is called Fly and the frog class Frog the variable where the Points are saved is called score Hope it helps
thank you
joeyjin_ joeyjin_

2019/4/24

#
Proprogrammer04 wrote...
You could implement this:
if(isTouching(Fly.class))
{
    getWorld().removeObject(getOneIntersectingObject(Fly.class));
    score++;
}
my fly class is called Fly and the frog class Frog the variable where the Points are saved is called score Hope it helps
I have that says Actor not in world, even though the fly is in the world
Nosson1459 Nosson1459

2019/4/24

#
did you put any code for the fly after it was removed? because the remove must be the last thing you use the fly for
danpost danpost

2019/4/24

#
Nosson1459 wrote...
did you put any code for the fly after it was removed? because the remove must be the last thing you use the fly for
The removal was probably from something executed just prior to this code.
You need to login to post a reply.