-
Notifications
You must be signed in to change notification settings - Fork 0
/
Puck.java
60 lines (56 loc) · 1.38 KB
/
Puck.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
import java.awt.Image;
import java.awt.Rectangle;
/* ûÁÊÂÁ */
class Puck extends MovableSprite {
/*
* @_ps - ÈÒÁÎÉÌÉÝÅ ÛÁÊÂ, Ä×ÕÎÁÐÒÁ×ÌÅÎÁÑ ÁÓÓÏÃÉÁÃÑ
*/
private PuckSupply _ps;
public Puck(PlayField pf, PuckSupply ps, Image img) {
super(
pf,
img,
(new Rectangle(pf.getWidth()/2, pf.getHeight()/2, img.getWidth(pf), img.getHeight(pf))),
90,
6);
_isMoving = true;
_ps = ps;
}
public void move() {
if (!_isMoving)
return;
Rectangle b = _pf.getBoundary();
_prevPos = _pos;
_pos.translate(_v.getSpeedX(), _v.getSpeedY());
/* OÂÒÁÂÏÔËÁ ÓÏÕÄÁÒÅÎÉÑ ÓÏ ÓÔÅÎÁÍÉ, ÐÏÌÏÍ É ÐÏÔÏÌËÏÍ. */
if (_pos.x <= b.x) {
_pos.x = b.x;
_v.reverseX();
} else if (_pos.x + _pos.width >= b.width + b.x) {
_pos.x = b.x + b.width - _pos.width;
_v.reverseX();
} else if (_pos.y <= b.y) {
_pos.y = b.y;
_v.reverseY();
} else if (_pos.y + _pos.height > b.y + b.height) {
/* ûÁÊÂÁ ÕÐÁÌÁ ÎÁ ÐÏÌ */
_isDead = true;
if (_ps.size() == 0) {
_pf.getMatch().loose();
} else {
_pf.addSprite(_ps.get());
}
}
/* ïÂÒÁÂÏÔËÁ ÓÏÕÄÁÒÅÎÉÑ Ó ÄÒÕÇÉÍÉ ÓÐÒÁÊÔÁÍÉ */
if (collideWith() != null) {
_pos = _prevPos;
collideInto(collideWith());
}
}
public void collideInto(Sprite s) {
s.hitBy(this);
}
public void hitBy(Puck p) {
;
}
}