The objective of this lab is that you learn the basics of animation. This knowledge will be useful for the project.
You will implement an animation in a Java programming framework provided by Brackeen (the course book author) and us.
The task is split up in the following parts:
- Show one animated object in a window, e.g. a winking smiley, or the images below.
- Make the object move around and bounce off the window boundaries.
- Add more moving animated objects, and make them bounce off each other.
You will solve the task in groups of 1 or 2, and demonstrate your solutions (programs) to one of us course assistants.
When solving these tasks, it is allowed to use code from the book. Regardless of whether you use code from the book, you should at the examination know how to solve these tasks, and related tasks. You should be able to explain to us how to implement variants of the program.
Deadline will be announced on the course page.
Background material: The course book p. 22-55 (especially p. 47-55).
- Download the following zip file containing the code you need to get started. lab1.zip
- Familiarize yourself with the code (not ScreenManager.java). During the lab examination, you will be expected to know why and how it works.
- Experiment with the animation loop and animation set-up.
Background material: The course book p. 71-75.
- Your task is to extend your the code in part 1, so that the animated object moves around and "bounces" off the window boundaries. See "Sprite" in the course book and in the code from the book.
- Make the necessary changes to the code from Part 1 so that the Animation/Sprite can move across the screen.
- Next implement the bouncing off window boundaries. Some leading questions to help you: What are the window boundaries? How do you know when a sprite hits them? How should a sprite change after a collision with a window edge to model "bouncing off the edge"?
Background material: Parts of chapter 5 and 11 of the course book
- Your task is to extend your animation in part 2, so that there is more than one sprite and the sprites bounce off each other when they collide.
- Your program should be designed such that it it easy to add another sprite (or remove one).
- Collision detection:
- If you use the images provided for this lab, I recommend simple bounding circles - however, you may use other detection schemes, using a simple bounding box is NOT OK here.
- Collision handling:
- You are free to model the collision as you want, but the result should look realistic.
This is the extra assignment for those who missed one or more mandatory lectures or completed this lab after the deadline (the last scheduled lab).
- Use the code from part 3 and add keyboard control.
- Using the arrow keys it should be possible to direct the movements of one sprite, that one sprite will start with zero velocity.
- Pressing for example the "up" key, should accelerate the sprite in the "up" direction.
- Note: The controlled sprite should handle collisions in the same way as the others.
The extra assignment is to be handed in via a runnable jar-file which *includes* source code.