-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ricardo.java
86 lines (73 loc) · 1.83 KB
/
Ricardo.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
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Ricardo extends Asteroid{
private int dx;
private int dy;
private List<RicardoMissile> missiles;
public Random rand = new Random();
private int MOVE_SPEED = 5;
public int life;
public int maxlife;
public Boolean ricardoGoRight = false;
public Boolean ricardoGoLeft = false;
public Ricardo(int x){
super(x, 25, 50);
this.life = 50;
this.maxlife = 50;
this.width = 275;
this.height = 275;
initRicardo();
}
private void initRicardo(){
missiles = new ArrayList<>();
loadImage("img/ricardo.gif");
}
@Override
public int maxLife(){
return maxlife;
}
public List<RicardoMissile> getMissiles(){
return missiles;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public void removeLife(int damage){
if(life > 0){
life -= damage;
}
}
@Override
public int getLife() {
return life;
}
public boolean isRicardo(){
return true;
}
public void fire(){
int random = rand.nextInt(40);
if(random == 10){
missiles.add(new RicardoMissile(x + width / 2, y + height));
}
}
public void move(){
int random = rand.nextInt(20);
if(random == 6 && x < 1100 || ricardoGoRight && x < 1100){
ricardoGoRight = true;
ricardoGoLeft = false;
x += MOVE_SPEED;
}
if(random == 15 && x > 0|| ricardoGoLeft && x > 0){
ricardoGoLeft = true;
ricardoGoRight = false;
x -= MOVE_SPEED;
}
if(y > 1100 || x > 1400){
visible = false;
}
}
}