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 pathInvadersAlienTimer.html
More file actions
73 lines (55 loc) · 3.95 KB
/
InvadersAlienTimer.html
File metadata and controls
73 lines (55 loc) · 3.95 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
<!DOCTYPE html>
<html>
<title>League Invaders - Game Loop</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>Alien Timer</h1>
<br>
<p class="normal">A Timer will control the rate at which enemies will appear in the game. The following steps will create and start the timer as part of the GamePanel function, but the aliens will be added as part of the ObjetManager function.
</p>
<h2>ObjectManager</h2>
<br>
<p class="normal">
The <code>ObjectManager</code> is going to use the <code>ActionListener</code> interface to add an alien to the game each time it expires. Make the <code>ObjectManager</code> class implement the <code>ActionListener</code> interface as shown below:<br>
<pre>public class ObjectManager implements ActionListener
{ ... }</pre>
<br>
<p class="normal">
Add the unimplemented method (Eclipse can help). You should now have an <code>actionPerformed()</code> method in this class.</p>
<br>
<p class="normal">
Each alien should have a random location across the top of the game, so in this method add the following:</p>
<pre>
addAlien(new Alien(new Random().nextInt(LeagueInvaders.WIDTH),0,50,50));</pre>
<br>
<h2>GamePanel</h2>
<p class="normal">
1. In the <code>GamePanel</code> class add another <code>Timer</code> member variable called <code>alienSpawn</code>. You should already have imported <code>javax.swing.Timer</code> when you set up the main game timer. DO NOT INITIALIZE THIS VARIABLE YET.<br></p>
<br>
<p class="normal">
2. We only want the aliens to be created while the game is running, so create a new method <code>startGame()</code>. This method should initialize the <code>alienSpawn</code> member variable and start this timer. The constructor of the Timer class takes two parameters. The first parameter is an int for how fast your want the timer to repeat in milliseconds. Let's start by having one alien spawn every second. So the first parameter will be 1000. The second parameter takes a reference to an ActionListener object. We are going to implement the alienSpawn code in the <code>ObjectManager</code>, so we put objectManager as the second parameter (see below).<br>
<pre>
alienSpawn = new Timer(1000 , objectManager);</pre>
<br>
<p class="normal">
3 Call the startGame() method when the game state changes from MENU to GAME (in the keyPressed() method). Also add code to stop this timer when the game state changes from GAME to END.</p>
<br>
<p class="normal">
4. Add code to create projectiles when the Space Bar is pressed in the GAME state. The ObjectManger has an addProjectile() method for this. Make your projectiles start from the middle of the top of the game's Rocketship.</p>
<br>
<h3><u>TESTING</u></h3>
<p class="normal">
5. Run the program. In the game state (black background) yellow alien squares should be falling from the top of the frame at a rate of about 1 per second. When you press the space bar, do red projectiles go up from the rocket?
</p>
</div></div></div>
<div id="footer">
<script>addFooter();</script>
</div>
</body></html>