Course Contents — Links to Lessons

Unit 4: Graphics using HSA2

A simple way to have popup input and messages is JOptionPane. Please have a look at the document and see how to use them.
In HSA2 we use simpler form gc.showDialog() and gs.showInputDialog()

We are going to be using a graphics library, called HSA2, that removes a lot of the complexity of Swing graphics.
We'll learn Swing graphics in grade 12 programming.
You can find the latest HSA2 package on my GitHub . Download the zip file at home.

Step 1: Learn The Graphics Commands

 

TODO: Do the Graphics Drawing program
Rubric

Step 2: Basic Animation

 

a) Read this overview of game loops first.

b) In this step we'll learn how to make a program with something changing on the screen. We'll be using a while loop to do this continually.

Work through the PDF that explains the "Fading.java" program.

This shows

c) Read notes on organizing an animation program

d) Work through the PDF that explains the "Bounce1.java" program.

Step 3: Understanding Movement

a) Read Notes on motion and bouncing
This also shows bouncing off of an immovable object as well as two balls bouncing off each other.

TODO: Take the "Bounce1.java" program that you wrote above, and add the code to actually make the ball bounce.

Step 4: Using Objects for Animation

We use objects to hold all of the variables for a certain thing - e.g. a Ball. All of the variables that control the position, speed, colour, ..., of the shape drawn on the screen can be hidden inside the object.
We can also make multiple balls really easily, like this:
Ball b1 = new Ball(); and Ball b2 = new Ball();

a) Work through the Using objects in graphics program.

TODO: Draw3Circles.java
Note that these balls are not going to bounce yet.

Our objects are almost always
either rectangles e.g. Rectangle paddle = new Rectangle (300,650,100,10); ← this would be for a paddle in Pong or Breakout
or an object the extends Rectangle. e.g. Class Ball extends Rectangle { }

The reason for doing this is that rectangles have a simple intersect() method, though it's not entirely accurate if you have two balls hitting diagonally. They also have another useful method called contains() .

TODO: Work through the TwoBalls.java program. You'll also need Ball.java

When two things collide there are various things we want to do:

How to do various useful things in HSA2

TODO: Simple Game. This will use all that you've learned so far. You can also use the techniques from steps 5 and 6 below. Some of you will want to do more complicated things with arrays and arraylists, but we haven't learned those yet (if you can figure them out, great)

Step 5: Keyboard and Mouse Input

Step 6: Timers

How to use Timers
Sample program: Timer showing seconds on screen and pause functionality

Images and Sound

ColourRainbow.java is here

Other

How to make an intro screen — to pop up with instructions before your game starts

Videos about graphics

Go to the Salamander2 youtube channel and watch the videos in order. Make sure that you put cc. on because my voice is often not clear.

The videos discuss pretty much everything we've covered here as well as other things. The basics are: how to make ball objects instead of just a bunch of variables, how to make things collide and bounce, how to make arrays and arraylists of balls, how to add and delete balls.