1
4 import java.awt.*;
5
6 public class JRobo
7 {
8 int x; int y;
10 boolean draw; int heading;
13 Graphics robog;
15 JRobo( Graphics g )
17 {
18 x = 200;
19 y = 150;
20 draw = true;
21 heading = 0;
22 robog = g;
23 }
24
25 public void r( int degrees )
27 {
28 heading = ( heading + degrees ) % 360;
29 }
30
31 public void l( int degrees )
33 {
34 heading = ( heading - degrees ) % 360;
35 }
36
37 public void f( int distance )
39 {
40 int dx, dy;
41 dx = ( int ) Math.round( distance * Math.sin( heading * 2 * 3.142 / 360 ) * 500.0/1000 );
42 dy = ( int ) Math.round( distance * - Math.cos( heading * 2 * 3.142 / 360 ) * 500.0/1000 );
43 if ( draw )
44 robog.drawLine( x, y, x + dx, y + dy );
45 x = x + dx;
46 y = y + dy;
47 }
48
49 public void p()
51 {
52 draw = ! draw;
53 }
54
55 }