-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointUpActor.java
More file actions
executable file
·85 lines (72 loc) · 2.04 KB
/
Copy pathPointUpActor.java
File metadata and controls
executable file
·85 lines (72 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.lang.Math;
/**
* Write a description of class PointUp here.
*
* @author (your name)
* @version (a version number or a date)
*/
public abstract class PointUpActor extends Actor
{
private int rotation = 0;
/**
* Act - do whatever the PointUp wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public abstract void act();
public Background world;
@Override
public void setRotation(int rotation)
{
this.rotation = rotation;
}
@Override
public int getRotation()
{
return this.rotation;
}
@Override
public void move(int distance)
{
super.setRotation(this.rotation);
super.move(distance);
super.setRotation(0);
}
@Override
public void turnTowards(int x,int y)
{
//This routine does not act as desired super turn towards does not set rotation
//right away you will have to do some arc tan stuff or something
//System.out.println("Turn Towards " + x + " " + y);
//super.turnTowards(x,y);
//this.rotation = super.getRotation();
double deltaX = x - getX();
double deltaY = y - getY();
double degrees = Math.atan2(deltaY,deltaX) * 180.0 / Math.PI;
this.rotation = (int)degrees;
while(this.rotation < 0)
{
this.rotation+=360;
}
this.rotation = this.rotation % 360;
//System.out.println("Degrees " + this.rotation);
super.setRotation(0);
}
@Override
public void turn(int amount)
{
rotation += amount;
while(rotation < 0)
{
rotation += 360;
}
if (rotation >= 360)
{
rotation = rotation % 360;
}
}
@Override
public void addedToWorld(World world) {
this.world = (Background) world;
}
}