- Code a cluster of sprites that behaves as a group.
- Demonstrate the use of aggregation.
Exercises
Exercise 5A_RotatingShip
Make a ship in the center of the screen rotate when the left and right arrow keys are pressed.
Exercise 5B_FiringRotating
Make the ship fire a missile in the direction it is facing. You’ll have to use vector dynamics for this.
Exercise 5C_SpaceRockCluster
Make two separate space rocks that appear and move in a random direction wrapping around the screen. Make a cluster of four space rocks that bounces as a group off the edge walls.
ShowCollisionBounds on the rock in the cluster that is closest to the ship at all times.
Exercise 5D_RockExplosions
When a missile hits a lone space rock or a space rock in the cluster, make an explosion appear and the single rock disappear. When the ship gets hit by a space rock, make the ship and rock both explode, then disappear.
During the entire game, showCollisionBounds on the rock in the cluster that is closest to the ship.
Challenges
Challenge 5E_SpaceAliensTest
Code a Space Aliens game from the UML class diagram provided.
The game should have the following features:
- A spaceship that can move left/right along the baseline using the A/D and arrow keys. It should fire missiles when the space bar is pressed.
- An army of aliens that march towards the baseline (bottom of the screen). The army of aliens should march horizontally, stepping forward when it gets to the edge of the screen. When an alien is hit by a spaceship missile, it should explode and disappear.
- ShowCollisionBounds on the “frontline” of aliens. The frontline is always the highest ranking in each file. Note that the “front line” is not necessarily a straight line:
Challenge 5F_SpaceAliens
Add the following features to your 5E_SpaceAliensTest:
- The frontline aliens should fire ‘fireballs’ back at the spaceship. Only the front line aliens should fire. In addition, an alien should not fire at another alien.
- The spaceship should explode if hit by a fireball thrown by an alien. It should also explode if bumped by an alien.