-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ship.pde
45 lines (39 loc) · 1.26 KB
/
Ship.pde
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
class Ship {
int xPos;
int yPos;
int partWidth;
float speed;
Ship(int x, int y) {
xPos = x;
yPos = y;
partWidth = 10;
speed = 20;
}
void display() {
rectMode(CORNERS);
noStroke();
colorMode(RGB, 255);
fill(255);
rect(xPos, yPos, xPos + partWidth, yPos - 3 * partWidth);
rect(xPos + partWidth, yPos - partWidth, xPos + 2 * partWidth, yPos - 4 * partWidth);
rect(xPos + 2 * partWidth, yPos - 3 * partWidth, xPos + 4 * partWidth, yPos - 5 * partWidth);
rect(xPos + 4 * partWidth, yPos - partWidth, xPos + 5 * partWidth, yPos - 4 * partWidth);
rect(xPos + 5 * partWidth, yPos, xPos + 6 * partWidth, yPos - 3 * partWidth);
}
void moveShip(float moveX, float moveY) {
xPos += moveX;
yPos += moveY;
}
Bullet shootGun(float angle, float bulletSpeed) {
colorMode(HSB);
int h = floor(random(0,360));
int s = floor(random(230,256));
int b = floor(random(230,256));
return new Bullet(xPos + 3 * partWidth,
yPos - 5 * partWidth,
angle, new DynamicColor(h, s, b, 255, "HSB"), bulletSpeed);
}
float gunX() { return xPos + 3 * partWidth; }
float gunY() { return yPos - 5 * partWidth; }
void setSpeed(float value) { speed = value; }
}