-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.pde
48 lines (43 loc) · 1.36 KB
/
Bullet.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
46
47
48
/*
ICS4U
2018/06/17 v1
Game Summative
Bullet class
Made by Eren Sulutas and Nabeel Warsalee
*/
class Bullet extends Rectangle {
private char lastKey;
// Default constructor for the Bullet
Bullet() {
super();
lastKey = ' ';
}
// Constructor for the Bullet class, sets up the position of the bullet
Bullet(float xPos, float yPos, char lastPress) {
super(xPos+ceil(gridSize/2), yPos+ceil(gridSize/2), ceil(gridSize*0.1), ceil(gridSize*0.1));
this.lastKey = lastPress;
}
// Method for the bullet moving
void move() {
float v = ceil(gridSize/2); // Float value for the speed of the bullet, the speed will always be half the gridSize per frame
// Shoots in a different direction depending on last key pressed
if (lastKey == 'r') {
setPos(getX()+v, getBottom());
} else if (lastKey == 'l') {
setPos(getX()-v, getBottom());
} else if (lastKey == 'u') {
setPos(getX(), getBottom()-v);
} else if (lastKey == 'd') {
setPos(getX(), getBottom()+v);
}
updatePos(); // Updating the other coordinates of the bullet.
}
// Method for showing the bullet
void show() {
fill(200);
noStroke();
if (inBounds(getX(), getBottom())) { // Checking to see if the bullet is in Bounds
rect(getX(), getBottom(), getWidth(), getHeight());
}
}
}