null
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 1/23)
Today we invite you to write an exciting game — Moon Lander. As always, we'll start with the rules. The objective is guide a landing module down to the lunar surface. To do this, the player must overcome the Moon's gravitational attraction, using an aft booster to slow the descent and side thruster
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 2/23)
Now we'll implement the drawScene() method, where we'll paint all the cells of the playing field the same color. To help us, we'll use the Game class's setCellColor(int, int, Color) method, whose parameters are the cell coordinates and color. We'll call it every coordinate from 0 to WIDTH and from
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 3/23)
Because Moon Lander will use game objects, let's create a GameObject class, where we'll put all the common properties. At this point, these are x and y coordinates.
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 4/23)
In addition to coordinates, a game object will have a matrix responsible for the object's appearance. Let's add an int[][] matrix variable to the GameObject class to store it. And now we'll tackle the lunar landing module. For simplicity, we'll just call it a rocket. We'll create a Rocket that inhe
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 5/23)
We will use a game object's properties, such as width and height, quite often. Accordingly, we'll put them in separate variables in the GameObject class. To allow the object to draw itself on the playing field, we'll add a draw method. This method will take a Game object as an argument. Now we can
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 6/23)
We've got our rocket. Now we'll handle drawing the landscape. We created its matrix for you. You'll find it in the ShapeMatrix class. The landscape is also a game object, so let's create a method that will be responsible for initializing such objects. That's where the landscape and rocket will be c
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 7/23)
Let's make our rocket move. To begin, we'll create a move() method and implement free fall in it. Of course, free fall involves acceleration, so we'll need to constantly increase the speed of descent. The speedY variable will be responsible for the speed of motion along the Y axis, and we'll increa
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 8/23)
We will continue to implement the rocket's movement. Let's add fields that will be responsible for the state of the keys used to move the rocket about the screen. These fields will take only two values: true, if the key is pressed; otherwise — false. We'll only need three keys to control the rocket
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 9/23)
At this stage, we'll implement the onKeyPress and onKeyReleased methods. As you can tell from the name, the onKeyPress method is called when any key is pressed, and the onKeyReleased method is called when a key is released. Let's get started on the implementation of the onKeyPress method. It must p
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 10/23)
Let's continue implementing the rocket's movement. It should be able to move vertically and horizontally. Let's make the necessary changes in the move method: now its parameters will be the states of keys. The first parameter is isUpPressed, the second — isLeftPressed, and the third — isRightPresse
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 11/23)
At the moment, the rocket can fly beyond the bounds of the playing field. Let's fix that. We'll create a special method that will check whether the rocket has reached the left, right, or top edge of the screen. If the rocket reaches one of these edges, we'll keep it within the playing field. The ca
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 12/23)
As you've noticed, after the left or right key is released, the rocket stops moving immediately, but it should continue moving from inertia. To achieve this, we will use the slowdown variable, which is responsible for slowing the rocket. If we release the left or right key, the move method will gra
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 13/23)
Now we'll declare several methods that we'll need in the future. The check method will check whether the rocket's coordinates intersect with the landscape. The win and gameOver methods will be responsible for winning and losing, respectively. The isStopped method will check the "softness" of the la
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 14/23)
We'll create a GameObject platform variable to make it easy to check the rocket's landing. Initialize its matrix by passing ShapeMatrix.PLATFORM, which we've added to the ShapeMatrix class. Now we'll implement the check method. It will call the win or gameOver method, depending on the situation. Wh
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 15/23)
We'll create a land method, which will be responsible for landing the rocket. If the rocket intersects the platform, we consider it to be landed. Thus, in order to display everything correctly, we need to lift the rocket up by one position so it doesn't overlap the platform. We also need a special
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 16/23)
Let's tackle the method responsible for crashing the rocket when it collides with the landscape. This method will change the rocket's appearance by replacing its matrix (you'll find the matrix in the ShapeMatrix class). Now we'll implement the gameOver method. It must call the crash method on the r
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 17/23)
The time has come to implement the rocket's jet thrusters. At this stage, we'll create a RocketFire class, which will be responsible for drawing and animating the exhaust blast. The matrices used in the animation will be stored in a List frames variable. A frameIndex variable will store the index
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 18/23)
Let's continue implementing the jet thrusters. At this stage, we'll add variables responsible for left, right, and bottom thrust to the Rocket class. In the constructor, we'll set these fields to the appropriate matricies in the ShapeMatrix class, which we've already prepared.
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 19/23)
At this stage, we'll finish our work to display the animation of the jet thrusters. We'll add and implement a nextFrame() method that will switch frames in order to create an animation (set the matrix variable to the current matrix from frames). We'll also override the draw method, which will chang
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 20/23)
At this stage, we'll draw our first animation. We will need show and hide methods, which will be responsible for displaying and hiding the exhaust blast, as well as a switchFire method, which will set the coordinates of the exhaust and call the show and hide methods, depending on the passed argumen
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 21/23)
To fully implement the animation, the switchFire method must account for whether the side thusters are engaged. Accordingly, we'll give the existing switchFire method additional parameters responsible for the state of keys for lateral motion, i.e. the method's first parameter will be isUpPressed, t
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 22/23)
The game for entertainment, but it would still be great to add a score counter. The user's score depends on how long it takes to land: the faster the landing, the higher the score. Accordingly, we'll reduce the user's score (at each step in the game) until it reaches 0. To keep track of the score,
undefined
3
Task
Games, level 0, lesson 4
Locked
Moon Lander (Part 23/23)
Congratulations! The game is done! Now you can play it! If you have time and motivation, you can improve the game by adding some features of your own. For example: - make the game harder or easier by changing the landscape (for example, by adding a tunnel); - make several landscapes/levels; - add v