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

2020/9/28

setLocation for other classes

Quabey Quabey

2020/9/28

#
Hey, Im currently working on a small game and Im trying to reset the player after every round to his starting point. This code is in my commands class snake and turtle are both subclasses of commands
public void score(int splus){
        score1= score1 + splus;
        getWorld().showText(""+score1, 1, 1);
        Actor actor =getOneIntersectingObject(turtle.class);
        if (turtle != null){
            turtle.setLocation(46,21);
        }
        Actor snake = getOneIntersectingObject(snake.class);
        if (actor1 != null){
            snake.setLocation(7,13);
        }
But it just doesn't work. Anyone here know how I can fix it.
danpost danpost

2020/9/28

#
Quabey wrote...
Hey, Im currently working on a small game and Im trying to reset the player after every round to his starting point. This code is in my commands class snake and turtle are both subclasses of commands << Code Omitted >> But it just doesn't work. Anyone here know how I can fix it.
Looks to me like lines 8 thru 11 (presuming "actor1", which looks undefined, should be "snake") are specific to the turtle and lines 4 thru 7 are specific to the snake and, therefore should be done in their specific classes (however, cross-collision checking should be avoided). You can forego lines 4 thru 7 and move lines 8 thru 12 (with an extra setLocation call for the turtle) into the turtle class.
You need to login to post a reply.