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. 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.

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.

Enough chit chat. 
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:
Click to Enlarge
Call it KiloboltGame (consistency will ensure that we won't have errors due to naming).
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.
KiloboltGame Project containing a kiloboltgame Package containing a StartingClass class.
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:
5. Press Ctrl + Shift + F to auto-organize your code. 

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{

   public void init() {
   // TODO Auto-generated method stub

   public void start() {
   //TODO Auto-generated method stub

  public void stop() {
  // TODO Auto-generated method stub

  public void destroy() {
  // TODO Auto-generated method stub

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:

Figure 2-2: Final Code:

package kiloboltgame;

import java.applet.Applet;

public class StartingClass extends Applet{

   public void init() {
   // TODO Auto-generated method stub
   public void start() {
   //TODO Auto-generated method stub

  public void stop() {
  // TODO Auto-generated method stub

  public void destroy() {
  // TODO Auto-generated method stub

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!

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

while (playerIsAlive){
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.

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!



10/05/2012 1:11am


10/05/2012 6:30am

Thank you for this tutorial. I have been looking for a good tutorial for android development and this one is great. If I ever sell some of my games on Android I will definitely donate some here. :)

Check out this game titles:

- Advanced Android Annihilation
- Samurai Carnage
- Dynamite Shootout
- Chocolate Crocodile
- Fluffy Princess
- Chase Munchers
- Hyper Sushi Man
- Prince Kilo vs Super Bolt

Scott link
10/05/2012 11:10am

Thanks for writing this tutorial! I've always been interested in developing games, but never really know how to go about it, and I hope by following your tutorial I can.

It would be cool if you could post all of this stuff on Github, Unit has its own public repo, and each day has its own subfolder.

10/05/2012 3:09pm


John Paul
10/05/2012 3:33pm

Hello everyone!!!
I am super exited to the next tutorial, I love free education, I am going to create a website for free education and when I do I will definetly talk about you. Thank you so much.
The best name that I can think of is: "Cortilo"

Roshan Karki link
10/07/2012 1:57am

Thanks, can't wait for more.

10/07/2012 10:24am

Just cant wait for complete tutorials to be out.......i Guess u mae a FAN!

10/07/2012 10:37am

Thanks a lot for this. I am getting very excited and learning whole this in bits is actually making me understand more than what I learned from other books and tutorials.

10/17/2012 8:05pm

Are you saying that your TUMBL game was written in Applet? Or you are giving us an example of writing an Applet game and then teach us about how to create a game for Android? I am really NOT that interested in learning Applet, but if it is a way to create a game for Android, I can continue reading it.

BTW, I really appreciate your efforts and willingness to help others. Great work!

James C.
10/17/2012 8:28pm

TUMBL was originally written as an Applet (as a proof of concept) and then ported to Android.

The curriculum for this tutorial series is as follows (simplified):
Unit 1: Basic Java
Unit 2: Creating a Java Game
Unit 3: Porting this game to Android
Unit 4: Advanced Game Dev.

Since this tutorial was created for beginners, we assume that you have not created a game before. Since it is a huge leap to go from not knowing how to make a game using Basic Java to making a full-fledged Android application that incorporates SurfaceViews and XMLs while worrying about resource management, activity life cycles and touch/accelerometer input, we are covering Applets first (not because we are going to be making Applets in the future, but because it is a way to apply basic game development concepts).

Most of the concepts that we discuss here will scale up perfectly -- in fact, you can even copy and paste some of the code when we begin Unit 3.

The other alternative is to utilize Swing, but I just chose the path that I've taken when I developed TUMBL.

I hope that clears things up and thank you for following the guide!

11/03/2012 12:17pm

Thank you so much for these tutorials James. I have learned java for 2 years in university but only for boring stuff like recursive algorithms and efficient search and stuff like that. I always wanted to learn about android game development and these tutorials are absolutely perfect as i have been learning something new every tutorial. Amazing job man, keep up the good work. Will be donating soon :)

11/08/2012 7:34am


11/17/2012 11:29pm

Awesome stuff. I'm really looking forward to doing this unit.

Thank you!

Alihan Yılmaz
11/20/2012 12:25am

Thank You !! I really learn a alot from you. Cant wait to see new lessons.

11/21/2012 7:12pm

Great stuff. This is very helpful. Thank you!!! Excited to the transition into Android Development! :P

Roberto Rios link
12/02/2012 8:32pm


The Sinister V
12/05/2012 1:38am

You could be making some money off these tutorials yet here you are sharing the knowledge for free.
I seriously cannot thank you enough.
Thank you.
Thank you.
Thank you.

12/05/2012 10:47pm

excellent tutorial man im loving them if i end making the game i want ill totally give you the credits you deserve+donations if i sell it on the playstore :D
and the game name related to you is
Revenge of Kilobolt

12/12/2012 11:56am

Great job!

FWIW, I more used to having an "auto" autocomplete, especially being out of the language for a while and forgetting so much. I followed a stackoverflow tip to go in to Preferences -> Java -> Editor -> Content Assist and add a-z and A-Z to the activation triggers. I also set the activation delay to 50 ms. The autocomplete options now pop up as I type.

syed huzaifa
12/13/2012 3:20am

Awesome tutorial,great job and thoroughly explained.

12/19/2012 10:51pm

Thanks for this nice tutorial,
I am new, and little bit confused in placing all class and code together. Then i download your code and your final source code showing error when i import.
plz provide compiling source code.

James C.
12/19/2012 11:09pm

I copied and pasted the "final code" and it works perfectly for me.

Check that you have named your .java file exactly as the class declaration says: StartingClass.java.

James C.
12/19/2012 11:07pm

Could you email me a screenshot of the error?


Thank you!

Connor link
01/01/2013 10:07pm

Thanks for taking the time to make this tutorial :) i have been looking for one and i found this very high quality tutorial for free :) thanks.

01/07/2013 11:29pm

On my version control + space does not work, but i found out Alt + / works. Might help somebody.

01/15/2013 12:36pm

Man u rock!!! Thanks to ppl like u this world goes around. My only complaint is that TUMBL+ is soooo addictive ;P

I m a student but I ll try to support u as much as I can. Thx again a million times :D

01/21/2013 9:31pm

The best! You actually teach stuff, and explain well! You actually care about your readers! I find these tutorials 100x better than YouTube videos!

rohanpro(xda developer)
02/04/2013 3:50am

its a great learning site....keep up the good work

02/05/2013 10:10am

Go ahead lads ! Thanks for your work.

02/10/2013 7:34am

This is seriously a Godsend:D

02/14/2013 1:39pm

You're a cool guy man. Thanks for putting up all this stuff. I've already learned so much and I'm a noob. :)

02/16/2013 3:32am


03/27/2013 12:01pm

Please add moneybookers for donations.

03/31/2013 9:36pm


04/04/2013 11:28am

Thanks for this wonderful tutoriual!

- Bolts from the blue
- Kane Kilobolt

04/09/2013 4:31am

James Bolt

04/27/2013 11:59pm

Tutorial is great. however can u make the code more like the one in stakoverflow? To make it more readable?

06/14/2013 5:26am

Thank you Bolt... Your tutorial is my foundation step for some great game development.

06/17/2013 6:58am

Good work ...i enjoyed it lets move on.....

06/18/2013 11:30pm

Sir my previous questione's solution has found. I want a suggestion from you that wheather I use netbeans because graphic creation Is simple in that software.

06/20/2013 1:39pm

Just in case anyone doesn't feel like typing all of the inherited methods

right click where you would like to insert code > Source > Override/Implement Methods... then you can choose which methods you would like to Override instead of typing them out.

07/03/2013 7:56am

Thanks for the heart work you've put into these guides. I've started from the beginning and hope to develop games in my spare time. I appreciate everything you've done. Thank you!

sid link
07/28/2013 5:03am

System.out.println("Thank you for great tutorials");

08/02/2013 6:14pm

I love the shortcuts of Eclipse you told that I don't know already :)

08/04/2013 11:26am

Kilo Invader

08/13/2013 12:31pm

thanks a lot for this tutorial.. this helps me a lot.. this tutorial is way better that school :)

08/23/2013 2:41pm

Thanks for these tuts.. what about Trench like the combat trench in war.

Carlos Navas
09/04/2013 12:51pm

This is really really well explained. Thank you!!

09/24/2013 4:59am

very very useful.

09/29/2013 10:49pm

At Step 1 I came across a problem that might be a version of eclipse issue. There is no folder under the src and no way of adding a package. What am I missing?

michael roni
09/30/2013 5:41am

shooting dino

10/03/2013 8:55pm

Thank you very much for these tutorials, they are really helpful. I am not able donate money, but all I can do is share your site with my friends and I can help you make some money off Google Adsense ads that you have put on this site (Obviously by clicking the ads once a while :P)
Btw, thanks again :)


Leave a Reply


    James Cho is the lead developer at Kilobolt Studios. He is a college student at Duke University and loves soccer, music, and sharing knowledge.