-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSprite.pde
139 lines (112 loc) · 2.31 KB
/
Sprite.pde
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
public class Sprite{
PImage image;
float center_x, center_y;
float change_x, change_y;
int w, h;
int size_x,size_y;
boolean faceto = false;
boolean fly = false;
public Sprite(String filename, int size_x, int size_y, float x, float y) {
image = loadImage(filename);
w = size_x;
h = size_y;
center_x = x;
center_y = y;
change_x = 0;
change_y = 0;
}
public Sprite(String filename, int size_x, int size_y) {
this(filename, size_x, size_y, 0, 0);
}
public Sprite(PImage img, int size_x, int size_y, float x, float y) {
image = img;
w = size_x;
h = size_y;
center_x = x;
center_y = y;
change_x = 0;
change_y = 0;
}
public Sprite(PImage img, int size_x, int size_y) {
image = img;
w = size_x;
h = size_y;
center_x = 0;
center_y = 0;
change_x = 0;
change_y = 0;
}
public void display() {
pushMatrix();
image.resize(w,h);
translate(center_x, center_y);
if (change_x < 0 || (change_x == 0 && faceto == true)) {
scale(-1, 1);
faceto = true;
}
if ((change_x > 0) || (change_x == 0 && faceto == false)) {
scale(1, 1);
faceto = false;
}
image(image, 0, 0);
popMatrix();
}
public void update() {
center_x += change_x;
center_y += change_y;
}
void setCenter_x(float x) {
center_x = x;
}
float getCenter_x() {
return center_x;
}
void setCenter_y(float y) {
center_y = y;
}
float getCenter_y() {
return center_y;
}
void setLeft(float left) {
center_x = left + w / 2;
}
float getLeft() {
return center_x - w / 2;
}
void setRight(float right) {
center_x = right - w / 2;
}
float getRight(){
return center_x + w/2 ;
}
void setTop(float top) {
center_y = top + h / 2;
}
float getTop() {
return center_y - h/2;
}
void setBottom(float bottom) {
center_y = bottom - h / 2;
}
float getBottom() {
return center_y + h / 2;
}
float getChangeX() {
return change_x;
}
void setChangeX(float cx) {
change_x = cx;
}
float getChangeY() {
return change_y;
}
void setChangeY(float cy) {
change_y = cy;
}
public PImage getImage() {
return image;
}
public void setImage(PImage image) {
this.image = image;
}
}