Sorry I'm here again, but I have encountered a few more errors:
The first is when I want to make my car drive without having to hold down a key all of the time.
so far I have:
( I haven't finished it as it does not work)
My second problem sort of continues my previous post, but it is about detecting objects in a range from an actor. I want to make my policemen start following a robber once it comes near...
Sorry to go on, but my third and final problem is where I want to 'drag' an object but not with my mouse. I want my car to move with a money bag once they are touching, and then drop it off in the hide-out.
Basically I want to extend my method for driving to the money bag, but only when the money bag and the car are touching.
So that
if the car is touching the money bag,
drive with keys
until
if the money bag is touching the hideout,
where it will stop driving with keys,
leaving the moneybag in the hideout.
Thanks again, and just to reiterate that I am new to greenfoot and java, so I am looking for simple, easy code.
/** * Control the car with arrow keys and change image */ public void driveWithKeys() { if ("left".equals(key)) { setRotation(270); move(4); setImage ("crook car left.png"); } if("space".equals(key)) { move(0); } accelerateWithTab(); } /** * Car accelerates with tab held down */ public void accelerateWithTab() { if (Greenfoot.isKeyDown ("tab")) { move (12); } }
public boolean isBaddyNear() { Baddies Baddies; Baddies = (Baddies)getObjectsInRange(1200, Baddies.class); if(Baddies != null) { move (3); } }