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

2014/5/20

If my actor is within this certain area display gameover

kayuhnjayuhn kayuhnjayuhn

2014/5/20

#
I am trying to get my frogger so when it is within specific quardinates then it displays my game over class which is a pop-up. I tried to be all smart and I feel like I was decently close, but to no avail, it still didn't work. This is my code and the numbers are just at guess and check right now but how would I make it to work for this? Here is my code.
if (400 <= getX() >= 480 && 66 <= getY() >= 1)
       {
         GameOver();
       }
danpost danpost

2014/5/20

#
You cannot combine multiple checks by putting a conditional on both sides of the same value. You have to do each check individually:
if (400 <= getX() && getX() >= 480 && 66 <= getY() && getY() >= 1)
However, I do not think this is what you want, unless you just want this:
if (getX() >= 480 && getY() >= 66)
which means basically anywhere on the right side of the world except when near the very top. If you were trying to limit the area to between 400 and 480 for x and between 1 and 66 for y, then:
if (getX() >= 400 && getX() <= 480 && getY() >= 1 && getY() <= 66)
would be what you wanted.
kayuhnjayuhn kayuhnjayuhn

2014/5/20

#
This worked great, but now I am trying to set it up so if it's not on an object in this area, or if it's touching the background then it resets. Here is my code for this.
if ( getX() >= 1 && getX() <= 645 && getY() >= 284 && getY() <= 190 && canSee(Background.class))
       {
           setLocation(436, 612);
       }
danpost danpost

2014/5/20

#
If 'Background' is your world class name, then you cannot check for intersection with it as it would be a World object, not an Actor object. In this case, you would use:
if (geX() >= 1 and getX() <= 645 && getY <= 284 && getY() >= 190 && getIntersectingObjects(null).isEmpty())
kayuhnjayuhn kayuhnjayuhn

2014/5/20

#
Okay, and since I have you on here I am going to ask one more question, though it doesn't have much to do with this exact topic. When the frogger jumps onto a lily pad he is supposed to stay on it and follow until it jumps to another lilypad, and I have that code...
if (isJumping == false)    
       {    
           Actor lily = getOneIntersectingObject(Lilypad.class);      
           if (lily != null)     
           {      
               setLocation(lily.getX(), lily.getY());      
           }     
       }
My issue is that when it is on a lilypad it picks up the one moving right next to it and will automatically jump to it and then back sometimes because it picks the other one right back up. How would this be changed so it won't pick up the other lilypad unless the frog is right on top of it?
danpost danpost

2014/5/20

#
I think you just need to a little more specific as far as what is considered to be a Lilypad that will move the frog. What I mean is 'getOneIntersectingObject' will not necessarily continue returning the first Lilypad encountered. Therefore, you might want to qualify that the lilypad must be below (at near the feet of) the frog. Use 'getOneObjectAtOffset(0, getImage().getWidth()/2-1, Lilypad.class)', or something like that. If your scenario is more of a top-down view, where the frog is actually on top of the lilypad and not above it, then try saving the lilypads coordinates to remove and add it back into the world. That way it will be the last drawn lilypad (this is undocumented happenstance and a later greenfoot update could change this -- but, that is not very likely) and the frog might stay on top of it (I am guessing here, as I have not tried anything like that)
kayuhnjayuhn kayuhnjayuhn

2014/5/20

#
Yes, this is a top-down view, but when I tried doing all this the frog won't stay on top of the lilypad and follow it to the end of the screen, it just stays right where it's at.
danpost danpost

2014/5/20

#
kayuhnjayuhn wrote...
Yes, this is a top-down view, but when I tried doing all this the frog won't stay on top of the lilypad and follow it to the end of the screen, it just stays right where it's at.
You need to show what you tried.
kayuhnjayuhn kayuhnjayuhn

2014/5/20

#
if (isJumping == false)    
       {    
           Actor lily = getOneObjectAtOffset(0, getImage().getWidth()/2-1, Lilypad.class);      
           if (lily != null)     
           {      
               setLocation(lily.getX(), lily.getY());      
           }     
       }
danpost danpost

2014/5/20

#
That code was for if you were not doing a top-down. Try 'getOneObjectAtOffset(0, 0, Lilypad.class);'.
kayuhnjayuhn kayuhnjayuhn

2014/5/20

#
Awesome! Worked great! Thanks!
You need to login to post a reply.