-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBandit.java
More file actions
127 lines (107 loc) · 3.5 KB
/
Bandit.java
File metadata and controls
127 lines (107 loc) · 3.5 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
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
124
125
126
127
import java.util.Random;
public class Bandit extends Enemy{
public Bandit(GamePanel p, int xPos, int yPos, Car bat, int enemy, int speed) {
panel = p;
// dimension = panel.getSize();
backgroundColour = panel.getBackground ();
width = 58;
height = 52;
random = new Random();
x = xPos;
y = yPos;
enemy_num= enemy;
//setLocation();
dx = speed; // move side to side
dy = speed; // would like to drop down after hitting wall
this.bat = bat;
this.bullet= null;
this.oppBullet= null;
soundManager = SoundManager.getInstance();
imageUp= ImageManager.loadImage ("images/banditUp.png");
imageDown= ImageManager.loadImage ("images/banditDown.png");
imageLeft= ImageManager.loadImage ("images/banditLeft.png");
imageRight= ImageManager.loadImage ("images/banditRight.png");
alienImage = imageUp;
imageFX1= null;
rand= random.nextInt(4);
type= 1;
}
// public void setLocation(){
// int panelWidth = panel.getWidth();
// int panelHeight= panel.getHeight();
// x = random.nextInt (panelWidth - width);
// y = random.nextInt(panelHeight- height);
// dx+= 2;
// };
public void move() {
int height = panel.getHeight();
int width= panel.getWidth();
boolean CarCollision = collideWithPlayer();
boolean BulletCollision= collideWithBullet();
checkBounds();
if (!panel.isVisible ()) return;
long now= System.currentTimeMillis();
if(now - lastShotTime>= shotDelay){
shoot();
lastShotTime= now;
shotDelay= 2000+ random.nextInt(1000);
}
if(rand== 0){
alienImage= imageUp;
y-=dy;
}
else if(rand== 1){
alienImage= imageDown;
y+=dy;
}
else if(rand== 2){
alienImage= imageLeft;
x-= dx;
}
else if(rand==3){
alienImage= imageRight;
x+= dx;
}
rand1= random.nextInt(10);
if(rand1>7)
rand= random.nextInt(4);
// if(this.side){
// if(x>= width - this.width){
// y+= dy;
// this.side= false;
// }
// x+= dx;
// }
// else if(!this.side){
// x-= dx;
// if(x<= 0){
// y+= dy;
// this.side= true;
// }
// }
if (CarCollision) {
soundManager.playClip("playerHit", false);
panel.loseLife(1);
if(panel.getLifeTotal()<= 0){
soundManager.playClip("death", false);
panel.destroyed(bat.getX(), bat.getY(), bat.getHeight(), bat.getWidth());
panel.endGame();
return;
}
// setLocation();
panel.killEnemy(x, y, this.height, this.width, 0, enemy_num, 1);
panel.destroyed(bat.getX(), bat.getY(), bat.getHeight(), bat.getWidth());
}
// if(BulletCollision){
// soundManager.playClip("hit", false);
// // setLocation();
// dx= 0;
// dy= 0;
// panel.addPoints(1);
// // bullet.erase();
// bullet= null;
// panel.deleteBullet();
// panel.killEnemy(x, y, this.height, this.width, 0, enemy_num, 0);
// }
}
}