-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTarget.pde
More file actions
65 lines (53 loc) · 1.16 KB
/
Target.pde
File metadata and controls
65 lines (53 loc) · 1.16 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
public class Target
{
Vec pos = new Vec();
Vec vel = new Vec();
float durchmesser;
Target(Vec spielerPos, float durch)
{
durchmesser = durch;
setPos(spielerPos, 0);
}
public void setPos(Vec spos, int level)
{
if(spos.x > width/2)
{
pos.x = random((float)durchmesser,(float)(width / 2 - durchmesser));
}
else
{
pos.x = random((float)(width / 2 + durchmesser),(float)(width - durchmesser) );
}
pos.y = random((float)durchmesser,(float)(height - durchmesser));
if(level >= 20)
{
vel.x = random(-50,50);
vel.y = random(-50,50);
}
else
{
vel.x = 0;
vel.y = 0;
}
}
public void update(float dt)
{
pos.x -= vel.x * dt;
if(pos.x - durchmesser / 2 <= 0 || pos.x + durchmesser / 2 >= width)
{
vel.x *= -1;
}
pos.y += vel.y * dt;
if(pos.y - durchmesser / 2 <= 0 || pos.y + durchmesser / 2 >= height)
{
vel.y *= -1;
}
}
public void show()
{
fill(131,131,131);
strokeWeight(2.0);
stroke(222, 222, 221);
ellipse(pos.x, pos.y, durchmesser, durchmesser);
}
}