lecture 3 Flashcards

(6 cards)

1
Q

intersects(other) {
let d = dist(this.xPos, this.yPos, other.xPos, other.yPos);
if (d < this.radius + other.radius) {
return true;
} else {
return false;
}
}

what is the above code doing?

A

checking collision based on radius

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

if (missile1.intersects(enemy1)) {
enemy1.colour = ‘black’;
}

what will occur when the above code is called?

A

if a missile intersects with an enemy the colour of the enemy will be black

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

for (let i = 0; i < missiles.length; i++) {
for (let j = 0; j < numOfEnemies; j++) {
if (missiles[i].intersects(enemies[j]) || missiles[i].xPos > width) {
enemies[j].colour = ‘black’;
missiles.splice(i, 1);

What single piece of code would you add after splice to prevent accessing deleted missiles in a loop?

A

break;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

for an enemy is it better to A. delete and create a new enemy or B. make the enemy invisible and reuse it after its traversed the screen?

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

for a missile is it better to reuse or recreate?

A

recreate as it is dynamic to the player and they are no longer required. e.g. after a collision or if they have traversed the screen (without a collision).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what would happen if you didn’t delete the missile after it traverses your screen?

A

it will continue moving and increase memory usage in your application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly