-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBallEvent.java
67 lines (59 loc) · 1.73 KB
/
BallEvent.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
/**
* Write a description of class Ball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class BallEvent extends Element implements Runnable
{
private double distance = 20;
private double xPlus = 10;
private double yPlus = 10;
private double points;
private boolean finished;
private Spell origin;
public BallEvent(Spell s,double x,double y)
{
super("ball_in_action");
setX(s.getStartX());
setY(s.getStartY());
origin = s;
double ll = Math.sqrt((x-getStartX())*(x-getStartX())+(y-getStartY())*(y-getStartY()));
xPlus = (getStartX()-x)/ll*10*(-1);
yPlus = (getStartY()-y)/ll*10*(-1);
finished = false;
}
/*
* This method manages the triggering event of the spell
*/
public void run()
{
int l = 0;
int stopTime = (int) Math.round(distance*1000/origin.getSpeed());
while (l < distance && Element.checkX(getStartX()) && Element.checkY(getStartY() ))
{
if (l>5)
{
try
{
Character ch = Show.bf.findTarget(getStartX(),getStartY());
ch.decreaseStrength(origin.getPoints());
break;
}
catch (NullPointerException e)
{
//e.printStackTrace();
}
}
setX((int) Math.round(getStartX() + xPlus));
setY((int) Math.round(getStartY() + yPlus));
Element.stopForWhile(stopTime);
l++;
}
finished = true;
}
public boolean notFinished()
{
return !finished;
}
}