-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShip.java
123 lines (90 loc) · 4.24 KB
/
Ship.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
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
117
118
119
120
121
122
123
import java.awt.Color;
import java.awt.Graphics;
public class Ship{
private int x;
private int y;
private int width;
private int height;
private Color blue;
private Color red;
private Color black;
static public int lives = 3;
public Ship(int x, int y){
this.x = x;
this.y = y;
this.width = 70;
this.height = 125;
this.blue = new Color(207, 229, 232);
this.red = new Color(197, 17, 17);
this.black = new Color(0, 0, 0);
}
public void drawMe(Graphics g){
g.setColor(black);
g.fillOval(x-25,y-40,width,height);
g.setColor(red);
int[] xdata1 =
{ x+(85 -100)/2, x+(85 -100)/2, x+(86 -100)/2, x+(117-100)/2, x+(191-100)/2, x+(216-100)/2, x+(226-100)/2, x+(223-100)/2,
x+(209-100)/2, x+(178-100)/2, x+(144-100)/2, x+(86 -100)/2, x+(145-100)/2, x+(180-100)/2, x+(208-100)/2, x+(192-100)/2,
x+(169-100)/2, x+(148-100)/2, x+(120-100)/2, x+(95 -100)/2, x+(74 -100)/2, x+(63 -100)/2, x+(52 -100)/2, x+(49 -100)/2,
x+(49 -100)/2, x+(52 -100)/2, x+(56 -100)/2, x+(71 -100)/2, x+(101-100)/2, x+(114-100)/2, x+(114-100)/2, x+(151-100)/2,
x+(153-100)/2, x+(163-100)/2, x+(182-100)/2, x+(193-100)/2, x+(197-100)/2, x+(198-100)/2, x+(207-100)/2, x+(205-100)/2,
x+(216-100)/2, x+(227-100)/2, x+(222-100)/2, x+(206-100)/2, x+(168-100)/2, x+(149-100)/2, x+(114-100)/2, x+(96 -100)/2,
x+(75 -100)/2, x+(64 -100)/2, x+(52 -100)/2, x+(49 -100)/2, x+(27 -100)/2, x+(18 -100)/2, x+(18 -100)/2, x+(22 -100)/2,
x+(25 -100)/2, x+(39 -100)/2, x+(50 -100)/2, x+(47 -100)/2, x+(54 -100)/2, x+(68 -100)/2, x+(95 -100)/2, x+(126-100)/2,
x+(149-100)/2, x+(168-100)/2, x+(203-100)/2, x+(224-100)/2, x+(225-100)/2, x+(217-100)/2, x+(205-100)/2};
int[] ydata1 =
{ y+(215-250)/2, y+(215-250)/2, y+(263-250)/2, y+(281-250)/2, y+(281-250)/2, y+(266-250)/2, y+(246-250)/2, y+(227-250)/2,
y+(216-250)/2, y+(205-250)/2, y+(204-250)/2, y+(217-250)/2, y+(205-250)/2, y+(207-250)/2, y+(215-250)/2, y+(194-250)/2,
y+(168-250)/2, y+(161-250)/2, y+(159-250)/2, y+(160-250)/2, y+(171-250)/2, y+(189-250)/2, y+(234-250)/2, y+(272-250)/2,
y+(339-250)/2, y+(376-250)/2, y+(415-250)/2, y+(429-250)/2, y+(435-250)/2, y+(421-250)/2, y+(394-250)/2, y+(394-250)/2,
y+(416-250)/2, y+(435-250)/2, y+(435-250)/2, y+(421-250)/2, y+(403-250)/2, y+(386-250)/2, y+(350-250)/2, y+(274-250)/2,
y+(266-250)/2, y+(247-250)/2, y+(225-250)/2, y+(215-250)/2, y+(168-250)/2, y+(160-250)/2, y+(160-250)/2, y+(160-250)/2,
y+(172-250)/2, y+(191-250)/2, y+(232-250)/2, y+(268-250)/2, y+(269-250)/2, y+(303-250)/2, y+(337-250)/2, y+(362-250)/2,
y+(384-250)/2, y+(388-250)/2, y+(388-250)/2, y+(272-250)/2, y+(223-250)/2, y+(181-250)/2, y+(160-250)/2, y+(161-250)/2,
y+(160-250)/2, y+(168-250)/2, y+(213-250)/2, y+(229-250)/2, y+(249-250)/2, y+(266-250)/2, y+(275-250)/2};
g.fillPolygon(xdata1, ydata1, 71);
g.setColor(blue);
int[] xdata3 =
{ x+(85 -100)/2, x+(85 -100)/2, x+(86 -100)/2, x+(117-100)/2, x+(191-100)/2, x+(216-100)/2, x+(226-100)/2, x+(223-100)/2,
x+(209-100)/2, x+(178-100)/2, x+(144-100)/2};
int[] ydata4 =
{ y+(215-250)/2, y+(215-250)/2, y+(263-250)/2, y+(281-250)/2, y+(281-250)/2, y+(266-250)/2, y+(246-250)/2, y+(227-250)/2,
y+(216-250)/2, y+(205-250)/2, y+(204-250)/2};
g.fillPolygon(xdata3, ydata4, 11);
}
public void moveUp(){
y-=10;
}
public void moveDown(){
y+=10;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
// TODO: add method for reset position
public void reset(int x, int y){
this.x= x;
this.y= y;
}
public void checkCollision(Enemy e){
if( e.isAlive() ){
int sX = x-25;
int sY = y-40;
int sWidth = width;
int sHeight = height;
int tX = e.getX();
int tY = e.getY();
int tWidth = e.getWidth();
int tHeight = e.getHeight();
if( sX+sWidth >= tX && sX <= tX + tWidth &&
sY+sHeight >= tY && sY <= tY + tHeight ){
//System.out.println("Collision");
e.kill(); //e. because in enemy class
lives--;
}
}
}
}