-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerUp.java
More file actions
82 lines (58 loc) · 1.79 KB
/
PowerUp.java
File metadata and controls
82 lines (58 loc) · 1.79 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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.Image;
public abstract class PowerUp{
protected GamePanel panel;
protected int x;
protected int y;
protected int width;
protected int height;
protected Ellipse2D.Double head; // ellipse drawn for face
protected Color backgroundColour;
protected Car bat;
protected SoundManager soundManager;
protected Image alienImage;
public void draw(Graphics2D g2, double cameraX, double cameraY) {
int drawX = (int)(x - cameraX);
int drawY = (int)(y - cameraY);
g2.drawImage(alienImage, drawX, drawY, width, height, null);
}
public void erase() {
Graphics g = panel.getGraphics();
Graphics2D g2 = (Graphics2D) g;
g2.setColor (backgroundColour);
g2.fill (new Ellipse2D.Double (x, y, width, height));
g2.setColor(backgroundColour);
g2.draw(new Ellipse2D.Double (x, y, width, height));
g.dispose();
}
public void move() {
boolean CarCollision = collidesWithCar();
if (!panel.isVisible ()) return;
if (CarCollision) {
soundManager.playClip("pickup", false);
if(panel.getLifeTotal()>= 5){
panel.addPoints(5);
}else{
panel.addLife(2);
}
}
}
public Rectangle2D.Double getBoundingRectangle() {
return new Rectangle2D.Double (x, y, width, height);
}
public boolean collidesWithCar() {
Rectangle2D.Double myRect = getBoundingRectangle();
Rectangle2D.Double batRect = bat.getBoundingRectangle();
return myRect.intersects(batRect);
}
public int getX(){
return this.x;
}
public int getY(){
return this.y;
}
}