-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaddle.java
More file actions
93 lines (84 loc) · 1.86 KB
/
Paddle.java
File metadata and controls
93 lines (84 loc) · 1.86 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public class Paddle extends Rectangle
{
Image myImage;
int dx;
int dy;
int speed;
int health;
int startX;
int startY;
int livesRemaining;
Rectangle left;
Rectangle right;
Rectangle top;
Rectangle bottom;
public Paddle(int x, int y, int width, int height, int s, int h, Image img)
{
super(x,y,width,height);
startX = x;
startY = y;
speed = s;
health = h;
myImage = img;
dx = 0;
dy = 0;
left = new Rectangle(x,y,1,110);
right = new Rectangle(x+110,y,1,110);
top = new Rectangle(x,y,15,1);
bottom = new Rectangle(x,y+15,15,1);
}
public Image getImage()
{ return myImage; }
public double getX()
{ return x; }
public void setSpeed(int s)
{ speed = s; }
public void move()
{
x+=dx;
if(x>1190)
x=x-dx;
if(x<0)
x=x-dx;
}
public void left()
{ dx=-speed; }
public void stopLeft()
{ dx=0; }
public void right()
{ dx=speed; }
public void stopRight()
{ dx=0; }
public void up()
{ dy=-speed; }
public void stopUp()
{ dy=0; }
public void down()
{ dy=speed; }
public void stopDown()
{ dy=0; }
public void resetGame()
{
x=startX;
y=startY;
}
public String intersectsString(Rectangle other)
{
boolean b = intersects(other);
if(b==false)
return "NO";
if(other.intersects(top))
return "TOP";
if(other.intersects(bottom))
return "BOTTOM";
if(other.intersects(left))
return "LEFT";
if(other.intersects(right))
return "RIGHT";
return "INSIDE";
}
}