forked from udohi/GameArena
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFence.java
More file actions
80 lines (69 loc) · 1.44 KB
/
Fence.java
File metadata and controls
80 lines (69 loc) · 1.44 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
import java.util.Random;
/**
* This class extends the Rectangle class.
*
* The Fence class exists of a Rectangle (and a triangle - planned) to create a picket-fence like shape, over which the user should jump.
*
* @see Rectangle
* @see Sheep
*
* @author Adam Bogg, Harry Almond
*/
public class Fence extends Rectangle
{
private int x;
private int y;
private int w;
private int h;
private int speed = 10;
private int numFences = 0;
Random rand = new Random();
Boolean reached = false;
public Fence(int x, int y, int w, int h, java.lang.String col, GameArena arena)
{
super(x, y, w, h, col);
// arena.addRectangle(r);
// Ball post = new Ball(x, y-75, 17, "YELLOW");
// arena.addBall(post);
}
/*
public int getXPosition()
{
return x;
}
public void setXPosition(int newX)
{
x = newX;
}
*/
public int getSpeed()
{
return speed;
}
public void setSpeed(int newS)
{
speed = newS;
}
private int increment = 0;
public void move()
{
setXPosition(getXPosition() - getSpeed());
if (getXPosition() < (0 - (getWidth() / 2)))
setXPosition(1350);
increment++;
if (increment == 150 && getSpeed() < 30)
{
setSpeed(getSpeed() + 1);
increment = 0;
}
if (getSpeed() >= 30)
reached = true;
if (getXPosition() > 1300 && reached)
setSpeed(rand.nextInt(25) + 10);
}
public void collision(Sheep s)
{
if (this.intersects(s.collisionBox) || this.intersects(s.collisionBoxLegs))
Driver.arena.fail();
}
}