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

2020/7/16

How to have the first position of an object?

cccmoi88 cccmoi88

2020/7/16

#
Hey, I want to know how can I have the first position of an object, because I'm making a football game, and you get more poit if you score far. So I don't know if it's possible to have only the first position of an actor.
if(this.getOneIntersectingObject(Goal.class) != null && this.getX() < 100){
        
            point = point + 5;
            
        
        }
        
              
        if(this.getOneIntersectingObject(Goal.class) != null && this.getX() < 300){
        
            point = point + 1;
            
        
        }
danpost danpost

2020/7/16

#
cccmoi88 wrote...
Hey, I want to know how can I have the first position of an object, because I'm making a football game, and you get more poit if you score far. So I don't know if it's possible to have only the first position of an actor. << Code Omitted >>
I cannot see where near or far is relevant here. If you are intersecting the goal, you would be just there, touching the goal. Give example with details of what you are trying to accomplish here.
cccmoi88 cccmoi88

2020/7/17

#
https://prnt.sc/tjg9h5 This is a screenshot of my game, and if the player shoot at the +5 point, he receive, +5 point, if he shoot at the +3 point, he receive +3 point, and if he shoot at +1 point, he receive +1 point. But, the ball move and the getX() is not constant, so I don't know if it's possible to make it constant.
danpost danpost

2020/7/17

#
Have the ball assigned a "worth" value when kicked. Only use it if touches goal.
Falafel_ Falafel_

2020/7/17

#
The getX() will always change with location of the ball. But you can take a 'snapshot' of getX() at a certain time by having some sort of interaction (touching the goal) or timer, and assign it to a variable. I don't quite get what you want to do, but to assign such a variable:
if(getOneIntersectingObject(Goal.class) != null)
        {
            int xAtTimeOfIntersectingGoal = getX();        
        }
Here you will simply get the x-location of the ball when it goes through a goal, meaning it will be the x-location of whichever goal it hits. If you want to keep that location and not have it update when hitting the next goal, you need to either have seperate goal classes or some sort of toggle to prevent xAtTimeOfIntersectingGoal from updating, such as:
boolean hasHitGoal = false;

if(getOneIntersectingObject(Goal.class) != null && hasHitGoal == false)
        {
            xAtTimeOfIntersectingGoal = getX();
            hasHitGoal = true;
        }
cccmoi88 cccmoi88

2020/7/18

#
Thanks guys
You need to login to post a reply.