1.3-Object-Georienteerd-Programmeren

ChillyGame - Part 1: Walking around

Screenshot of the end result

In this assignment you are going to create a game using the SaxionApp GameLoop feature.

Please setup your project first using the setup guide

You end up with a class with 5 methods (An explanation for this methods can be found in the videos and setup guide):

Step 1: Draw a background

Let’s pimp that ugly black screen by adding drawing a nice background image every time the loop runs.

Step 2: Create a class for the player (a.k.a Chilly the penguin)

First, download the images for chilly the penguin here. Add them to a subfolder named player in your resources folder.

Our gameworld will consist of objects. At first there is one type of object: The player. A player will have the following properties:

Besides these properties the Player also has some methods:

    public void draw() {
        SaxionApp.drawImage("resources/player/penguin-down.png", x, y, width, height);
    }

Step 3: Add Chilly to the game

Now we want to see Chilly in our game. You can do that using the following steps:

Run the game. You should see Chilly on your screen

Step 4: Let Chilly move around!

You should end up with something like this (Make sure that in your version Chilly can move to all directions):

    public void keyboardEvent(KeyboardEvent keyboardEvent) {
        if (keyboardEvent.isKeyPressed()) {
            if (keyboardEvent.getKeyCode() == KeyboardEvent.VK_RIGHT) {
                player.moveRight();
            }
            ...
        }
    }

Step 5: Update Chilly’s image according to the direction he is moving

Quite a simple step, but makes it look a bit better. Please update Chilly’s image based on the direction he is moving in. There are four images: penguin-left.png, penguin-right.png, penguin-up.png and penguin-down.png

Advanced suggestion 1: Slippery ice!

If you think this was to easy. Try the following thing:

As you know ice is slippery. You can also update the Player class in a way that Chily has a speed for both directions (so an int speedx and an int speedy).

Please note: Chilly probably slips out of the screen very quick! Find a way to make these controls a bit easier. For example by setting both speedx and speedy to zero when pressing the spacebar or another key. Or set variable back to zero if you move in the opposite direction. So, if moveLeft() is called when speedx is greater then 0 then move set it to zero first.

Advanced suggestion 2: Make sure Chilly does not walk away!

If you think this was still to easy, try the following:

Make sure Chilly is kept between the bounds of the screen. You can do that by checking and updating Chilly’s coordinates in the loop() method before we draw him.

Do the same for the Y coordinate!