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

Report as inappropriate.

nccb
nccb presents ...

2012/2/14

Cat Chases Mouse

No description.

7753 views / 27 in the last 7 days

2 votes | 0 in the last 7 days

Tags: with-source

open in greenfoot
Your browser is ignoring the <APPLET> tag.
DutaDuta

2012/2/15

Is the cat's act method just (assuming the dot is Mouse.class): if(!getWorld().getObjects(Mouse.class).isEmpty()) { Mouse mouse = getWorld().getObjects(Mouse.class).get(0); setRotation((int)(180*Math.atan2(mouse.getY()-getY(), mouse.getX()-getX())/Math.PI)); } (Would check myself but for some reason I can't DL the source code)
DutaDuta

2012/2/15

Well actually the line: Mouse mouse = getWorld().getObjects(Mouse.class).get(0); should be: Mouse mouse = (Mouse) getWorld().getObjects(Mouse.class).get(0); (Just realised after I posted >.<)
danpostdanpost

2012/2/15

Actually, instead of 'getWorld().getObjects(Class class)', what was used was 'getObjectsInRange(int range, Class class)' with a range of 1000. Everything else was pretty much on target, except used 'Math.toDegrees(...)' instead of '180 * (...) / Math.PI'.
DutaDuta

2012/2/15

Oh wow, I didn't realise there was a toDegrees method - seems pretty useful :)
nccbnccb

2012/2/15

This scenario is the example for a blog post I've written explaining the principle. I'll put a link up here once I've published it (either this week or next)
nccbnccb

2012/2/16

Ok, I've published the post this scenario refers to, go have a read: http://sinepost.wordpress.com/2012/02/16/theyve-got-atan-you-want-atan2/
yedefeiyedefei

2012/8/6

I've maken a improved version of this(http://www.greenfoot.org/scenarios/5769), may be useful under any situations

Want to leave a comment? You must first log in.

Who likes this?

ITTC idltcaa