This is where the fun begins.
All the hard work. The hours of dedication. The years of dreaming. It culminates here.
Welcome to Unit 2. By the time you walk away from this Unit, you will have made a fully playable game.
Before we get into the actual coding, let's talk about logistics.
1. You will be making a Java based applet. The purpose of this is to make it easy to embed into HTML, so you will be seeing live examples on this page.
2. If you have not followed Unit 1, we will be using Eclipse throughout this series. So I suggest that you go read the first few lessons in the first Unit to get yourself ready to develop.
In the past, many of you (nearly a hundred) participated in the survey that was available on this page, and I read each response.
Thank you so much for your feedback.
Game Idea:
The most popular game idea was a platforming shooter. So that is the direction we will be headed.
Welcome to Unit 2. By the time you walk away from this Unit, you will have made a fully playable game.
Before we get into the actual coding, let's talk about logistics.
1. You will be making a Java based applet. The purpose of this is to make it easy to embed into HTML, so you will be seeing live examples on this page.
2. If you have not followed Unit 1, we will be using Eclipse throughout this series. So I suggest that you go read the first few lessons in the first Unit to get yourself ready to develop.
In the past, many of you (nearly a hundred) participated in the survey that was available on this page, and I read each response.
Thank you so much for your feedback.
Game Idea:
The most popular game idea was a platforming shooter. So that is the direction we will be headed.
Lesson #2-1: Setting up a Project
You're back for more! This Unit will be fun.
Open up Eclipse and create a Java project. You can do this by right clicking on the Package Explorer >> New >> Java Project:
You're back for more! This Unit will be fun.
Open up Eclipse and create a Java project. You can do this by right clicking on the Package Explorer >> New >> Java Project:
Call it KiloboltGame (consistency will ensure that we won't have errors due to naming). Also the JRE version can be either 1.6 or 1.7. It does not matter!
Inside this project's src folder (remember this is where we store all our code):
1. Create a Package. Name it kiloboltgame. By convention its the package name begins lowercase.
Packages are ways of organizing classes into folder-like structures.
Right click on your newly created package and create a class: StartingClass.
1. Create a Package. Name it kiloboltgame. By convention its the package name begins lowercase.
Packages are ways of organizing classes into folder-like structures.
Right click on your newly created package and create a class: StartingClass.
Now we can start coding.
Lesson #2-2: Adding Methods and extending Applet
By this time, I trust that you are all experienced Java programmers capable of discerning which brace corresponds with which.
As such I will no longer be color coding unless I believe it is absolutely necessary.
1. Add extends Applet after "StartingClass". Recall that we can borrow methods from a superclass by inheriting it.
2. You will see a red line under Applet. Import Applet by pressing Ctrl+Shift+O or by manually selecting the import by mouseover.
3. You can now add the following methods: init(), start(), stop(), destroy(). These are part of the Applet superclass, and by importing Applet, you gain the ability to use them.
4. An easy way to add a pre-defined method (as in one that is already written for you), is to use the auto-complete function. Begin typing "init" and then press Ctrl + Space. It will open an auto-complete suggestions box, from which you can choose the first init() function. Proceed to do this with all four methods and you will see this:
Lesson #2-2: Adding Methods and extending Applet
By this time, I trust that you are all experienced Java programmers capable of discerning which brace corresponds with which.
As such I will no longer be color coding unless I believe it is absolutely necessary.
1. Add extends Applet after "StartingClass". Recall that we can borrow methods from a superclass by inheriting it.
2. You will see a red line under Applet. Import Applet by pressing Ctrl+Shift+O or by manually selecting the import by mouseover.
3. You can now add the following methods: init(), start(), stop(), destroy(). These are part of the Applet superclass, and by importing Applet, you gain the ability to use them.
4. An easy way to add a pre-defined method (as in one that is already written for you), is to use the auto-complete function. Begin typing "init" and then press Ctrl + Space. It will open an auto-complete suggestions box, from which you can choose the first init() function. Proceed to do this with all four methods and you will see this:
5. Press Ctrl + Shift + F to auto-organize your code.
Shortcuts such as these will help you save a lot of time.
Shortcuts such as these will help you save a lot of time.
Figure 2-1
package kiloboltgame;
import java.applet.Applet;
public class StartingClass extends Applet {
@Override
public void init() {
// TODO Auto-generated method stub
super.init();
}
@Override
public void start() {
// TODO Auto-generated method stub
super.start();
}
@Override
public void stop() {
// TODO Auto-generated method stub
super.stop();
}
@Override
public void destroy() {
// TODO Auto-generated method stub
super.destroy();
}
}
Now, as always, we will talk about each of these methods.
The four methods: init(), start(), stop(), and destroy() are frameworks for execution provided by the Applet class. In this Applet's life cycle, major events will call one of these methods and execute it.
The @Override tests for errors upon compilation. In this case, we are using it to annotate that we are overriding methods from a parent class. It informs you when you make mistakes.
More information on this can be found on Google. But for now, don't worry about it. :)
Within each method, you will see a "super." This "super" is referring to the superclass (in this case Applet). You might also see a "this" in the future, which will refer to the current class. Don't worry about this for now. We can safely delete each "super" line (or leave it, if you choose):
The four methods: init(), start(), stop(), and destroy() are frameworks for execution provided by the Applet class. In this Applet's life cycle, major events will call one of these methods and execute it.
The @Override tests for errors upon compilation. In this case, we are using it to annotate that we are overriding methods from a parent class. It informs you when you make mistakes.
More information on this can be found on Google. But for now, don't worry about it. :)
Within each method, you will see a "super." This "super" is referring to the superclass (in this case Applet). You might also see a "this" in the future, which will refer to the current class. Don't worry about this for now. We can safely delete each "super" line (or leave it, if you choose):
Before we move on!
Mini Quiz:
1. How can you make a program keep running? How do you repeat statements?
2. What tool do we use for simultaneous processes in Java?
3. What is a game loop?
Answer these questions and check below!
Answers:
1. We utilize a loop.
2. A thread.
3. A game loop is the central component of a game. People refer to it as the heartbeat of the game. To put simply, it is a loop that will continuously check for changes in the game and make necessary updates. Graphics, controls, movement, physics all rely on the game loop in some way.
Here's a fake game loop that will help you understand:
Mini Quiz:
1. How can you make a program keep running? How do you repeat statements?
2. What tool do we use for simultaneous processes in Java?
3. What is a game loop?
Answer these questions and check below!
Answers:
1. We utilize a loop.
2. A thread.
3. A game loop is the central component of a game. People refer to it as the heartbeat of the game. To put simply, it is a loop that will continuously check for changes in the game and make necessary updates. Graphics, controls, movement, physics all rely on the game loop in some way.
Here's a fake game loop that will help you understand:
Figure 2-2
while (playerIsAlive) {
updatePosition();
applyGravity();
drawCharacterAtCurrentLocation();
}
Figure 2-3 incorporates three pseudo-methods (they are simply there for illustration).
We have a condition that while the playerIsAlive is true, we update his position, redraw his character at that new position, and apply gravity.
This is a simplified example of a game loop.
As we get into more advanced gaming concepts, we will talk about creating a proper game loop. But for now, a simple one will have to suffice (And on modern computers, a little bit of slacking here won't hurt us). But wait until we start developing on Android. Technical considerations can be PAINFUL.
Day 1 will stop here. Day 2 will be up in an hour or two.
In Day 2, we will talk about applying threads and loops to create the heartbeat of our upcoming game.
Be excited.
Thank you for being an awesome audience, and please share our page on Facebook.
We have a condition that while the playerIsAlive is true, we update his position, redraw his character at that new position, and apply gravity.
This is a simplified example of a game loop.
As we get into more advanced gaming concepts, we will talk about creating a proper game loop. But for now, a simple one will have to suffice (And on modern computers, a little bit of slacking here won't hurt us). But wait until we start developing on Android. Technical considerations can be PAINFUL.
Day 1 will stop here. Day 2 will be up in an hour or two.
In Day 2, we will talk about applying threads and loops to create the heartbeat of our upcoming game.
Be excited.
Thank you for being an awesome audience, and please share our page on Facebook.
