This repository was archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInvadersCollision.html
More file actions
60 lines (47 loc) · 2.66 KB
/
InvadersCollision.html
File metadata and controls
60 lines (47 loc) · 2.66 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
<!DOCTYPE html>
<html>
<title>League Invaders - Collision</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://league-central.github.io/curriculum/style/style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<script src="https://league-central.github.io/curriculum/script/headerAndFooter.js"></script>
<body>
<div id ="wrap">
<div id ="main">
<div id = "moduleIndex">
<h1>Collision Management</h1>
<br>
<p class="normal">
If a projectile collides with an alien, both objects are marked inactive. If an alien collides with the rocketship, both are marked inactive. Inactive objects are removed from the game so they are no longer drawn. </p>
<h2>GameObject</h2>
<p class="normal">
1. In your <code>GameObject</code> class, create an object of the <code>Rectangle</code> class in your member variables. Call this object <code>collisionBox</code> and DO NOT INITIALIZE IT YET.</p>
<br>
<p class="normal">
2. Initialize the collision box in the constructor. It takes four parameters. Use its x, y, width, and height variables.</p>
<br>
<p class="normal">
3. In the update method, update the collision box with the x, y, width, and height variables so it keeps moving with the GameObject (Alien, Projectile, or Rocketship).
<pre>
collisionBox.setBounds(x, y, width, height);</pre><br>
<h2>ObjectManager</h2>
<br>
<p class="normal">
4. Create a method called checkCollision. Add code that iterates through every alien and checks if it collides with any "enemy" (Rocket or Projectile). If they collide, set the Alien AND "enemy's" isActive variables to false. NOTE: you will need nested for loops! Collision can be checked using the Rectangle intersects() method - see example below:<br>
<pre>rocket.collisionBox.intersects(alien.collisionBox)</pre>
</p>
<br>
<p class="normal">
5. In the update() method call the checkCollision() and the purgeObjects() methods after you have updated all the game objects.</p>
<br>
<h3><u>TESTING</u></h3>
<p class="normal">
6. Run the program. Do the aliens and projectiles disappear when they are supposed to?
</p>
<br>
</div></div></div>
<div id="footer">
<script>addFooter();</script>
</div>
</body></html>