York U: Redefine the Possible HOME | Current Students | Faculty & Staff | Research link: Future Students, Alumni & Visitors
Search »  
Department of Computer Science and Engineering
Home
Announcements
Course Calendar
Course Forum


Y graphic
CSE 1030 - Practice Assignment - Enhance AlienAttack Game

SC/CSE 1030 - Fall 2012 - Practice Assignment

Enhance the AlienAttack Game





In class we discussed the AlienAttack game program at length. Your task for this assignment is to make some enhancements to the game. The enhancements are described below. Note that this is only a practice assignment, so it does not have a due date, does not have to be submitted, will not be marked, and the solution is provided below.

To complete this assignment, you must do these things:

  1. The game panel is currently 400 pixels wide. Make it 50 pixels wider.

  2. Add a cloud anywhere on the screen that you wish.

  3. In class I demonstrated a minor "bug" in the game. In the public void keyReleased(KeyEvent ke) function we don't check which key was released. This means that if the missile is moving right or left and the space bar it hit, the missile stops moving (right or left) even if the right or left cursor key is still being held down by the player. An easy fix is to add an "if" statement to the keyReleased() key listener function. The "if" statement should check whether it was a "space" key that was released, and then call missile_no_fire.setSpeedXY(0, 0); only if it was not the space bar that was released. Look at the keyPressed() function to see an example of how to check which key caused the key pressed or released event.

  4. The Aliens "come in Peace!" - they have brought a cargo of exotic flowers to give to the humans. When the UFO spaceship is destroyed, the flowers should fall down to the earth.

    • create 4 new flower Sprites, named "flower1" to "flower4" (use the image provided: flower.gif)

    • don't forget to call registerSprite() to register each of the flower sprites with the gamepanel

    • in the checkForCollision() function, if the UFO is hit by the missile...

      • for each of the 4 flowers, use setXY() to set the position of the flowers, so that the centre of each flower is positioned at the centre of the UFO

      • we want the falling flowers to spread out as they fall, so set the velocities of the 4 flowers as follows:

        • flower1.setSpeedXY(-0.3, 0.4);
        • flower2.setSpeedXY(-0.1, 0.4);
        • flower3.setSpeedXY(0.1, 0.4);
        • flower4.setSpeedXY(0.3, 0.4);
      • make all 4 flowers visible (.setVisible(true))

    • create a new function called manageFlowers(), to "turn-off" the flowers once they have fallen to the bottom of the display panel:

      • in manageFlowers(), check whether the y position (.getY()) is greater than PANEL_HEIGHT

      • if it is, make all 4 flowers invisible (.setVisible(false))

      • set the position of all 4 flowers to be (0,0) (use the .setXY(,) function)

      • set the speed of all 4 flowers to be (0,0) (use the .setSpeedXY(,) function)

      • add this function to the main loop (i.e., call manageFlowers() from the actionPerformed() function

  5. Tricky bonus question - constrain the horizontal motion of the "no fire" missile so that it can not move off of the screen (to the left or right). You may have to modify the Sprite.java file. No solution is provided.

Some notes:

  1. To complete this assignment you will need to modify the AlienAttck.java program previously given (you can download the entire AlienAttack package (including the code and media (.gif) files) here: AlienAttack.zip).

    Note that all of the suggested changes described above require you to change the AlienAttack.java file, you should not have to change the Sprite.java or GamePanel.java classes.

  2. As always, your source code should be well organised and documented.

  3. Forget about the Course's, Department's, and the University's policies on academic honesty - but you should still do your own assignment yourself. The only way to learn to code is to play with code, so get in there and play!

  4. This assignment has no due date.

  5. Do not submit your solution.

  6. Do not use the Type package, nor its earlier incarnation, the york package.

  7. This assignment will not be graded. But you will know if your solution is correct when the game does what you intend. But if you want to see what the solution looks like, you can see it here: AlienAttack.java. The changes I made to this program are indicated by comments.

  8. Have FUN!






graphic rule