-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphicObject.java
More file actions
92 lines (83 loc) · 2.07 KB
/
GraphicObject.java
File metadata and controls
92 lines (83 loc) · 2.07 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
85
86
87
88
89
90
91
92
import processing.core.PImage;
/**
* GraphicObject is a class that represents a drawable object in the game.
*/
public class GraphicObject extends Object implements Drawable {
/**
* PImage object that represents the image of this object
*/
protected PImage image;
/**
* ToySaga PApplet object where the button will be displayed
*/
protected static ToySaga toySaga;
/**
* x-position of the center of this object
*/
protected int x;
/**
* y-position of the center of this object
*/
protected int y;
/**
* Constructs a new GraphicObject with a specific filename
*
* @param filename name of the file that contains the image of this object
*/
public GraphicObject(String filename) {
image = toySaga.loadImage(filename);
x = 400; // center of the screen
y = 300; // center of the screen
}
/**
* Constructs a new GraphicObject with a specific filename, x and y position
*
* @param filename name of the file that contains the image of this object
* @param x x-position of the center of this object
* @param y y-position of the center of this object
*/
public GraphicObject(String filename, int x, int y) {
image = toySaga.loadImage(filename);
this.x = x;
this.y = y;
}
/**
* Draws the object on the screen
*
* @param filename name of the file that contains the image of this object
*/
public void setImage(String filename) {
image = toySaga.loadImage(filename);
}
/**
* Moves the object to a specific x and y position
*/
@Override
public void draw() {
toySaga.image(image, x, y);
}
/**
* returns the x position of the object
*
* @return x position of the object
*/
public int getX() {
return x;
}
/**
* returns the y position of the object
*
* @return y position of the object
*/
public int getY() {
return y;
}
/**
* Sets the x position of the object
*
* @param toySaga x position of the object
*/
public static void setProcessing(ToySaga toySaga) {
GraphicObject.toySaga = toySaga;
}
}