This is where the fun begins.
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. Your voice will matter. Use the comments box below. We will be adding nonessential features as you guys deem necessary.
3. 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 two days, 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.
Like I said before, YOU decide where we will be at the end of the unit. I will simply lead you there.
Changes:
The biggest complaint was that the lessons were too far apart. I will be changing that this Unit. Expect more frequent updates (most likely 2 lessons a week). I hope to finish this Unit in about a month.
In addition, thanks to donations from users like you, we were able to upgrade our website with premium features. So, whenever I use a game asset (graphics, sound, etc), I will be posting them here for you to download and incorporate into your own project. You don't need to start up Photoshop and throw together artwork for this Unit. Of course to maintain this, Kilobolt has to pay a monthly fee. So if you donate any amount (yes even a dollar) it will help us retain this service and bring more exciting features to you in the coming lessons.
In addition we are offering an advertising service. Kilobolt.com, although a very new website, receives significant traffic from very dedicated users. If you want to promote your business, contact us. We are offering two weeks of free advertising to qualifying partners.
Donate Here or Advertise Here.
Let's begin.
Lesson #2-1: Setting up a Project
Open up Eclipse and create a Java project. You can do this by right clicking on the Package Explorer >> New >> Java Project:
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.
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:
Shortcuts such as these will help you save a lot of time.
Figure 2-1
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();
}
}
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:
Figure 2-2: Final Code:
import java.applet.Applet;
public class StartingClass extends Applet{
@Override
public void init() {
// TODO Auto-generated method stub
}
@Override
public void start() {
//TODO Auto-generated method stub
}
@Override
public void stop() {
// TODO Auto-generated method stub
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}
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-3
updatePosition();
drawCharacterAtCurrentLocation();
applyGravity();
}
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.
Oh and also, please post a good game name as a comment down below. :)
We will see what kind of names come up.
Thank you for being an awesome audience, and please share our page on Facebook.
Help us reach 1,000 likes by November!
