-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ramp.java
71 lines (59 loc) · 1.71 KB
/
Ramp.java
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Class representing the ramp
*
* @author Austin
* @version 0
*/
public class Ramp extends Actor {
private int height = 325;
private int length = 575;
/**
* Updates the image
*/
public void act() {
createImage();
}
/**
* Displays the triangle with length and height to the screen
*/
public void createImage() {
// Vertices of triangle
int[] x = new int[]{0, 0, length};
int[] y = new int[]{0, height, height};
GreenfootImage image = new GreenfootImage(length, height);
// Draw the triangle to the screen
image.setColor(new Color(57, 181, 74, 150));
image.fillPolygon(x, y, 3);
setImage(image);
setLocation(length / 2, 800 - (height / 2 + 50));
}
/**
* Adds the ramp to the world at the suitable location
*
* @param world The world to add the ramp to
*/
public void addToWorld(World world) {
world.addObject(this, length / 2, 800 - (height / 2 + 50));
}
/**
* Sets the base length of the triangle
*
* @param length The length to set the ramp to
*/
public void setLength(int length) {
this.length = length;
}
/**
* Sets the height of the triangle
*
* @param height The height to set the ramp to
*/
public void setHeight(int height) {
this.height = height;
}
// Getters
public int getHeight() { return height; }
public int getLength() { return length; }
public double getAngle() { return Math.atan2(height, length); }
}