CAN SOMEGIVE ME A CODE TO PIC ITEMS IN GREEN FOOT. PLS I HAVE BEEN WORKING ON THIS FOR AGES AND IT WILL NOT WORK.
//Global boolean picked=false; //Act method if(isTouching(Gun.class) && Greenfoot.isKeyDown("p")) picked=true; else if(Greenfoot.isKeyDown("d")) picked=false; if(picked) { Gun gun = (Gun)getWorld().getObjects(Gun.class).get(0); gun.setLocation(getX(), getY()); gun.setRotation(getRotation());//optinal....not required according to what you asked for }
private Gun gun = null;
if (Greenfoot.isKeyDown("p")) gun = (Gun)getOneIntersectingObject(Gun.class);
if (gun != null) gun.setLocation(getX(), getY());
if (gun.getWorld() == null) gun = null;
public void shoot() { getWorld().addObject(new Bullet(getRotation()), getX(), getY()); shotsRemaining--; if (shotsRemaining == 0) getWorld().removeObject(this); }
if (gun != null && Greenfoot.isKeyDown("space")) gun.shoot();
if (gun != null) gun.setLocation(getX(), getY());