-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShot.java
87 lines (73 loc) · 1.78 KB
/
Shot.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
import java.awt.*;
public class Shot implements Runnable {
private int vitezaLoviturii = 10;
private int LATIMEA_LOVITURII = 12;
private int INALTIMEA_LOVITURII = 23;
private int x = 0;
private int shotHeight = 0;
boolean stareLovitura = true;
private Image imagineLovitura = new javax.swing.ImageIcon("supermanshot.gif").getImage();
Armata armata = null;
Boss boss = null;
SpaceInvaders spaceInvaders = null;
public Shot(int xVal, int yVal, Armata aa, SpaceInvaders si, Boss seful) {
x = xVal;
shotHeight = yVal;
armata = aa;
boss = seful;
spaceInvaders = si;
Thread thread = new Thread(this);
thread.start();
}
private boolean mutaLovitura() {
if(armata.verificaLovitura(x, shotHeight)) {
// Am lovit ceva din armata
System.out.println("Am impuscat un extraterestru!");
stareLovitura = false;
return true;
}
if(boss.bossLovit(x, shotHeight)) {
stareLovitura = false;
return true;
}
shotHeight -= 2;
// Verificam daca am iesit in afara ecranului
if(shotHeight < 0) {
stareLovitura = false;
return true;
}
return false;
}
/**
* Desenarea loviturii propriu zise
*/
public void drawShot(Graphics g) {
if(stareLovitura) {
g.drawImage(imagineLovitura, x, shotHeight, spaceInvaders);
g.setColor(Color.green);
} else {
g.setColor(Color.red);
}
}
public boolean getStareLovitura() {
return stareLovitura;
}
/**
* Thread-ul care misca shot-ul
*/
public void run() {
while(true) {
try {
Thread.sleep(vitezaLoviturii);
} catch(InterruptedException ie) {
// nu facem din nou ceva
}
// Daca folosim moveshot() facand abstractie de shotState vom putea folosi aceeasi
// lovitura pentru a omora toti extraterestrii din drumul ei
//mutaLovitura();
if(mutaLovitura()) {
break;
}
}
}
}