-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.java
More file actions
44 lines (38 loc) · 1.1 KB
/
Copy pathBullet.java
File metadata and controls
44 lines (38 loc) · 1.1 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
import greenfoot.*;
public class Bullet extends Actor {
private int speed = 7;
private int targetX, targetY;
private double angle;
private Actor owner;
/**
* Konstruktor Bullet.
* @param x Koordinat X tujuan tembakan.
* @param y Koordinat Y tujuan tembakan.
* @param shooter Aktor yang menembakkan peluru ini (biasanya 'this' dari Player).
*/
public Bullet(int x, int y, Actor shooter) {
targetX = x;
targetY = y;
this.owner = shooter;
}
public Actor getActor() {
return owner;
}
public void addedToWorld(World world) {
angle = Math.atan2(targetY - getY(), targetX - getX());
setRotation((int)Math.toDegrees(angle));
}
public void act() {
move(speed);
if (isTouching(Enemy.class)) {
Enemy e = (Enemy)getOneIntersectingObject(Enemy.class);
if (e != null) {
e.takeDamage(50);
}
getWorld().removeObject(this);
}
else if (isAtEdge()) {
getWorld().removeObject(this);
}
}
}