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

2012/1/20

Greeps error

MikevP MikevP

2012/1/20

#
I get the folowing error when I run my greeps: java.lang.IndexOutOfBoundsException: Y is out of bounds. It was: 603 and it should have been smaller than: 600 at greenfoot.GreenfootImage.getRGBAt(GreenfootImage.java:571) at greenfoot.GreenfootImage.getColorAt(GreenfootImage.java:528) at Earth.isWater(Earth.java:60) at Creature.move(Creature.java:119) at Greep.act(Greep.java:62) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) This happens when one of the greeps touches the water at the edge of the map (what couses it to leave the world a litle bit). The strange thing is that the exact same code worked perfectly fine at school. My question was how I could solve this problem? This is my code for the Greep.class: import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A Greep is an alien creature that likes to collect tomatoes. * * @author (your name here) * @version 0.1 */ public class Greep extends Creature { // Remember: you cannot extend the Greep's memory. So: // no additional fields (other than final fields) allowed in this class! /** * Default constructor for testing purposes. */ public Greep() { this(null); } /** * Create a Greep with its home space ship. */ public Greep(Ship ship) { super(ship); } /** * Do what a greep's gotta do. */ public void act() { super.act(); // do not delete! leave as first statement in act(). if (carryingTomato()) { if(atShip()) { dropTomato(); } else { WorldEdge(); atWater1(); turnHome(); move(); spit("purple"); } } if (false) { if(atShip()) { dropTomato(); } else { turnHome(); move(); } } else { move(); checkFood(); WorldEdge(); atWater1(); turnToTomatoes(); folowPaint(); } } /** * Is there any food here where we are? If so, try to load some! */ public void checkFood() { // check whether there's a tomato pile here TomatoPile tomatoes = (TomatoPile) getOneIntersectingObject(TomatoPile.class); if(tomatoes != null) { loadTomato(); // Note: this attempts to load a tomato onto *another* Greep. It won't // do anything if we are alone here. } } /** * This method specifies the name of the author (for display on the result board). */ public static String getAuthorName() { return "Anonymous"; // write your name here! } /** * This method specifies the image we want displayed at any time. (No need * to change this for the competition.) */ public String getCurrentImage() { if(carryingTomato()) return "greep-with-food.png"; else return "greep.png"; } public void WorldEdge() { if(atWorldEdge()) { turn(70); } } public void atWater1() { if(atWater()) { turn(70); move(); } } public boolean seeFood() { if (getOneIntersectingObject(TomatoPile.class) == null) { return false; } else { return true; } } public void turnToTomatoes() { if (seeFood()) { int deltaX = getOneIntersectingObject(TomatoPile.class).getX() - getX(); int deltaY = getOneIntersectingObject(TomatoPile.class).getY() - getY(); setRotation((int) (180 * Math.atan2(deltaY, deltaX) / Math.PI)); } } public boolean seePaint() { if (getIntersectingObjects(Paint.class) == null) { return false; } else { return true; } } public void folowPaint() { if (carryingTomato()) { } else{ if (seePaint("purple")) { turnHome(); turn(180); } } } }
danpost danpost

2012/1/22

#
It appears that a 70 degree turn may not be enough, in some instances, to prevent the move() from putting the Greep past the barrier.
Duta Duta

2012/1/22

#
By the way, you're not allowed to ask for help with Greeps on the discussion boards - its pretty much the only rule
MikevP MikevP

2012/1/22

#
I know sorry. My teacher send me to this forum because he couldn't awnser my question.
davmac davmac

2012/1/22

#
What version of Greenfoot are you using at school, and what version at home? (i.e. are they different versions).
MikevP MikevP

2012/1/22

#
As far as I know the latest version at both locations. Where can I find the unedited source code for the greeps?? Maybe I used diferent source codes.
davmac davmac

2012/1/22

#
The official version is here.
MikevP MikevP

2012/1/22

#
Thanks a lot. It is working now.
You need to login to post a reply.