-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
198 lines (188 loc) · 5.95 KB
/
Player.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import javax.swing.ImageIcon;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.Cursor;
import java.awt.Point;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
public class Player extends Thing {
enum CursorType {
MOUSE,
KEYS
}
GamePanel gp;
InputController keys;
ImageIcon im;
Color scoopColor;
Toolkit tk;
CursorType cType;
public boolean clicking = false;
public boolean checking = false;
public boolean trashing = false;
public boolean playing = false;
public boolean exiting = false;
public boolean learning = false;
public boolean retrying = false;
public boolean isColliding = false;
public boolean isRetrying = false;
public boolean isLearning = false;
public boolean isTrashing = false;
public boolean isChecking = false;
public boolean isPlaying = false;
public boolean isExiting = false;
public Player(GamePanel gamepanel, InputController controller, ImageIcon image) {
this.gp = gamepanel;
this.keys = controller;
this.im = image;
this.cType = CursorType.KEYS;
spawn();
}
public void spawn() {
this.x = gp.tileSize * 8;
this.y = gp.tileSize * 8;
this.speed = 5;
}
public void update() {
switch(cType) {
case KEYS:
if(keys.downPressed == true) {
this.y += this.speed;
}
if(keys.upPressed == true) {
this.y -= this.speed;
}
if(keys.rightPressed == true) {
this.x += this.speed;
}
if(keys.leftPressed == true) {
this.x -= this.speed;
}
if(keys.clicked == true && isColliding ) {
clicking = true;
}
else if(keys.clicked == true && isTrashing ) {
//System.out.println( "Trashing" );
trashing = true;
}
else if(keys.clicked == true && isChecking ) {
//System.out.println( "Checking" );
checking = true;
}
else if(keys.clicked == true && isPlaying ) {
playing = true;
}
else if(keys.clicked == true && isLearning ) {
learning = true;
}
else if(keys.clicked == true && isExiting ) {
exiting = true;
}
else if(keys.clicked == true && isRetrying) {
retrying = true;
}
else {
playing = false;
checking = false;
trashing = false;
clicking = false;
exiting = false;
learning = false;
retrying = false;
}
break;
default:
break;
}
}
public void switchCursors() {
if( this.cType == CursorType.KEYS ) {
tk = Toolkit.getDefaultToolkit();
Cursor c = tk.createCustomCursor(im.getImage(), new Point(0, 0), "");
gp.setCursor(c);
this.cType = CursorType.MOUSE;
}
}
public void toKeys() {
this.cType = CursorType.KEYS;
gp.setCursor(Cursor.getDefaultCursor());
}
public void draw(Graphics g) { // Only do this after spawning
im.paintIcon(this.gp, g, this.x, this.y);
}
public void detectCollision(Button b1, Button b2, Button b3) {
// If players x or y when subtracted by an objects x or y is still a number between 0 and the objects size, then it is colliding
if( (this.x - b1.x >= 0 && this.x - b1.x <= 50 && this.y - b1.y >= 0 && this.y - b1.y <= 50) && !keys.clicked) {
isColliding = true;
scoopColor = b1.c;
}
else if ( (this.x - b2.x >= 0 && this.x - b2.x <= 50 && this.y - b2.y >= 0 && this.y - b2.y <= 50) && !keys.clicked) {
isColliding = true;
scoopColor = b2.c;
}
else if ( (this.x - b3.x >= 0 && this.x - b3.x <= 50 && this.y - b3.y >= 0 && this.y - b3.y <= 50) && !keys.clicked) {
isColliding = true;
scoopColor = b3.c;
}
else {
isColliding = false;
}
}
public void detectTrash(Button b1) {
if( (this.x - b1.x >= 0 && this.x - b1.x <= 50 && this.y - b1.y >= 0 && this.y - b1.y <= 50) && !keys.clicked) {
isTrashing = true;
}
else {
isTrashing = false;
}
}
public void detectRetry(Button b1) {
if( (this.x - b1.x >= 0 && this.x - b1.x <= 40 && this.y - b1.y >= 0 && this.y - b1.y <= 40) && !keys.clicked) {
isRetrying = true;
b1.im = b1.litIm;
}
else {
isRetrying = false;
b1.im = b1.unlitIm;
}
}
public void detectCheck(Button b1) {
if( (this.x - b1.x >= 0 && this.x - b1.x <= 50 && this.y - b1.y >= 0 && this.y - b1.y <= 50) && !keys.clicked) {
isChecking = true;
}
else {
isChecking = false;
}
}
public void detectPlay(Button b1) {
if( (this.x - b1.x >= 0 && this.x - b1.x <= 40 && this.y - b1.y >= 0 && this.y - b1.y <= 40) && !keys.clicked ) {
isPlaying = true;
b1.im = b1.litIm;
}
else {
isPlaying = false;
b1.im = b1.unlitIm;
}
}
public void detectExit(Button b1) {
if( ((this.x - b1.x >= 0 && this.x - b1.x <= 40 && this.y - b1.y >= 0 && this.y - b1.y <= 40) && !keys.clicked) || b1.isClicked ) {
isExiting = true;
b1.im = b1.litIm;
}
else {
isExiting = false;
b1.im = b1.unlitIm;
}
}
public void detectInfo(Button b1) {
if( ((this.x - b1.x >= 0 && this.x - b1.x <= 40 && this.y - b1.y >= 0 && this.y - b1.y <= 40) && !keys.clicked) || b1.isClicked ) {
isLearning = true;
b1.im = b1.litIm;
}
else {
isLearning = false;
b1.im = b1.unlitIm;
}
}
}