-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPokeball.java
More file actions
116 lines (97 loc) · 2.75 KB
/
Copy pathPokeball.java
File metadata and controls
116 lines (97 loc) · 2.75 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.awt.image.BufferedImage;
import java.awt.*;
import javax.swing.Timer;
import java.awt.event.*;
/**
* Pokeball object that player uses to catch pokemon.
*
* @Jonathan ke
* @8/13/2019
*/
public class Pokeball implements ActionListener{
//location fields
private final int yFin;
private int x;
private int y;
//animation fields
private int initVal;
private int time = 1;
private int direction;
private Timer t;
//accessor fields
private boolean ballStopped = false;
//image
private BufferedImage img = SpriteSheetCutter.getImage("pokeball");
//collision class
private Collision collision;
public Pokeball(int initX, int initY, int direction, Collision c){
this.direction = direction;
collision = c;
//check for direction of throw to set pokeball fields
if (direction == Player.NORTH){
yFin = initY-44;
x = initX+9;
initVal = initY+8;
} else if (direction == Player.SOUTH){
yFin = initY+32;
x = initX + 9;
initVal = initY + 20;
} else if (direction == Player.EAST){
yFin = initY;
x = initX;
initVal = initY + 16;
} else {
//ball thrown west
yFin = initY;
x = initX + 20;
initVal = initY + 16;
}
t = new Timer(100, this);
t.start();
}
//animation of pokeball, used parabolic arcs to best approximate a throw
@Override
public void actionPerformed(ActionEvent e){
if (direction == Player.WEST){
x += 4;
y = initVal - (int)(time*15.5) + 2*time*time;
} else if (direction == Player.EAST){
x -= 4;
y = initVal - (int)(time*15.5) + 2*time*time;
} else if (direction == Player.NORTH){
y = initVal - time*20 + 2*time*time;
} else {
y = initVal - time*12 + 2*time*time;
}
time += 1;
if (time == 9){
t.stop();
ballStopped = true;
Actor pok = collision.checkPokeball(this);
if (pok != null){
pok.flash();
}
}
}
//graphics accessor methods
public int getX(){
return x;
}
public int getY(){
return y;
}
public BufferedImage getBall(){
return img;
}
//accessor to check whether ball is still moving
public boolean stopped(){
return ballStopped;
}
//hitbox accessor methods
public Rectangle getHitBox(){
return new Rectangle(x+1, y, 12, 12);
}
public int getHitBoxY(){
return yFin;
}
}