code for a 2d java game?

Started by
4 comments, last by Jeffige 11 years, 8 months ago
I have started to learn java so I could create 2D games for Android. Out of curiosity, does anyone know

where I could find a simple open source 2D game so I could look over the code? It may help ( even if I don't fully understand it, yet) to actually see code and how it was written out.

A side scrolling game would be perfect since that is what I am aiming for. But, beggars can't be choosy.

Thanks for any recommendations.
Advertisement
http://www.youtube.com/playlist?list=PLA331A6709F40B79D

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

Are you using a framework, engine, or just Android API?

Android API: Check out Replica Island. It's a big game but you should be able to pick it apart.

Framework or engine: Depends on the framework or engine. LibGDX has some projects to look at.
Thanks guys.

David M, as of now, I just started to learn java (any programming for that matter) a few weeks ago. Self teaching/ learning with java, A beginners guide 5th ed. So, framework or engine? Couldn't tell ya.

I was just thinking if I looked over the code from an actual 2D java game, it may help me to understand as I learn along. As for Android, that is my ultimate goal.

Again, thanks for the help.
Read that wrong, sorry. I thought you were starting Android development. If you're just starting Java then I would pick up a book to learn the basics of the language. From there you can start to branch off into games. Start simple! Build tic-tac-toe as a console game. From there work up to basic graphics (drawing images on-screen and simple movement). You won't be able to use OpenGL with straight Java so drawing will reside in a frame of some sort (JPanel or something). Then you can move on to a Snake game and Space Invaders; more complicated games. Then you can pretty much go on to wherever you like. Jumping to Android wouldn't be too difficult from there, just learning the Android API.

If you decide along your journey into graphics programming that Swing is awful then look into some of the more popular OpenGL-based frameworks and libraries like Slick2D (Windows/Linux/Mac), LibGDX (Windows/Linux/Mac/Android), or a Java wrapper of OpenGL like LWJGL.

As far as examples go, for Swing there is Zetcode with its 2D games tutorials. I got started with it but don't recommend it. It uses a fixed Timer for movement which will be variable based on how fast your machine runs. You'll be much better off learning things right and using a delta time-step. Take a look at Kevin Glass' work. He wrote Slick2D. For Slick examples visit the SlickWiki. For LibGDX, go to the LibGDX wiki and git. LWJGL has examples but it's tougher to get started in.

If you're just starting Java then I would pick up a book to learn the basics of the language.


Wow! Thanks David. That is more & concise info that I have read in one spot. Actually, after searching a couple of weeks
for a good starting java book, I eneded up with java, A beginners guide 5th edition. I have read, although I do not need to know complete java, I do need to know the core. After that, I can start on Android while still learning java.

As for frameworks & libraries, No Idea! I have not gotten to that intersection, yet. I do know that I only want to create simple 2D games like Tetris, Space invaders, Tumbl on Android, and some simple kid games like where they snap the puzzle pieces into place and an ABC learning game.

On one of the posts here at gamedev.net I read someone mentioned this (sorry I have forgotten who exactly)

A complete understanding of the basics would be desirable.
Specifically the following topics:
•Declarations and Access Control
•ObjectOrientation
•Assignments
•Operators
•Flow Control, Exceptions, and Assertions
•Strings, I/O, Formatting, and Parsing
•Generics and Collections
•InnerClasses
•Threads

I know even a simple 2D game is a lot of work for a beginner. So, I'm taking it one line of code at a time.

Thanks for the replies.

This topic is closed to new replies.

Advertisement