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

Report as inappropriate.

danpost
danpost presents ...

2013/10/11

Dual-method Locator

Move the mouse around the window and watch the arrows point toward it using the closest 45 or 90 degree angle toward the mouse.

The code is quite simple and can be used for following an actor.

Clicking the mouse will toggle between 8-way and 4-way locating.

3489 views / 9 in the last 7 days

3 votes | 0 in the last 7 days

Tags: mouse demo with-source danpost locating eight_way following turntowards four_way

This scenario is a member of: Demos by danpost


open in greenfoot
Your browser does not support the canvas tag.
KartoffelbrotKartoffelbrot

2013/10/11

public void turnToMouse(){ MouseInfo m = Greenfoot.getMouseInfo(); turnTowards(m.getX(), m.getY()); double r = getRotation()/45; int rI = (int) r; if(r-rI>0.5) rI++; setRotation(rI); } Did you make it that way? }
KartoffelbrotKartoffelbrot

2013/10/11

I mean setRotation(rI+45); in line 8
danpostdanpost

2013/10/11

@Kartoffelbrot, the code is open source.
KartoffelbrotKartoffelbrot

2013/10/11

Oh, I didn't see it.
A new version of this scenario was uploaded on Fri Oct 11 17:58:22 UTC 2013 Got rid of the Arrow class and used unnamed Actors. Also change the way they were added into the world. Did not change how their behaviour was rendered.
A new version of this scenario was uploaded on 2020-11-02 19:51:06 UTC

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

Who likes this?

AussieDauz data17 Draymothisk